-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_methods.py
117 lines (99 loc) · 3.35 KB
/
test_methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import pytest
import vcr
from apidatamosru.apidatamos import ApiClient
from apidatamosru.exceptions import APIDataMosError, APIDataMosCountLimitError, APIDataMosAuthError
API_KEY = '7e5b3dd05fbfe77c66a8c356c45eea81'
@vcr.use_cassette()
def test_of_datasets_list():
client = ApiClient(API_KEY)
response = client.get_datasets_list()
assert (response.status_code == 200)
assert (response.json() is not None)
client.close()
@vcr.use_cassette()
def test_count_datasets_list():
client = ApiClient(API_KEY)
response = client.get_datasets_list(inlinecount='allpages')
assert (response.status_code == 200)
assert ('Items' in response.json())
assert ('Count' in response.json())
client.close()
@vcr.use_cassette()
def test_top_datasets_list():
client = ApiClient(API_KEY)
response = client.get_datasets_list(top=6)
assert (response.status_code == 200)
assert (len(response.json()) == 6)
client.close()
@vcr.use_cassette()
def test_dataset_meta():
client = ApiClient(API_KEY)
response = client.get_dataset_meta(658)
assert (response.status_code == 200)
assert ('Id' in response.json())
assert (response.json()['Id'] == 658)
client.close()
@vcr.use_cassette()
def test_dataset_count():
client = ApiClient(API_KEY)
response = client.get_dataset_count(658)
assert (response.status_code == 200)
assert (isinstance(int(response.text), int))
client.close()
@vcr.use_cassette()
def test_dataset_version():
client = ApiClient(API_KEY)
response = client.get_dataset_version(658)
assert ('versionNumber' in response.json())
assert ('releaseNumber' in response.json())
client.close()
@vcr.use_cassette()
def test_dataset_icons():
client = ApiClient(API_KEY)
response = client.get_dataset_icons(658)
assert (response.status_code == 200)
assert (isinstance(response.content, bytes))
client.close()
@vcr.use_cassette()
def test_dataset_image():
client = ApiClient(API_KEY)
response = client.get_dataset_image(658)
assert (response.status_code == 200)
assert (isinstance(response.content, bytes))
client.close()
@vcr.use_cassette()
def test_dataset_marker():
client = ApiClient(API_KEY)
response = client.get_dataset_marker(658)
assert (response.status_code == 200)
assert (isinstance(response.content, bytes))
client.close()
@vcr.use_cassette()
def test_get_dataset():
client = ApiClient(API_KEY)
response = client.get_dataset(658, top=5)
assert (response.status_code == 200)
assert (len(response.json()) == 5)
client.close()
@vcr.use_cassette()
def test_get_geodata():
client = ApiClient(API_KEY)
response = client.get_geodata(658)
assert (response.status_code == 200)
assert ('features' in response.json())
client.close()
@vcr.use_cassette()
def test_invalid_api_key():
invalid_api_key = 'd870b8ec9ae96da2f33493f85f01999f'
client = ApiClient(invalid_api_key, 8)
with pytest.raises(APIDataMosAuthError):
response = client.get_datasets_list()
assert (response.status_code == 403)
assert (response.json() is None)
@vcr.use_cassette()
def test_count_limit():
client = ApiClient(API_KEY)
with pytest.raises(APIDataMosCountLimitError):
response = client.get_dataset(3013)
assert (response.status_code == 413)
assert (response.json() is None)