Exemple #1
0
    def setUp(self):
        super().setUp()
        group = base.ProductGroupFactory()
        component = base.ComponentFactory()
        status = base.ProductStatusFactory()
        area = base.AreaFactory()
        self.user = provider_user = base.UserFactory(is_superuser=True,
                                                     username='******')
        self.client.force_login(provider_user)
        self._DATA = {
            'acronym': 'TST',
            'name': 'TEST product',
            'note': 'TEST note',
            'description': 'TEST description',
            'group': group.pk,
            'component': component.pk,
            'status': status.pk,
            'area': area.pk
        }

        with open(os.devnull, 'w') as f:
            call_command('search_index', '--rebuild', '-f', stdout=f)
    def setUp(self):
        super().setUp()
        group = base.ProductGroupFactory()
        component = base.ComponentFactory()
        status = base.StatusFactory()
        area = base.AreaFactory()
        self.user = provider_user = base.UserFactory(
            is_superuser=True, username="******"
        )
        self.client.force_login(provider_user)
        self._DATA = {
            "acronym": "TST",
            "name": "TEST product",
            "note": "TEST note",
            "description": "TEST description",
            "group": group.pk,
            "component": component.pk,
            "status": status.pk,
            "area": area.pk,
        }

        with open(os.devnull, "w") as f:
            call_command("search_index", "--rebuild", "-f", stdout=f)
Exemple #3
0
    def test_entity_and_group_sync_other_filters(self):
        """
        Whenever any of the filters is selected, this should trigger
        a synchronization of all other filters. Because of combinatorial
        explosion it is impractical to test all possible combinations, so this
        only tests one specific case that was selected at random, namely
        `entity`, and `group` triggering the synchronization of `service`,
        `component`, `status` and `area`.
        """
        service_1 = base.CopernicusServiceFactory(name="Service 1")
        service_2 = base.CopernicusServiceFactory(name="Service 2")
        entity_1 = base.EntrustedEntityFactory(acronym="Entity 1")
        entity_2 = base.EntrustedEntityFactory(acronym="Entity 2")

        component_1 = base.ComponentFactory(name='Component 1',
                                            service=service_1,
                                            entrusted_entity=entity_1)
        component_2 = base.ComponentFactory(name='Component 2',
                                            service=service_1,
                                            entrusted_entity=entity_2)
        component_3 = base.ComponentFactory(name='Component 3',
                                            service=service_2,
                                            entrusted_entity=entity_1)

        group_1 = base.ProductGroupFactory(name='Group 1')
        group_2 = base.ProductGroupFactory(name='Group 2')
        status_1 = base.ProductStatusFactory(name='Status 1')
        status_2 = base.ProductStatusFactory(name='Status 2')
        area_1 = base.AreaFactory(name='Area 1')
        area_2 = base.AreaFactory(name='Area 2')

        base.ProductFactory(component=component_1,
                            group=group_1,
                            status=status_1,
                            area=area_1)
        base.ProductFactory(component=component_2,
                            group=group_1,
                            status=status_1,
                            area=area_1)
        base.ProductFactory(component=component_1,
                            group=group_2,
                            status=status_2,
                            area=area_1)
        base.ProductFactory(component=component_3,
                            group=group_1,
                            status=status_1,
                            area=area_2)

        resp = self.client.get(reverse('product:json'), {
            'entity': entity_1.acronym,
            'group': group_1.name
        })
        self.assertEqual(resp.status_code, 200)

        data = resp.json()

        filters = {
            'component': {
                'options': ['Component 1', 'Component 3'],
                'selected': None
            },
            'area': {
                'options': ['Area 1', 'Area 2'],
                'selected': None
            },
            'entity': {
                'options': ['Entity 1'],
                'selected': 'Entity 1'
            },
            'group': {
                'options': ['Group 1'],
                'selected': 'Group 1'
            },
            'service': {
                'options': ['Service 1', 'Service 2'],
                'selected': None
            },
            'status': {
                'options': ['Status 1'],
                'selected': None
            }
        }

        self.assertEqual(data['filters'], filters)
    def test_entity_and_group_sync_other_filters(self):
        """
        Whenever any of the filters is selected, this should trigger
        a synchronization of all other filters. Because of combinatorial
        explosion it is impractical to test all possible combinations, so this
        only tests one specific case that was selected at random, namely
        `entity`, and `group` triggering the synchronization of `service`,
        `component`, `status` and `area`.
        """
        service_1 = base.CopernicusServiceFactory(name="Service 1")
        service_2 = base.CopernicusServiceFactory(name="Service 2")
        entity_1 = base.EntrustedEntityFactory(acronym="Entity 1")
        entity_2 = base.EntrustedEntityFactory(acronym="Entity 2")

        component_1 = base.ComponentFactory(
            name="Component 1", service=service_1, entrusted_entity=entity_1
        )
        component_2 = base.ComponentFactory(
            name="Component 2", service=service_1, entrusted_entity=entity_2
        )
        component_3 = base.ComponentFactory(
            name="Component 3", service=service_2, entrusted_entity=entity_1
        )

        group_1 = base.ProductGroupFactory(name="Group 1")
        group_2 = base.ProductGroupFactory(name="Group 2")
        status_1 = base.StatusFactory(name="Status 1")
        status_2 = base.StatusFactory(name="Status 2")
        area_1 = base.AreaFactory(name="Area 1")
        area_2 = base.AreaFactory(name="Area 2")

        base.ProductFactory(
            component=component_1, group=group_1, status=status_1, area=area_1
        )
        base.ProductFactory(
            component=component_2, group=group_1, status=status_1, area=area_1
        )
        base.ProductFactory(
            component=component_1, group=group_2, status=status_2, area=area_1
        )
        base.ProductFactory(
            component=component_3, group=group_1, status=status_1, area=area_2
        )

        resp = self.client.get(
            reverse("product:json"), {"entity": entity_1.acronym, "group": group_1.name}
        )
        self.assertEqual(resp.status_code, 200)

        data = resp.json()

        filters = {
            "component": {"options": ["Component 1", "Component 3"], "selected": None},
            "area": {"options": ["Area 1", "Area 2"], "selected": None},
            "entity": {"options": ["Entity 1"], "selected": "Entity 1"},
            "group": {"options": ["Group 1"], "selected": "Group 1"},
            "service": {"options": ["Service 1", "Service 2"], "selected": None},
            "status": {"options": ["Status 1"], "selected": None},
        }

        self.assertEqual(data["filters"], filters)
