Skip to content

Commit

Permalink
Add tests to cover the analytics url
Browse files Browse the repository at this point in the history
  • Loading branch information
guyandtheworld committed Jan 24, 2019
1 parent 3619e68 commit dc17d1b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/data/challenge_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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
Expand Down

0 comments on commit dc17d1b

Please sign in to comment.