Пример #1
0
 def test_product_group_requirement_add_unique_relation_to_products_without(
         self):
     data = copy.deepcopy(self._DATA)
     data.pop("product")
     product_group = base.ProductGroupFactory()
     product1 = base.ProductFactory(group=product_group)
     product2 = base.ProductFactory(group=product_group)
     base.ProductRequirementFactory(
         product=product1,
         requirement=self.requirement,
         relevance=self.relevance,
         created_by=self.creator,
     )
     data["product_group"] = product_group.pk
     resp = self.client.post(
         reverse(
             "requirement:product:add_group",
             kwargs={"requirement_pk": self._DATA["requirement"]},
         ),
         data,
     )
     self.assertEqual(resp.status_code, 302)
     products = [
         product_requirement.product for product_requirement in models.
         ProductRequirement.objects.filter(product__group=product_group)
     ]
     self.assertEqual(len(products), 2)
     self.assertIn(product1, products)
     self.assertIn(product2, products)
Пример #2
0
 def test_product_group_requirement_add_unique_relation_raise_error(self):
     data = copy.deepcopy(self._DATA)
     data.pop("product")
     product_group = base.ProductGroupFactory()
     data["product_group"] = product_group.pk
     self.client.post(
         reverse(
             "requirement:product:add_group",
             kwargs={"requirement_pk": self._DATA["requirement"]},
         ),
         data,
     )
     resp = self.client.post(
         reverse(
             "requirement:product:add_group",
             kwargs={"requirement_pk": self._DATA["requirement"]},
         ),
         data,
     )
     self.assertEqual(resp.status_code, 200)
     unique_relation_error = {
         "__all__":
         ["A relation already exists for all products of this group."]
     }
     self.assertEqual(resp.context["form"].errors, unique_relation_error)
Пример #3
0
 def test_product_group_requirement_add(self):
     data = copy.deepcopy(self._DATA)
     data.pop('product')
     product_group = base.ProductGroupFactory()
     data['product_group'] = product_group.pk
     resp = self.client.post(
         reverse('requirement:product:add_group',
                 kwargs={'requirement_pk': self._DATA['requirement']}),
         data)
     self.assertEqual(resp.status_code, 302)
     self.check_single_object(models.ProductRequirement, self._DATA)
Пример #4
0
 def test_product_group_requirement_add(self):
     data = copy.deepcopy(self._DATA)
     data.pop("product")
     product_group = base.ProductGroupFactory()
     data["product_group"] = product_group.pk
     resp = self.client.post(
         reverse(
             "requirement:product:add_group",
             kwargs={"requirement_pk": self._DATA["requirement"]},
         ),
         data,
     )
     self.assertEqual(resp.status_code, 302)
     self.check_single_object(models.ProductRequirement, self._DATA)
Пример #5
0
 def test_product_group_requirement_add_unique_relation_raise_error(self):
     data = copy.deepcopy(self._DATA)
     data.pop('product')
     product_group = base.ProductGroupFactory()
     data['product_group'] = product_group.pk
     self.client.post(
         reverse('requirement:product:add_group',
                 kwargs={'requirement_pk': self._DATA['requirement']}),
         data)
     resp = self.client.post(
         reverse('requirement:product:add_group',
                 kwargs={'requirement_pk': self._DATA['requirement']}),
         data)
     self.assertEqual(resp.status_code, 200)
     unique_relation_error = {
         '__all__':
         ['A relation already exists for all products of this group.']
     }
     self.assertEqual(resp.context['form'].errors, unique_relation_error)
Пример #6
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)
Пример #7
0
    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)
Пример #8
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)
Пример #9
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.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)