Skip to content

Commit

Permalink
Add tests for analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
guyandtheworld committed Jan 24, 2019
1 parent a98b9cf commit 3619e68
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/data/challenge_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,13 @@
"last_submission_timestamp_in_challenge_phase": "2018-07-15T04:37:26.717957Z"
}
"""

challenge_analytics = """
{
"total_submissions": 7195,
"participant_team_count": 159,
"flagged_submissions_count": 0,
"public_submissions_count": 0,
"challenge_phase": 199
}
"""
8 changes: 7 additions & 1 deletion tests/test_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ def setup(self):
self.challenge_phase_list_json = json.loads(challenge_response.challenge_phase_stats)
self.challenge_count_stats_json = json.loads(challenge_response.challenge_count_stats)
self.last_submission_stats_json = json.loads(challenge_response.last_submission_stats)
self.challenge_analytics = json.loads(challenge_response.challenge_analytics)

url = "{}{}"
responses.add(responses.GET, url.format(API_HOST_URL, URLS.challenge_phase_list.value).format('1'),
Expand All @@ -742,19 +743,24 @@ def setup(self):
responses.add(responses.GET, url.format(API_HOST_URL, URLS.last_submission_stats.value).format('1', '3'),
json=self.last_submission_stats_json, status=200)

responses.add(responses.GET, url.format(API_HOST_URL, URLS.analytics.value).format('1', '3'),
json=self.challenge_analytics, status=200)

@responses.activate
def test_display_challenge_stats(self):
stats = {}
stats["Philip Phase"] = []
stats["Philip Phase"].append(self.challenge_count_stats_json)
stats["Philip Phase"].append(self.last_submission_stats_json)
stats["Philip Phase"].append(self.challenge_analytics)
table = BeautifulTable(max_width=150)
table.column_headers = ["ID", "Phase", "Total Submissions", "Latest Submission At"]
table.column_headers = ["ID", "Phase", "Total Submissions", "Total Participant Teams", "Latest Submission At"]
for key in stats:
values = []
values.append(stats[key][0]["challenge_phase"])
values.append(key)
values.append(stats[key][0]["participant_team_submission_count"])
values.append(stats[key][2]["participant_team_count"])
label = "last_submission_timestamp_in_challenge_phase"
if (label in stats[key][1].keys() and
stats[key][1][label] != "You dont have any submissions in this challenge phase!"):
Expand Down

0 comments on commit 3619e68

Please sign in to comment.