Exemple #5
0
    def test_list_provider_json_filter_component(self):
        metrics = base.RequirementFactory.create_metrics(self.creator)
        romania = base.CountryFactory(code="RO")

        # Create 4 components
        first_component = base.ComponentFactory(name="First component")
        second_component = base.ComponentFactory(name="Second component")
        common_component = base.ComponentFactory(name="Common component")
        other_component = base.ComponentFactory(name="Other component")

        # Create data provider
        dpr1 = base.DataProviderRelationFactory(
            created_by=self.creator,
            data__created_by=self.creator,
            provider__name="First provider",
            provider__created_by=self.creator,
            provider__countries=[romania],
        )
        requirement1 = base.RequirementFactory(created_by=self.creator,
                                               **metrics)
        data_req1 = base.DataRequirementFactory(
            created_by=self.creator,
            data=dpr1.data,
            requirement=requirement1,
        )
        # Associate it with first and common components
        prod_req1 = base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement1,
            product__component=first_component,
        )
        base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement1,
            product__component=common_component,
        )

        # Create a second data provider
        dpr2 = base.DataProviderRelationFactory(
            created_by=self.creator,
            data__created_by=self.creator,
            provider__name="Second provider",
            provider__created_by=self.creator,
            provider__countries=[romania],
        )
        requirement2 = base.RequirementFactory(created_by=self.creator,
                                               **metrics)
        base.DataRequirementFactory(
            created_by=self.creator,
            data=dpr2.data,
            requirement=requirement2,
        )
        # Associate it with second and common components
        base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement2,
            product__component=second_component,
        )
        base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement2,
            product__component=common_component,
        )

        # Create a third data provider
        dpr3 = base.DataProviderRelationFactory(
            created_by=self.creator,
            data__created_by=self.creator,
            provider__name="Third provider",
            provider__created_by=self.creator,
            provider__countries=[romania],
        )
        requirement3 = base.RequirementFactory(created_by=self.creator,
                                               **metrics)
        base.DataRequirementFactory(
            created_by=self.creator,
            data=dpr3.data,
            requirement=requirement3,
        )
        # Associate it with other component
        base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement3,
            product__component=other_component,
        )

        # Filter by component (First component)
        resp = self.client.get(reverse("provider:json"),
                               {"component": "First component"})
        self.assertEqual(resp.status_code, 200)
        data = resp.json()
        self.assertIs(data["recordsTotal"], 3)
        self.assertIs(data["recordsFiltered"], 1)

        # Filter by component (Second component)
        resp = self.client.get(reverse("provider:json"),
                               {"component": "Second component"})
        self.assertEqual(resp.status_code, 200)
        data = resp.json()
        self.assertIs(data["recordsTotal"], 3)
        self.assertIs(data["recordsFiltered"], 1)

        # Filter by component (Common component)
        resp = self.client.get(reverse("provider:json"),
                               {"component": "Common component"})
        self.assertEqual(resp.status_code, 200)
        data = resp.json()
        self.assertIs(data["recordsTotal"], 3)
        self.assertIs(data["recordsFiltered"], 2)

        objs_to_soft_delete = [
            dpr1.provider,
            dpr1,
            dpr1.data,
            data_req1,
            requirement1,
            prod_req1,
            prod_req1.product,
        ]
        # Soft delete intermediate objects
        for obj in objs_to_soft_delete:
            with soft_deleted(obj):
                resp = self.client.get(reverse("provider:json"),
                                       {"component": "First component"})
                self.assertEqual(resp.status_code, 200)
                data = resp.json()
                # No records are filtered
                self.assertIs(data["recordsFiltered"], 0)
