Beispiel #1
0
    def test_do_uuid(self):
        fake_request = self.mox.CreateMockAnything()
        fake_request.GET = {'uuid': INSTANCE_ID_1}
        result = self.mox.CreateMockAnything()
        models.RawData.objects.select_related().AndReturn(result)
        result.filter(instance=INSTANCE_ID_1).AndReturn(result)
        result.order_by('when').AndReturn(result)
        raw = self._create_raw()
        result.__iter__().AndReturn([raw].__iter__())
        self.mox.ReplayAll()

        resp = stacky_server.do_uuid(fake_request)

        self.assertEqual(resp.status_code, 200)
        json_resp = json.loads(resp.content)
        self.assertEqual(len(json_resp), 2)
        header = [
            "#", "?", "When", "Deployment", "Event", "Host", "State", "State'",
            "Task'"
        ]
        self.assertEqual(json_resp[0], header)
        datetime = dt.dt_from_decimal(raw.when)
        body = [
            1, " ",
            str(datetime), "deployment", "test.start", "example.com", "active",
            None, None
        ]
        self.assertEqual(json_resp[1], body)
        self.mox.VerifyAll()
    def test_do_uuid_bad_uuid(self):
        fake_request = self.mox.CreateMockAnything()
        fake_request.GET = {"uuid": "obviouslybaduuid"}
        self.mox.ReplayAll()

        resp = stacky_server.do_uuid(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 uuid-like"
        self.assertEqual(resp_json[1], ["Bad Request", msg])
        self.mox.VerifyAll()
Beispiel #3
0
    def test_do_uuid_bad_uuid(self):
        fake_request = self.mox.CreateMockAnything()
        fake_request.GET = {'uuid': "obviouslybaduuid"}
        self.mox.ReplayAll()

        resp = stacky_server.do_uuid(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 uuid-like'
        self.assertEqual(resp_json[1], ['Bad Request', msg])
        self.mox.VerifyAll()
    def test_do_uuid(self):
        fake_request = self.mox.CreateMockAnything()
        fake_request.GET = {"uuid": INSTANCE_ID_1}
        result = self.mox.CreateMockAnything()
        models.RawData.objects.select_related().AndReturn(result)
        result.filter(instance=INSTANCE_ID_1).AndReturn(result)
        result.order_by("when").AndReturn(result)
        raw = self._create_raw()
        result.__iter__().AndReturn([raw].__iter__())
        self.mox.ReplayAll()

        resp = stacky_server.do_uuid(fake_request)

        self.assertEqual(resp.status_code, 200)
        json_resp = json.loads(resp.content)
        self.assertEqual(len(json_resp), 2)
        header = ["#", "?", "When", "Deployment", "Event", "Host", "State", "State'", "Task'"]
        self.assertEqual(json_resp[0], header)
        datetime = dt.dt_from_decimal(raw.when)
        body = [1, " ", str(datetime), "deployment", "test.start", "example.com", "active", None, None]
        self.assertEqual(json_resp[1], body)
        self.mox.VerifyAll()