Created
July 30, 2013 23:38
-
-
Save GabiThume/6118035 to your computer and use it in GitHub Desktop.
add test for crontabber_state_json() view -- bug 888952
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mock.patch('requests.get') | |
def test_crontabber_state_json(self, rget): | |
url = reverse('crashstats.crontabber_state_json') | |
def mocked_get(**options): | |
assert 'crontabber_state' in options['url'] | |
return Response(""" | |
{ | |
"state": { | |
"slow-one": { | |
"next_run": "2013-02-19 01:16:00.893834", | |
"first_run": "2012-11-05 23:27:07.316347", | |
"last_error": { | |
"traceback": "error error error", | |
"type": "<class 'sluggish.jobs.InternalError'>", | |
"value": "Have already run this for 2012-12-24 23:27" | |
}, | |
"last_run": "2013-02-09 00:16:00.893834", | |
"last_success": "2012-12-24 22:27:07.316893", | |
"error_count": 6, | |
"depends_on": [] | |
} | |
} | |
} | |
""") | |
rget.side_effect = mocked_get | |
response = self.client.get(url) | |
struct = json.loads(response.content) | |
eq_(response.status_code, 200) | |
ok_(response.content.strip().startswith('{')) | |
ok_('application/json' in response['Content-Type']) | |
ok_('state' in response.content) | |
eq_(struct['state']["slow-one"]["next_run"], | |
"2013-02-19 01:16:00.893834") | |
eq_(struct['state']["slow-one"]["last_success"], | |
"2012-12-24 22:27:07.316893") | |
eq_(struct['state']["slow-one"]["last_error"]["type"], | |
"<class 'sluggish.jobs.InternalError'>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment