def test_do_request(self): fake_request = self.mox.CreateMockAnything() fake_request.GET = {"request_id": REQUEST_ID_1} raw = self._create_raw() results = self.mox.CreateMockAnything() models.RawData.objects.filter(request_id=REQUEST_ID_1).AndReturn(results) results.order_by("when").AndReturn(results) results.__iter__().AndReturn([raw].__iter__()) self.mox.ReplayAll() resp = stacky_server.do_request(fake_request) self.assertEqual(resp.status_code, 200) json_resp = json.loads(resp.content) self.assertEqual(len(json_resp), 2) self.assertEqual(json_resp[0], ["#", "?", "When", "Deployment", "Event", "Host", "State", "State'", "Task'"]) self.assertEqual(json_resp[1][0], 1) self.assertEqual(json_resp[1][1], u" ") self.assertEqual(json_resp[1][2], str(dt.dt_from_decimal(raw.when))) self.assertEqual(json_resp[1][3], u"deployment") self.assertEqual(json_resp[1][4], u"test.start") self.assertEqual(json_resp[1][5], u"example.com") self.assertEqual(json_resp[1][6], u"active") self.assertEqual(json_resp[1][7], None) self.assertEqual(json_resp[1][8], None) self.mox.VerifyAll()
def test_do_request(self): fake_request = self.mox.CreateMockAnything() fake_request.GET = {'request_id': REQUEST_ID_1} raw = self._create_raw() results = self.mox.CreateMockAnything() models.RawData.objects.filter( request_id=REQUEST_ID_1).AndReturn(results) results.order_by('when').AndReturn(results) results.__iter__().AndReturn([raw].__iter__()) self.mox.ReplayAll() resp = stacky_server.do_request(fake_request) self.assertEqual(resp.status_code, 200) json_resp = json.loads(resp.content) self.assertEqual(len(json_resp), 2) self.assertEqual(json_resp[0], [ "#", "?", "When", "Deployment", "Event", "Host", "State", "State'", "Task'" ]) self.assertEqual(json_resp[1][0], 1) self.assertEqual(json_resp[1][1], u' ') self.assertEqual(json_resp[1][2], str(dt.dt_from_decimal(raw.when))) self.assertEqual(json_resp[1][3], u'deployment') self.assertEqual(json_resp[1][4], u'test.start') self.assertEqual(json_resp[1][5], u'example.com') self.assertEqual(json_resp[1][6], u'active') self.assertEqual(json_resp[1][7], None) self.assertEqual(json_resp[1][8], None) self.mox.VerifyAll()
def test_do_request_bad_request_id(self): fake_request = self.mox.CreateMockAnything() fake_request.GET = {"request_id": "obviouslybaduuid"} self.mox.ReplayAll() resp = stacky_server.do_request(fake_request) self.assertEqual(resp.status_code, 400) resp_json = json.loads(resp.content) self.assertEqual(len(resp_json), 2) self.assertEqual(resp_json[0], ["Error", "Message"]) msg = "obviouslybaduuid is not request-id-like" self.assertEqual(resp_json[1], ["Bad Request", msg]) self.mox.VerifyAll()
def test_do_request_bad_request_id(self): fake_request = self.mox.CreateMockAnything() fake_request.GET = {'request_id': "obviouslybaduuid"} self.mox.ReplayAll() resp = stacky_server.do_request(fake_request) self.assertEqual(resp.status_code, 400) resp_json = json.loads(resp.content) self.assertEqual(len(resp_json), 2) self.assertEqual(resp_json[0], ['Error', 'Message']) msg = 'obviouslybaduuid is not request-id-like' self.assertEqual(resp_json[1], ['Bad Request', msg]) self.mox.VerifyAll()