Skip to content

Commit

Permalink
Add unittest for json report creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tobami committed Feb 21, 2011
1 parent f0a2cf4 commit 522685e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 1 addition & 2 deletions speedcenter/codespeed/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def getlogs(endrev, startrev):

p = Popen(cmd, stdout=PIPE, stderr=PIPE, cwd=working_copy)
stdout, stderr = p.communicate()
print stdout
print stderr

if stderr:
return [{'error': True, 'message': stderr}]
else:
Expand Down
19 changes: 14 additions & 5 deletions speedcenter/codespeed/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ def test_add_correct_results(self):
)
self.assertTrue(res.value, 458)

number_of_reports = len(Report.objects.all())
# After adding 4 result for 3 revisions, only 2 reports should be created
# The third revision will need a result for Richards2 in order to trigger report creation
self.assertEquals(number_of_reports, 1)

def test_bad_environment(self):
"""Add result associated with non-existing environment.
Only change one item in the list.
Expand Down Expand Up @@ -259,6 +254,20 @@ def test_missing_argument(self):
self.assertEquals(response.content, 'Key "' + key + '" missing from request')
data[key] = backup

def test_report_is_created(self):
'''Should create a report when adding json results for two revisions
plus a third revision with one result less than the last one'''
response = self.client.post(self.path, {'json' : json.dumps(self.data)})

# Check that we get a success response
self.assertEquals(response.status_code, 202)

number_of_reports = len(Report.objects.all())
# After adding 4 result for 3 revisions, only 2 reports should be created
# The third revision will need an extra result for Richards2 in order
# to trigger report creation
self.assertEquals(number_of_reports, 1)


class Timeline(TestCase):
fixtures = ["pypy.json"]
Expand Down
4 changes: 3 additions & 1 deletion speedcenter/codespeed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,9 @@ def add_json_results(request):
logging.debug("add_json_results: save item %d." % i)
response, error = save_result(result)
if error:
logging.debug("could not save item %d because %s" % (i, response))
logging.debug(
"add_json_results: could not save item %d because %s" % (
i, response))
return HttpResponseBadRequest(response)
else:
unique_reports.add(response)
Expand Down

0 comments on commit 522685e

Please sign in to comment.