diff --git a/tests/data/challenge_response.py b/tests/data/challenge_response.py index 624188e2a..c70a88735 100644 --- a/tests/data/challenge_response.py +++ b/tests/data/challenge_response.py @@ -427,6 +427,16 @@ """ +challenge_last_submission_stats = """ + { + "last_submission_timestamp_in_challenge": "2019-01-24T14:05:34.693148Z", + "last_submission_timestamp_in_challenge_phase": "You dont have any submissions \ + in this challenge phase!", + "challenge_phase": 349 + } +""" + + last_submission_stats = """ { "challenge_phase": 1, diff --git a/tests/test_requests.py b/tests/test_requests.py index 402d08e90..eac6540f4 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -321,7 +321,7 @@ def test_create_team_for_object_does_not_exist(self): assert response == expected @responses.activate - def test_participate_in_a_challenge_for_object_does_not_exist(self): + def test_participate_in_a_challenge_when_object_does_not_exist(self): runner = CliRunner() result = runner.invoke(challenge, ['2', 'participate', '3']) response = result.output.rstrip() @@ -364,6 +364,27 @@ def test_display_challenge_last_submission_stats_url_for_object_does_not_exist(s url = "{}{}".format(API_HOST_URL, URLS.last_submission_stats.value).format("1", "3") assert response == "404 Client Error: Not Found for url: {}".format(url) + @responses.activate + def test_display_challenge_analytics_url_for_object_does_not_exist(self): + url = "{}{}" + challenge_count_stats_json = json.loads(challenge_response.challenge_count_stats) + challenge_last_submission_stats_json = json.loads(challenge_response.challenge_last_submission_stats) + + responses.add(responses.GET, url.format(API_HOST_URL, URLS.count_stats.value).format('1', '3'), + json=challenge_count_stats_json, status=200) + + responses.add(responses.GET, url.format(API_HOST_URL, URLS.last_submission_stats.value).format('1', '3'), + json=challenge_last_submission_stats_json, status=200) + + responses.add(responses.GET, url.format(API_HOST_URL, URLS.analytics.value).format('1', '3'), + status=404) + + runner = CliRunner() + result = runner.invoke(challenge, ['1', 'stats']) + response = result.output.rstrip() + url = "{}{}".format(API_HOST_URL, URLS.analytics.value).format("1", "3") + assert response == "404 Client Error: Not Found for url: {}".format(url) + class TestDisplayChallengeStatsForRequestException(BaseTestClass): @@ -386,11 +407,30 @@ def test_display_challenge_count_stats_url_for_request_exception(self): def test_display_challenge_last_submission_stats_url_for_request_exception(self): url = "{}{}" challenge_count_stats_json = json.loads(challenge_response.challenge_count_stats) + + responses.add(responses.GET, url.format(API_HOST_URL, URLS.count_stats.value).format('1', '3'), + json=challenge_count_stats_json, status=200) + responses.add(responses.GET, url.format(API_HOST_URL, URLS.last_submission_stats.value).format('1', '3'), + body=RequestException('...')) + runner = CliRunner() + result = runner.invoke(challenge, ['1', 'stats']) + assert result.exit_code == 1 + + @responses.activate + def test_display_challenge_analytics_url_for_request_exception(self): + url = "{}{}" + challenge_count_stats_json = json.loads(challenge_response.challenge_count_stats) + challenge_last_submission_stats_json = json.loads(challenge_response.challenge_last_submission_stats) + responses.add(responses.GET, url.format(API_HOST_URL, URLS.count_stats.value).format('1', '3'), json=challenge_count_stats_json, status=200) responses.add(responses.GET, url.format(API_HOST_URL, URLS.last_submission_stats.value).format('1', '3'), + json=challenge_last_submission_stats_json, status=200) + + responses.add(responses.GET, url.format(API_HOST_URL, URLS.analytics.value).format('1', '3'), body=RequestException('...')) + runner = CliRunner() result = runner.invoke(challenge, ['1', 'stats']) assert result.exit_code == 1