Пример #1
0
    def test_do_summary(self):
        fake_request = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(stacky_server, "get_event_names")
        events = [{"event": "test.start"}, {"event": "test.end"}]
        stacky_server.get_event_names().AndReturn(events)
        fake_request.GET = {"name": "test.event"}
        results = self.mox.CreateMockAnything()
        models.Timing.objects.filter(name="test").AndReturn(results)
        results.exclude(mox.IgnoreArg()).AndReturn(results)
        results.exclude(diff__lt=0).AndReturn(results)
        timing1 = self.mox.CreateMockAnything()
        timing1.lifecycle = self.mox.CreateMockAnything()
        timing1.lifecycle.instance = INSTANCE_ID_1
        timing1.diff = 10
        timing2 = self.mox.CreateMockAnything()
        timing2.lifecycle = self.mox.CreateMockAnything()
        timing2.lifecycle.instance = INSTANCE_ID_2
        timing2.diff = 20
        results.__len__().AndReturn(2)
        results.__iter__().AndReturn([timing1, timing2].__iter__())
        self.mox.ReplayAll()

        resp = stacky_server.do_summary(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], ["Event", "N", "Min", "Max", "Avg"])
        self.assertEqual(json_resp[1], [u"test", 2, u"0d 00:00:10.0", u"0d 00:00:20.0", u"0d 00:00:15"])

        self.mox.VerifyAll()
Пример #2
0
    def test_do_watch_with_event_name(self):
        fake_request = self.mox.CreateMockAnything()
        fake_request.GET = {"event_name": "test.start"}
        self.mox.StubOutWithMock(stacky_server, "get_deployments")
        deployment1 = self.mox.CreateMockAnything()
        deployment1.id = 1
        deployment1.name = "dep1"
        deployments = [deployment1]
        stacky_server.get_deployments().AndReturn(deployments)
        self.mox.StubOutWithMock(stacky_server, "get_event_names")
        events = [{"event": "test.start"}, {"event": "test.end"}]
        stacky_server.get_event_names().AndReturn(events)
        results = self.mox.CreateMockAnything()
        models.RawData.objects.order_by("when").AndReturn(results)
        results.filter(event="test.start").AndReturn(results)
        results.filter(when__gt=mox.IgnoreArg()).AndReturn(results)
        results.filter(when__lte=mox.IgnoreArg()).AndReturn(results)
        results.__iter__().AndReturn([self._create_raw()].__iter__())
        self.mox.ReplayAll()

        resp = stacky_server.do_watch(fake_request, 0)
        self.assertEqual(resp.status_code, 200)
        json_resp = json.loads(resp.content)
        self.assertEqual(len(json_resp), 3)
        self.assertEqual(json_resp[0], [10, 1, 15, 20, 10, 36])
        print json_resp
        self.assertEqual(json_resp[1][0][0], 1)
        self.assertEqual(json_resp[1][0][1], u" ")
        time_str = "%s %s" % (json_resp[1][0][2], json_resp[1][0][3])
        datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S.%f")
        self.assertEqual(json_resp[1][0][4], u"dep1")
        self.assertEqual(json_resp[1][0][5], u"test.start")
        self.assertEqual(json_resp[1][0][6], u"%s" % INSTANCE_ID_1)
        self.mox.VerifyAll()
Пример #3
0
    def test_do_watch_with_event_name(self):
        fake_request = self.mox.CreateMockAnything()
        fake_request.GET = {'event_name': 'test.start'}
        self.mox.StubOutWithMock(stacky_server, 'get_deployments')
        deployment1 = self.mox.CreateMockAnything()
        deployment1.id = 1
        deployment1.name = 'dep1'
        deployments = [deployment1]
        stacky_server.get_deployments().AndReturn(deployments)
        self.mox.StubOutWithMock(stacky_server, 'get_event_names')
        events = [{'event': 'test.start'}, {'event': 'test.end'}]
        stacky_server.get_event_names().AndReturn(events)
        results = self.mox.CreateMockAnything()
        models.RawData.objects.order_by('when').AndReturn(results)
        results.filter(event='test.start').AndReturn(results)
        results.filter(when__gt=mox.IgnoreArg()).AndReturn(results)
        results.filter(when__lte=mox.IgnoreArg()).AndReturn(results)
        results.__iter__().AndReturn([self._create_raw()].__iter__())
        self.mox.ReplayAll()

        resp = stacky_server.do_watch(fake_request, 0)
        self.assertEqual(resp.status_code, 200)
        json_resp = json.loads(resp.content)
        self.assertEqual(len(json_resp), 3)
        self.assertEqual(json_resp[0], [10, 1, 15, 20, 10, 36])
        print json_resp
        self.assertEqual(json_resp[1][0][0], 1)
        self.assertEqual(json_resp[1][0][1], u' ')
        time_str = "%s %s" % (json_resp[1][0][2], json_resp[1][0][3])
        datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S.%f")
        self.assertEqual(json_resp[1][0][4], u'dep1')
        self.assertEqual(json_resp[1][0][5], u'test.start')
        self.assertEqual(json_resp[1][0][6], u'%s' % INSTANCE_ID_1)
        self.mox.VerifyAll()
