-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
test_endpoints.py
146 lines (125 loc) · 5.07 KB
/
test_endpoints.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import json
import os
import validators
from django.conf import settings
from rest_framework import status
from rest_framework.test import APILiveServerTestCase, RequestsClient
API_BASE = "http://testserver/api/v1"
# Set the custom headers
headersList = {
"accept": "application/json",
"access-token": os.environ.get("TESTING_TOKEN"),
}
class TaskApiTest(APILiveServerTestCase):
def setUp(self):
# Create a request factory instance
self.client = RequestsClient()
def test_auth_me(self):
res = self.client.get(f"{API_BASE}/auth/me/", headers=headersList)
print(res.json())
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
def test_auth_login(self):
res = self.client.get(f"{API_BASE}/auth/login/")
res_body = res.json()
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(validators.url(res_body["login_url"]), True)
def test_create_dataset(self):
payload = {
"name": "My test dataset",
"source_imagery": "https://tiles.openaerialmap.org/5ac4fc6f26964b0010033112/0/5ac4fc6f26964b0010033113/{z}/{x}/{y}",
}
# test without authentication should be forbidden
res = self.client.post(f"{API_BASE}/dataset/", payload)
self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN)
# test with authentication should be passed
res = self.client.post(f"{API_BASE}/dataset/", payload, headers=headersList)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# now dataset is created , create first aoi inside it
payload_second = {
"geom": {
"type": "Polygon",
"coordinates": [
[
[32.588507094820351, 0.348666499011499],
[32.588517512656978, 0.348184682976698],
[32.588869114643053, 0.348171660921362],
[32.588840465592334, 0.348679521066151],
[32.588507094820351, 0.348666499011499],
]
],
},
"dataset": 1,
}
json_type_header = headersList
json_type_header["content-type"] = "application/json"
res = self.client.post(
f"{API_BASE}/aoi/", json.dumps(payload_second), headers=json_type_header
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# create second aoi too , to test multiple aois
payload_third = {
"geom": {
"type": "Polygon",
"coordinates": [
[
[32.588046105549715, 0.349843692679227],
[32.588225813231475, 0.349484284008701],
[32.588624295482369, 0.349734307433132],
[32.588371662944233, 0.350088507273009],
[32.588046105549715, 0.349843692679227],
]
],
},
"dataset": 1,
}
res = self.client.post(
f"{API_BASE}/aoi/", json.dumps(payload_third), headers=json_type_header
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# download labels from osm for 1
res = self.client.post(
f"{API_BASE}/label/osm/fetch/1/", "", headers=headersList
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# download labels from osm for 2
res = self.client.post(
f"{API_BASE}/label/osm/fetch/2/", "", headers=headersList
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# build the dataset
build_dt_payload = {"dataset_id": 1, "zoom_level": ["19"]}
res = self.client.post(
f"{API_BASE}/dataset/image/build/",
json.dumps(build_dt_payload),
headers=json_type_header,
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# build dataset on multiple zoom levels
build_dt_payload = {"dataset_id": 1, "zoom_level": ["19", "20"]}
res = self.client.post(
f"{API_BASE}/dataset/image/build/",
json.dumps(build_dt_payload),
headers=json_type_header,
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# create model
model_payload = {"name": "My test model", "dataset": 1}
res = self.client.post(
f"{API_BASE}/model/", json.dumps(model_payload), headers=json_type_header
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# create training inside model
training_payload = {
"description": "My very first training",
"epochs": 1,
"batch_size": 1,
"model": 1,
}
res = self.client.post(
f"{API_BASE}/training/",
json.dumps(training_payload),
headers=json_type_header,
)
print(res.json())
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
# test