Skip to content

Commit 9651115

Browse files
authored
Merge pull request #79 from hfs/challenge-rebuild
Add endpoint to rebuild challenge
2 parents 0a3e4b6 + f5e625f commit 9651115

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

maproulette/api/challenge.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,23 @@ def update_challenge(self, challenge_id, data):
325325
body=data)
326326
return response
327327

328+
def rebuild_challenge(self, challenge_id, remove_unmatched=False, skip_snapshot=False):
329+
"""Rebuild the challenge by re-creating the tasks from the task data source
330+
331+
:param challenge_id: the ID corresponding to the challenge
332+
:param remove_unmatched: Used to remove incomplete tasks that have been addressed externally since the last
333+
rebuild, assuming the source data represents all tasks outstanding. If set to true, all existing tasks in
334+
CREATED or SKIPPED status (only) will be removed prior to rebuilding with the assumption that they will be
335+
recreated if they still appear in the updated source data. If set to false, unmatched existing tasks are
336+
simply left as-is. Default: False
337+
:param skipSnapshot: Whether to skip recording a snapshot before proceeding. Default: False
338+
"""
339+
response = self.put(
340+
endpoint=f"/challenge/{challenge_id}/rebuild",
341+
params={'removeUnmatched': str(remove_unmatched).lower(), 'skipSnapshot': str(skip_snapshot).lower()}
342+
)
343+
return response
344+
328345
@staticmethod
329346
def is_challenge_model(input_object):
330347
"""Method to determine whether user input is a valid challenge model

tests/test_challenge_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,12 @@ def test_update_challenge(self, mock_request, api_instance=api):
203203
f'{self.url}/challenge/{test_challenge_id}',
204204
json=json.loads(create_challenge_output),
205205
params=None)
206+
207+
@patch('maproulette.api.maproulette_server.requests.Session.put')
208+
def test_rebuild_challenge(self, mock_request, api_instance=api):
209+
test_challenge_id = '12345'
210+
api_instance.rebuild_challenge(test_challenge_id, True, True)
211+
mock_request.assert_called_once_with(
212+
f'{self.url}/challenge/{test_challenge_id}/rebuild',
213+
params={'removeUnmatched': 'true', 'skipSnapshot': 'true'},
214+
json=None)

0 commit comments

Comments
 (0)