Пример #4
0
    def test_do_summary(self):
        fake_request = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(stacky_server, 'get_event_names')
        events = [{'event': 'test.start'}, {'event': 'test.end'}]
        stacky_server.get_event_names().AndReturn(events)
        fake_request.GET = {'name': 'test.event'}
        results = self.mox.CreateMockAnything()
        models.Timing.objects.filter(name='test').AndReturn(results)
        results.exclude(mox.IgnoreArg()).AndReturn(results)
        results.exclude(diff__lt=0).AndReturn(results)
        timing1 = self.mox.CreateMockAnything()
        timing1.lifecycle = self.mox.CreateMockAnything()
        timing1.lifecycle.instance = INSTANCE_ID_1
        timing1.diff = 10
        timing2 = self.mox.CreateMockAnything()
        timing2.lifecycle = self.mox.CreateMockAnything()
        timing2.lifecycle.instance = INSTANCE_ID_2
        timing2.diff = 20
        results.__len__().AndReturn(2)
        results.__iter__().AndReturn([timing1, timing2].__iter__())
        self.mox.ReplayAll()

        resp = stacky_server.do_summary(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], ["Event", "N", "Min", "Max", "Avg"])
        self.assertEqual(
            json_resp[1],
            [u'test', 2, u'0d 00:00:10.0', u'0d 00:00:20.0', u'0d 00:00:15'])

        self.mox.VerifyAll()
Пример #5
0
    def test_do_events(self):
        fake_request = self.mox.CreateMockAnything()
        event1 = {"event": "some.event.1"}
        event2 = {"event": "some.event.2"}
        events = [event1, event2]
        self.mox.StubOutWithMock(stacky_server, "get_event_names")
        stacky_server.get_event_names().AndReturn(events)
        self.mox.ReplayAll()

        resp = stacky_server.do_events(fake_request)

        self.assertEqual(resp.status_code, 200)
        json_resp = json.loads(resp.content)
        self.assertEqual(len(json_resp), 3)
        self.assertEqual(json_resp[0], ["Event Name"])
        self.assertEqual(json_resp[1], ["some.event.1"])
        self.assertEqual(json_resp[2], ["some.event.2"])
        self.mox.VerifyAll()
Пример #6
0
    def test_do_events(self):
        fake_request = self.mox.CreateMockAnything()
        event1 = {'event': 'some.event.1'}
        event2 = {'event': 'some.event.2'}
        events = [event1, event2]
        self.mox.StubOutWithMock(stacky_server, 'get_event_names')
        stacky_server.get_event_names().AndReturn(events)
        self.mox.ReplayAll()

        resp = stacky_server.do_events(fake_request)

        self.assertEqual(resp.status_code, 200)
        json_resp = json.loads(resp.content)
        self.assertEqual(len(json_resp), 3)
        self.assertEqual(json_resp[0], ['Event Name'])
        self.assertEqual(json_resp[1], ['some.event.1'])
        self.assertEqual(json_resp[2], ['some.event.2'])
        self.mox.VerifyAll()
Пример #7
0
    def test_get_event_names(self):
        result = self.mox.CreateMockAnything()
        models.RawData.objects.values("event").AndReturn(result)
        result.distinct().AndReturn(result)
        self.mox.ReplayAll()

        event_names = stacky_server.get_event_names()
        self.assertEqual(event_names, result)

        self.mox.VerifyAll()
Пример #8
0
    def test_get_event_names(self):
        result = self.mox.CreateMockAnything()
        models.RawData.objects.values('event').AndReturn(result)
        result.distinct().AndReturn(result)
        self.mox.ReplayAll()

        event_names = stacky_server.get_event_names()
        self.assertEqual(event_names, result)

        self.mox.VerifyAll()