Пример #1
0
    def test_alert_can_be_filtered_by_content_type(self):
        project = structure_factories.ProjectFactory(customer=self.customer)
        alert1 = factories.AlertFactory(scope=project)
        alert2 = factories.AlertFactory(scope=self.customer)

        self.client.force_authenticate(self.owner)
        response = self.client.get(factories.AlertFactory.get_list_url(), data={'content_type': ['structure.project']})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn(alert1.uuid.hex, [a['uuid'] for a in response.data])
        self.assertNotIn(alert2.uuid.hex, [a['uuid'] for a in response.data])
Пример #2
0
    def test_service_project_link_alert_is_not_returned_when_its_scope_is_related_to_another_project(
            self):
        not_owned_alert = logging_factories.AlertFactory(
            scope=factories.TestServiceProjectLinkFactory())
        spl = factories.TestServiceProjectLinkFactory(project=self.project)
        owned_alert = logging_factories.AlertFactory(scope=spl)

        result = self._make_aggregate_request('project', self.project.uuid.hex)

        self.assertTrue(result.filter(uuid=owned_alert.uuid).exists())
        self.assertFalse(result.filter(uuid=not_owned_alert.uuid).exists())
Пример #3
0
    def test_alert_list_can_be_aggregated_for_concreate_customer(self):
        project = structure_factories.ProjectFactory(customer=self.customer)
        alert1 = factories.AlertFactory(scope=project)
        alert2 = factories.AlertFactory()

        self.client.force_authenticate(self.owner)
        response = self.client.get(factories.AlertFactory.get_list_url(), data={
            'aggregate': 'customer', 'uuid': self.customer.uuid.hex})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn(alert1.uuid.hex, [a['uuid'] for a in response.data])
        self.assertNotIn(alert2.uuid.hex, [a['uuid'] for a in response.data])
Пример #4
0
    def test_alert_list_can_be_filtered_by_scope_type(self):
        # XXX: this tests will removed after content type filter implementation at portal
        project = structure_factories.ProjectFactory(customer=self.customer)
        alert1 = factories.AlertFactory(scope=project)
        alert2 = factories.AlertFactory(scope=self.customer)

        self.client.force_authenticate(self.owner)
        response = self.client.get(factories.AlertFactory.get_list_url(), data={'scope_type': 'customer'})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn(alert2.uuid.hex, [a['uuid'] for a in response.data])
        self.assertNotIn(alert1.uuid.hex, [a['uuid'] for a in response.data])
Пример #5
0
    def test_alert_list_can_be_filtered_by_severity_list(self):
        project = structure_factories.ProjectFactory(customer=self.customer)
        alert1 = factories.AlertFactory(scope=project, severity=models.Alert.SeverityChoices.WARNING)
        alert2 = factories.AlertFactory(scope=project, severity=models.Alert.SeverityChoices.ERROR)
        alert3 = factories.AlertFactory(scope=project, severity=models.Alert.SeverityChoices.INFO)

        self.client.force_authenticate(self.owner)
        response = self.client.get(factories.AlertFactory.get_list_url(), data={'severity': ['Warning', 'Error']})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn(alert1.uuid.hex, [a['uuid'] for a in response.data])
        self.assertIn(alert2.uuid.hex, [a['uuid'] for a in response.data])
        self.assertNotIn(alert3.uuid.hex, [a['uuid'] for a in response.data])
Пример #6
0
    def test_alert_list_can_be_filtered_by_created_date(self):
        project = structure_factories.ProjectFactory(customer=self.customer)
        alert1 = factories.AlertFactory(scope=project, created=timezone.now()-timedelta(days=1))
        alert2 = factories.AlertFactory(scope=project, created=timezone.now()-timedelta(days=3))

        self.client.force_authenticate(self.owner)
        response = self.client.get(factories.AlertFactory.get_list_url(), data={
            'created_from': core_utils.datetime_to_timestamp(timezone.now()-timedelta(days=2)),
            'created_to': core_utils.datetime_to_timestamp(timezone.now())})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn(alert1.uuid.hex, [a['uuid'] for a in response.data])
        self.assertNotIn(alert2.uuid.hex, [a['uuid'] for a in response.data])
Пример #7
0
 def setUp(self):
     self.project = structure_factories.ProjectFactory()
     self.staff = get_user_model().objects.create_superuser(
         username='******', password='******', email='*****@*****.**')
     self.alert = factories.AlertFactory(scope=self.project)
     self.admin = structure_factories.UserFactory()
     self.project.add_user(self.admin, structure_models.ProjectRole.ADMINISTRATOR)
Пример #8
0
    def test_customer_owner_cannot_see_alert_about_other_customer(self):
        alert = factories.AlertFactory()

        self.client.force_authenticate(self.owner)
        response = self.client.get(factories.AlertFactory.get_list_url())

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotIn(alert.uuid.hex, [a['uuid'] for a in response.data])
Пример #9
0
    def test_customer_owner_can_see_alert_about_his_project(self):
        project = structure_factories.ProjectFactory(customer=self.customer)
        alert = factories.AlertFactory(scope=project)

        self.client.force_authenticate(self.owner)
        response = self.client.get(factories.AlertFactory.get_list_url())

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn(alert.uuid.hex, [a['uuid'] for a in response.data])
Пример #10
0
    def test_only_alerts_where_scopes_customer_is_the_aggregated_one_are_returned(
            self):
        customer_related_alerts = []
        logging_factories.AlertFactory(scope=factories.ProjectFactory())
        spl = factories.TestServiceProjectLinkFactory(
            service__customer=self.customer)
        customer_related_alerts.append(
            logging_factories.AlertFactory(scope=spl))
        service = factories.TestServiceFactory(customer=self.customer)
        customer_related_alerts.append(
            logging_factories.AlertFactory(scope=service))
        expected_alerts_ids = [alert.uuid for alert in customer_related_alerts]

        result = self._make_aggregate_request('customer',
                                              self.customer.uuid.hex)
        actual_alerts_ids = [alert.uuid for alert in result]

        self.assertItemsEqual(expected_alerts_ids, actual_alerts_ids)
Пример #11
0
    def test_project_alert_is_not_returned_when_its_scope_belongs_to_another_customer(
            self):
        alert = logging_factories.AlertFactory(
            scope=factories.ProjectFactory())

        result = self._make_aggregate_request('customer',
                                              self.customer.uuid.hex)

        self.assertFalse(result.filter(uuid=alert.uuid).exists())
Пример #12
0
    def test_service_alert_is_returned_when_aggregate_customer_is_the_same_as_its_scope_customer(
            self):
        scope = factories.TestServiceFactory(customer=self.customer)
        alert = logging_factories.AlertFactory(scope=scope)

        result = self._make_aggregate_request('customer',
                                              self.customer.uuid.hex)

        self.assertEqual(len(result), 1)
        self.assertTrue(result.filter(uuid=alert.uuid).exists())