11import maproulette
22import unittest
3- from tests .sample_data import test_geojson , test_overpassQL_query
3+ from tests .sample_data import test_geojson , test_overpassQL_query , create_challenge_output
44from unittest .mock import patch
5+ import json
56
67
78class TestChallengeAPI (unittest .TestCase ):
89
910 config = maproulette .Configuration (api_key = "API_KEY" )
1011 api = maproulette .Challenge (config )
12+ url = config .api_url
1113
1214 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
1315 def test_get_challenge_by_id (self , mock_request , api_instance = api ):
1416 test_challenge_id = '12974'
15- mock_request .return_value .status_code = '200'
16- response = api_instance .get_challenge_by_id (test_challenge_id )
17- self .assertEqual (response ['status' ], '200' )
17+ api_instance .get_challenge_by_id (test_challenge_id )
18+ mock_request .assert_called_once_with (
19+ f'{ self .url } /challenge/12974' ,
20+ params = None )
1821
1922 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
2023 def test_get_challenge_statistics_by_id (self , mock_request , api_instance = api ):
2124 test_challenge_id = '12974'
22- mock_request .return_value .status_code = '200'
23- response = api_instance .get_challenge_statistics_by_id (test_challenge_id )
24- self .assertEqual (response ['status' ], '200' )
25+ api_instance .get_challenge_statistics_by_id (test_challenge_id )
26+ mock_request .assert_called_once_with (
27+ f'{ self .url } /data/challenge/{ test_challenge_id } ' ,
28+ params = None )
2529
2630 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
2731 def test_get_challenge_tasks (self , mock_request , api_instance = api ):
2832 test_challenge_id = '12974'
29- mock_request .return_value .status_code = '200'
30- response = api_instance .get_challenge_tasks (test_challenge_id )
31- self .assertEqual (response ['status' ], '200' )
33+ api_instance .get_challenge_tasks (test_challenge_id )
34+ mock_request .assert_called_once_with (
35+ f'{ self .url } /challenge/{ test_challenge_id } /tasks' ,
36+ params = {'limit' : '10' ,
37+ 'page' : '0' })
3238
3339 @patch ('maproulette.api.maproulette_server.requests.Session.post' )
3440 def test_create_challenge (self , mock_request , api_instance = api ):
3541 test_challenge_model = maproulette .ChallengeModel (name = 'Test_Challenge_Name' ,
3642 instruction = 'Do something' ,
3743 description = 'This is a test challenge' ,
3844 overpassQL = test_overpassQL_query )
39- mock_request .return_value .status_code = '200'
40- response = api_instance .create_challenge (test_challenge_model )
41- self .assertEqual (response ['status' ], '200' )
45+ api_instance .create_challenge (test_challenge_model )
46+ mock_request .assert_called_once_with (
47+ f'{ self .url } /challenge' ,
48+ json = json .loads (create_challenge_output ),
49+ params = None )
4250
4351 @patch ('maproulette.api.maproulette_server.requests.Session.put' )
4452 def test_add_tasks_to_challenge (self , mock_request , api_instance = api ):
4553 test_challenge_id = '12978'
46- mock_request .return_value .status_code = '200'
47- response = api_instance .add_tasks_to_challenge (test_geojson , test_challenge_id )
48- self .assertEqual (response ['status' ], '200' )
54+ api_instance .add_tasks_to_challenge (test_geojson , test_challenge_id )
55+ mock_request .assert_called_once_with (
56+ f'{ self .url } /challenge/12978/addTasks' ,
57+ json = test_geojson ,
58+ params = None )
4959
5060 @patch ('maproulette.api.maproulette_server.requests.Session.post' )
5161 def test_create_virtual_challenge (self , mock_request , api_instance = api ):
@@ -54,17 +64,20 @@ def test_create_virtual_challenge(self, mock_request, api_instance=api):
5464 instruction = 'Do something' ,
5565 description = 'This is a test challenge' ,
5666 overpassQL = test_overpassQL_query )
57- mock_request .return_value .status_code = '200'
58- response = api_instance .create_virtual_challenge (test_challenge_model )
59- self .assertEqual (response ['status' ], '200' )
67+ api_instance .create_virtual_challenge (test_challenge_model )
68+ mock_request .assert_called_once_with (
69+ f'{ self .url } /virtualchallenge' ,
70+ json = test_challenge_model ,
71+ params = None )
6072
6173 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
6274 def test_get_challenge_by_name (self , mock_request , api_instance = api ):
6375 test_project_id = '12345'
6476 test_challenge_name = 'Test_Challenge_Name'
65- mock_request .return_value .status_code = '200'
66- response = api_instance .get_challenge_by_name (test_project_id , test_challenge_name )
67- self .assertEqual (response ['status' ], '200' )
77+ api_instance .get_challenge_by_name (test_project_id , test_challenge_name )
78+ mock_request .assert_called_once_with (
79+ f'{ self .url } /project/{ test_project_id } /challenge/{ test_challenge_name } ' ,
80+ params = None )
6881
6982 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
7083 def test_get_challenges_by_tags (self , mock_request , api_instance = api ):
@@ -76,79 +89,107 @@ def test_get_challenges_by_tags(self, mock_request, api_instance=api):
7689 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
7790 def test_get_virtual_challenge_by_id (self , mock_request , api_instance = api ):
7891 test_virtual_challenge_id = '12345'
79- mock_request .return_value .status_code = '200'
80- response = api_instance .get_virtual_challenge_by_id (test_virtual_challenge_id )
81- self .assertEqual (response ['status' ], '200' )
92+ api_instance .get_virtual_challenge_by_id (test_virtual_challenge_id )
93+ mock_request .assert_called_once_with (
94+ f'{ self .url } /virtualchallenge/{ test_virtual_challenge_id } ' ,
95+ params = None )
8296
8397 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
8498 def test_get_challenge_listing (self , mock_request , api_instance = api ):
8599 test_project_ids = '12345,67891,23456'
86- mock_request .return_value .status_code = '200'
87- response = api_instance .get_challenge_listing (test_project_ids )
88- self .assertEqual (response ['status' ], '200' )
100+ api_instance .get_challenge_listing (test_project_ids )
101+ mock_request .assert_called_once_with (
102+ f'{ self .url } /challenges/listing' ,
103+ params = {'projectIds' : test_project_ids ,
104+ 'limit' : '10' ,
105+ 'page' : '0' ,
106+ 'onlyEnabled' : 'true' })
89107
90108 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
91109 def test_get_challenge_children (self , mock_request , api_instance = api ):
92110 test_challenge_id = '12345'
93- mock_request .return_value .status_code = '200'
94- response = api_instance .get_challenge_children (test_challenge_id )
95- self .assertEqual (response ['status' ], '200' )
111+ api_instance .get_challenge_children (test_challenge_id )
112+ mock_request .assert_called_once_with (
113+ f'{ self .url } /challenge/{ test_challenge_id } /children' ,
114+ params = {'limit' : '10' ,
115+ 'page' : '0' })
96116
97117 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
98118 def test_get_challenge_comments (self , mock_request , api_instance = api ):
99119 test_challenge_id = '12345'
100- mock_request .return_value .status_code = '200'
101- response = api_instance .get_challenge_comments (test_challenge_id )
102- self .assertEqual (response ['status' ], '200' )
120+ api_instance .get_challenge_comments (test_challenge_id )
121+ mock_request .assert_called_once_with (
122+ f'{ self .url } /challenge/{ test_challenge_id } /comments' ,
123+ params = {'limit' : '10' ,
124+ 'page' : '0' })
103125
104126 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
105127 def test_extract_challenge_comments (self , mock_request , api_instance = api ):
106128 test_challenge_id = '12345'
107- mock_request .return_value .status_code = '200'
108- response = api_instance .extract_challenge_comments (test_challenge_id )
109- self .assertEqual (response ['status' ], '200' )
129+ api_instance .extract_challenge_comments (test_challenge_id )
130+ mock_request .assert_called_once_with (
131+ f'{ self .url } /challenge/{ test_challenge_id } /comments/extract' ,
132+ params = {'limit' : '10' ,
133+ 'page' : '0' })
110134
111135 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
112136 def test_extract_task_summaries (self , mock_request , api_instance = api ):
113137 test_challenge_id = '12345'
114- mock_request .return_value .status_code = '200'
115- response = api_instance .extract_task_summaries (test_challenge_id )
116- self .assertEqual (response ['status' ], '200' )
138+ api_instance .extract_task_summaries (test_challenge_id )
139+ mock_request .assert_called_once_with (
140+ f'{ self .url } /challenge/{ test_challenge_id } /tasks/extract' ,
141+ params = {'limit' : '10' ,
142+ 'page' : '0' ,
143+ 'status' : '' ,
144+ 'reviewStatus' : '' ,
145+ 'priority' : '' ,
146+ 'exportProperties' : '' ,
147+ 'taskPropertySearch' : '' })
117148
118149 @patch ('maproulette.api.maproulette_server.requests.Session.get' )
119150 def test_get_challenge_geojson (self , mock_request , api_instance = api ):
120151 test_challenge_id = '12345'
121- mock_request .return_value .status_code = '200'
122- response = api_instance .get_challenge_geojson (test_challenge_id )
123- self .assertEqual (response ['status' ], '200' )
152+ api_instance .get_challenge_geojson (test_challenge_id )
153+ mock_request .assert_called_once_with (
154+ f'{ self .url } /challenge/view/{ test_challenge_id } ' ,
155+ params = {'status' : '' ,
156+ 'reviewStatus' : '' ,
157+ 'priority' : '' ,
158+ 'taskPropertySearch' : '' })
124159
125160 @patch ('maproulette.api.maproulette_server.requests.Session.put' )
126161 def test_update_task_priorities (self , mock_request , api_instance = api ):
127162 test_challenge_id = '12345'
128- mock_request .return_value .status_code = '200'
129- response = api_instance .update_task_priorities (test_challenge_id )
130- self .assertEqual (response ['status' ], '200' )
163+ api_instance .update_task_priorities (test_challenge_id )
164+ mock_request .assert_called_once_with (
165+ f'{ self .url } /challenge/{ test_challenge_id } /updateTaskPriorities' ,
166+ json = None ,
167+ params = None )
131168
132169 @patch ('maproulette.api.maproulette_server.requests.Session.put' )
133170 def test_reset_task_instructions (self , mock_request , api_instance = api ):
134171 test_challenge_id = '12345'
135- mock_request .return_value .status_code = '200'
136- response = api_instance .reset_task_instructions (test_challenge_id )
137- self .assertEqual (response ['status' ], '200' )
172+ api_instance .reset_task_instructions (test_challenge_id )
173+ mock_request .assert_called_once_with (
174+ f'{ self .url } /challenge/{ test_challenge_id } /resetTaskInstructions' ,
175+ json = None ,
176+ params = None )
138177
139178 @patch ('maproulette.api.maproulette_server.requests.Session.delete' )
140179 def test_delete_challenge (self , mock_request , api_instance = api ):
141180 test_challenge_id = '12345'
142- mock_request .return_value .status_code = '200'
143- response = api_instance .delete_challenge (test_challenge_id )
144- self .assertEqual (response ['status' ], '200' )
181+ api_instance .delete_challenge (test_challenge_id )
182+ mock_request .assert_called_once_with (
183+ f'{ self .url } /challenge/{ test_challenge_id } ' ,
184+ params = {'immediate' : 'false' })
145185
146186 @patch ('maproulette.api.maproulette_server.requests.Session.delete' )
147187 def test_delete_challenge_tasks (self , mock_request , api_instance = api ):
148188 test_challenge_id = '12345'
149- mock_request .return_value .status_code = '200'
150- response = api_instance .delete_challenge_tasks (test_challenge_id )
151- self .assertEqual (response ['status' ], '200' )
189+ api_instance .delete_challenge_tasks (test_challenge_id )
190+ mock_request .assert_called_once_with (
191+ f'{ self .url } /challenge/{ test_challenge_id } /tasks' ,
192+ params = {'statusFilters' : '' })
152193
153194 @patch ('maproulette.api.maproulette_server.requests.Session.put' )
154195 def test_update_challenge (self , mock_request , api_instance = api ):
@@ -157,6 +198,8 @@ def test_update_challenge(self, mock_request, api_instance=api):
157198 instruction = 'Do something' ,
158199 description = 'This is a test challenge' ,
159200 overpassQL = test_overpassQL_query )
160- mock_request .return_value .status_code = '200'
161- response = api_instance .update_challenge (test_challenge_id , test_challenge_model )
162- self .assertEqual (response ['status' ], '200' )
201+ api_instance .update_challenge (test_challenge_id , test_challenge_model )
202+ mock_request .assert_called_once_with (
203+ f'{ self .url } /challenge/{ test_challenge_id } ' ,
204+ json = json .loads (create_challenge_output ),
205+ params = None )
0 commit comments