Example #1
0
    def test_delete(self):
        self.pollute_events_and_perform_synthesis(10)

        yield AnomaliesSchedule().run()
        yield StatisticsSchedule().run()

        # be sure that AnomalyHistory is populated
        handler = self.request({}, role='admin')
        yield handler.get()
        self.assertEqual(len(self.responses), 1)
        self.assertTrue(isinstance(self.responses, list))

        self.responses = []

        # delete stats
        handler = self.request({}, role='admin')
        yield handler.delete()

        self.responses = []

        # test that AnomalyHistory is not populated anymore
        handler = self.request({}, role='admin')
        yield handler.get()
        self.assertEqual(len(self.responses), 0)
        self.assertTrue(isinstance(self.responses, list))
Example #2
0
    def test_save_anomalies(self):
        """
        How create anomalies: a lots of event + compute stress
        """

        # start test
        ANOMALIES_AMOUNT = 50
        pollute_events_for_testing(ANOMALIES_AMOUNT)

        Alarm.compute_activity_level()

        anomdet = GLSettings.RecentAnomaliesQ.values()[0]
        self.assertEqual(len(GLSettings.RecentAnomaliesQ.keys()), 1)
        original_date = datetime_to_ISO8601(
            GLSettings.RecentAnomaliesQ.keys()[0])

        self.assertTrue(isinstance(anomdet, list))
        self.assertTrue(len(anomdet), 2)

        # alarm level was 2, right ?
        self.assertEqual(anomdet[1], 2, "Alarm raised is not 2 anymore ?")

        # every stuff need to be ANOMALIES_AMOUNT * 2, because
        # pollute function put two event each
        for event, amount in anomdet[0].iteritems():
            self.assertEqual(amount, ANOMALIES_AMOUNT * 2)

        # scheduler happen to save these anomalies, along with stats
        yield StatisticsSchedule().operation()

        # now if we get our anomalies, we expect the same 10, right ?
        AH = yield get_anomaly_history(limit=10)
        self.assertEqual(original_date, AH[0]['date'])
Example #3
0
    def test_get(self):
        pollute_events_for_testing(3)
        yield AnomaliesSchedule().operation()
        yield StatisticsSchedule().operation()

        handler = self.request({}, role='admin')
        yield handler.get()

        self.assertTrue(isinstance(self.responses, list))
        self.assertEqual(len(self.responses), 1)
Example #4
0
    def test_get(self):
        self.pollute_events_and_perform_synthesis(10)

        yield AnomaliesSchedule().run()
        yield StatisticsSchedule().run()

        handler = self.request({}, role='admin')
        yield handler.get()

        self.assertTrue(isinstance(self.responses, list))
        self.assertEqual(len(self.responses), 1)
    def test_get(self):

        StatisticsSchedule().operation()

        handler = self.request({}, role='admin')
        yield handler.get()

        self.assertTrue(isinstance(self.responses, list))
        self.assertEqual(len(self.responses), 1)
        self.assertEqual(len(self.responses[0]), 1)
        self._handler.validate_message(json.dumps(self.responses[0]),
                                       requests.StatsCollection)
Example #6
0
    def test_get(self):
        self.pollute_events_and_perform_synthesis(10)

        yield AnomaliesSchedule().run()
        yield StatisticsSchedule().run()

        handler = self.request({}, role='admin')
        response = yield handler.get()

        # be sure that AnomalyHistory is populated
        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 1)
Example #7
0
    def test_delete(self):
        pollute_events_for_testing(3)
        yield AnomaliesSchedule().operation()
        yield StatisticsSchedule().operation()

        # be sure that Stats is populated
        count = yield self.get_stats_count()
        self.assertEqual(count, 1)

        # delete stats
        handler = self.request({}, role='admin')
        yield handler.delete()

        # verify that stats are now empty
        count = yield self.get_stats_count()
        self.assertEqual(count, 0)
Example #8
0
    def test_get(self):
        handler = self.request({}, role='admin')
        response = yield handler.get(0)

        self.assertEqual(len(response), 3)
        self.assertEqual(len(response['heatmap']), 7 * 24)

        self.pollute_events_and_perform_synthesis(10)

        yield AnomaliesSchedule().run()
        yield StatisticsSchedule().run()

        for i in range(2):
            handler = self.request({}, role='admin')
            response = yield handler.get(i)
            self.assertEqual(len(response), 3)
            self.assertEqual(len(response['heatmap']), 7 * 24)
Example #9
0
    def test_delete(self):
        self.pollute_events_and_perform_synthesis(10)

        yield AnomaliesSchedule().run()
        yield StatisticsSchedule().run()

        # be sure that Stats is populated
        count = yield self.get_stats_count()
        self.assertEqual(count, 1)

        # delete stats
        handler = self.request({}, role='admin')
        yield handler.delete()

        # verify that stats are now empty
        count = yield self.get_stats_count()
        self.assertEqual(count, 0)
Example #10
0
    def test_get(self):
        handler = self.request({}, role='admin')
        yield handler.get(0)

        self.assertTrue(isinstance(self.responses, list))
        self.assertEqual(len(self.responses[0]), 3)
        self.assertEqual(len(self.responses[0]['heatmap']), 7 * 24)

        pollute_events_for_testing(3)

        yield AnomaliesSchedule().operation()
        yield StatisticsSchedule().operation()

        for i in range(0, 2):
            handler = self.request({}, role='admin')
            yield handler.get(i)
            self.assertEqual(len(self.responses[1 + i]), 3)
            self.assertEqual(len(self.responses[1 + i]['heatmap']), 7 * 24)
Example #11
0
    def test_get(self):
        pollute_events_for_testing_and_perform_synthesis(3)
        yield StatisticsSchedule().run()

        handler = self.request({}, role='admin')

        yield handler.get('details')
        yield handler.get('summary')

        self.assertTrue(isinstance(self.responses[0], list))
        self.assertTrue(isinstance(self.responses[1], dict))

        for k in ['id', 'duration', 'event', 'creation_date']:
            for elem in self.responses[0]:
                self.assertTrue(k in elem)

        for k in anomaly.ANOMALY_MAP.keys():
            self.assertTrue(k in self.responses[1])
Example #12
0
    def test_get(self):
        pollute_events_for_testing_and_perform_synthesis(3)
        yield StatisticsSchedule().operation()

        handler = self.request({}, role='admin')

        yield handler.get('details')
        yield handler.get('summary')

        self.assertTrue(isinstance(self.responses[0], list))
        self.assertTrue(isinstance(self.responses[1], dict))

        for k in ['id', 'duration', 'event', 'creation_date']:
            for elem in self.responses[0]:
                self.assertTrue(k in elem)

        for k in ['wb_messages', 'wb_comments',
                  'receiver_messages', 'receiver_comments',
                  'started_submissions', 'completed_submissions',
                  'successful_logins', 'failed_logins',
                  'uploaded_files']:
            self.assertTrue(k in self.responses[1])