Bug 1134916 - Fix tests that depend on jobs API response order

Tests that are not aimed at the jobs API should not be dependant on the
order of jobs returned by get_job_list().

* test_tbpl.py does not even need to use get_job_list() since the only
  accessed property is the job_id, which we are better off hard-coding.
* test_note_apy.py should use the job_id found earlier in the test,
  rather than hard-coding a wrong value.
* In test_bug_job_map_api.py, there is no ORDER BY clause for the stored
  get_bug_job_map_list query. The current test only happens to pass
  since the bug_job_map table currently uses the InnoDB engine, which
  default to the order of the primary key. Were our test environment and
  production bug_job_map tables to use different engines, the behaviour
  would silently change, so it seems wrong for the test to give the
  illusion of a guaranteed order. If in the future we wanted to give
  such a guarantee, we should add an ORDER BY to the
  get_bug_job_map_list query & update the test accordingly.
This commit is contained in:
Ed Morley 2015-02-23 13:32:57 +00:00
Родитель d6400a4115
Коммит 6fca7fe4ac
3 изменённых файлов: 16 добавлений и 16 удалений

Просмотреть файл

@ -15,21 +15,21 @@ def test_tbpl_bug_request_body(jm, eleven_jobs_processed):
Test the request body is created correctly
"""
bug_id = 12345678
job = jm.get_job_list(0, 1)[0]
job_id = 1
sample_artifact = {
"build_id": 39953854,
"buildername": "b2g_emulator_vm mozilla-inbound opt test crashtest-2"
}
placeholders = [
[job["id"], "buildapi", "json",
json.dumps(sample_artifact), job["id"], "buildapi"]
[job_id, "buildapi", "json",
json.dumps(sample_artifact), job_id, "buildapi"]
]
jm.store_job_artifact(placeholders)
submit_timestamp = int(time())
who = "user@mozilla.com"
req = OrangeFactorBugRequest(jm.project, job["id"],
req = OrangeFactorBugRequest(jm.project, job_id,
bug_id, submit_timestamp, who)
req.generate_request_body()
@ -58,7 +58,7 @@ def test_tbpl_bugzilla_request_body(jm, eleven_jobs_processed):
Test the request body is created correctly
"""
bug_id = 12345678
job = jm.get_job_list(0, 1)[0]
job_id = 1
who = "user@mozilla.com"
bug_suggestions = []
@ -66,13 +66,13 @@ def test_tbpl_bugzilla_request_body(jm, eleven_jobs_processed):
bug_suggestions.append({"search": "Second error line", "bugs": []})
bug_suggestions_placeholders = [
job['id'], 'Bug suggestions',
job_id, 'Bug suggestions',
'json', json.dumps(bug_suggestions),
job['id'], 'Bug suggestions',
job_id, 'Bug suggestions',
]
jm.store_job_artifact([bug_suggestions_placeholders])
req = BugzillaBugRequest(jm.project, job["id"], bug_id, who)
req = BugzillaBugRequest(jm.project, job_id, bug_id, who)
req.generate_request_body()
expected = {
@ -94,7 +94,7 @@ def test_tbpl_bugzilla_comment_length_capped(jm, eleven_jobs_processed):
Test that the total number of characters in the comment is capped correctly.
"""
bug_id = 12345678
job = jm.get_job_list(0, 1)[0]
job_id = 1
who = "user@mozilla.com"
# Create an error line with length equal to the max comment length.
@ -103,13 +103,13 @@ def test_tbpl_bugzilla_comment_length_capped(jm, eleven_jobs_processed):
bug_suggestions = [{"search": "a" * settings.BZ_MAX_COMMENT_LENGTH, "bugs": []}]
bug_suggestions_placeholders = [
job['id'], 'Bug suggestions',
job_id, 'Bug suggestions',
'json', json.dumps(bug_suggestions),
job['id'], 'Bug suggestions',
job_id, 'Bug suggestions',
]
jm.store_job_artifact([bug_suggestions_placeholders])
req = BugzillaBugRequest(jm.project, job["id"], bug_id, who)
req = BugzillaBugRequest(jm.project, job_id, bug_id, who)
req.generate_request_body()
assert len(req.body['comment']) == settings.BZ_MAX_COMMENT_LENGTH

Просмотреть файл

@ -133,8 +133,8 @@ def test_bug_job_map_list(webapp, jm, eleven_jobs_processed):
resp = webapp.get(
reverse("bug-job-map-list", kwargs={"project": jm.project}))
for i, v in enumerate(expected):
assert v == resp.json[i]
# The order of the bug-job-map list is not guaranteed.
assert sorted(resp.json) == sorted(expected)
jm.disconnect()

Просмотреть файл

@ -148,13 +148,13 @@ def test_create_note(webapp, eleven_jobs_processed, mock_message_broker, jm):
assert resp.status_code == 200
content = json.loads(resp.content)
assert content['message'] == 'note stored for job 1'
assert content['message'] == 'note stored for job %s' % job["id"]
note_list = jm.get_job_note_list(job_id=job["id"])
del(note_list[0]["note_timestamp"])
assert note_list[0] == {
u'job_id': 1L,
u'job_id': job["id"],
u'who': u'foo@bar.com',
u'failure_classification_id': 2L,
u'note': u'you look like a man-o-lantern',