Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
add test for crontabber_state_json() view -- bug 888952
@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