Exemple #6
0
    def test_list_data_json_filter_component(self):
        metrics = base.RequirementFactory.create_metrics(self.creator)

        # Create 4 components
        first_component = base.ComponentFactory(name="First component")
        second_component = base.ComponentFactory(name="Second component")
        common_component = base.ComponentFactory(name="Common component")
        other_component = base.ComponentFactory(name="Other component")

        # Create first Data and DataRequirement objects
        data1 = base.DataFactory(created_by=self.creator)
        requirement1 = base.RequirementFactory(created_by=self.creator,
                                               **metrics)
        data_req1 = base.DataRequirementFactory(
            created_by=self.creator,
            data=data1,
            requirement=requirement1,
        )
        # Associate it with first and common components
        prod_req1 = base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement1,
            product__component=first_component,
        )
        base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement1,
            product__component=common_component,
        )

        # Create second Data and DataRequirement objects
        data2 = base.DataFactory(created_by=self.creator)
        requirement = base.RequirementFactory(created_by=self.creator,
                                              **metrics)
        base.DataRequirementFactory(
            created_by=self.creator,
            data=data2,
            requirement=requirement,
        )
        # Associate it with second and common components
        base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement,
            product__component=second_component,
        )
        base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement,
            product__component=common_component,
        )

        # Create third Data and DataRequirement objects
        data3 = base.DataFactory(created_by=self.creator)
        requirement = base.RequirementFactory(created_by=self.creator,
                                              **metrics)
        base.DataRequirementFactory(
            created_by=self.creator,
            data=data3,
            requirement=requirement,
        )
        # Associate it with other component
        base.ProductRequirementFactory(
            created_by=self.creator,
            requirement=requirement,
            product__component=other_component,
        )

        # Filter by component (First component)
        resp = self.client.get(reverse("data:json"),
                               {"component": "First component"})
        self.assertEqual(resp.status_code, 200)
        data = resp.json()
        self.assertIs(data["recordsTotal"], 3)
        self.assertIs(data["recordsFiltered"], 1)

        # Filter by component (Second component)
        resp = self.client.get(reverse("data:json"),
                               {"component": "Second component"})
        self.assertEqual(resp.status_code, 200)
        data = resp.json()
        self.assertIs(data["recordsTotal"], 3)
        self.assertIs(data["recordsFiltered"], 1)

        # Filter by component (Common component)
        resp = self.client.get(reverse("data:json"),
                               {"component": "Common component"})
        self.assertEqual(resp.status_code, 200)
        data = resp.json()
        self.assertIs(data["recordsTotal"], 3)
        self.assertIs(data["recordsFiltered"], 2)

        objs_to_soft_delete = [
            data1,
            data_req1,
            requirement1,
            prod_req1,
            prod_req1.product,
        ]
        # Soft delete intermediate objects
        for obj in objs_to_soft_delete:
            with soft_deleted(obj):
                resp = self.client.get(reverse("provider:json"),
                                       {"component": "First component"})
                self.assertEqual(resp.status_code, 200)
                data = resp.json()
                # No records are filtered
                self.assertIs(data["recordsFiltered"], 0)