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)
def test_list_product_json_filter(self): base.ProductFactory(name="Test product") base.ProductFactory(name="Other product") resp = self.client.get(reverse("product:json"), {"search[value]": "Other"}) self.assertEqual(resp.status_code, 200) data = resp.json() self.assertIsNot(data["recordsTotal"], 0) self.assertFalse(data["recordsTotal"] < 2) self.assertIs(data["recordsFiltered"], 1)
def test_list_product_json_filter(self): base.ProductFactory(name="Test product") base.ProductFactory(name="Other product") resp = self.client.get(reverse('product:json'), {'search[value]': 'Other'}) self.assertEqual(resp.status_code, 200) data = resp.json() self.assertIsNot(data['recordsTotal'], 0) self.assertFalse(data['recordsTotal'] < 2) self.assertIs(data['recordsFiltered'], 1)
def test_edit_product(self): product = base.ProductFactory() data = self._DATA resp = self.client.post( reverse('product:edit', kwargs={'pk': product.pk}), data) self.assertEqual(resp.status_code, 302) self.check_single_object(models.Product, data)
def test_delete_product(self): product = base.ProductFactory() resp = self.client.post( reverse('product:delete', kwargs={'pk': product.pk})) self.assertEqual(resp.status_code, 302) self.check_single_object_deleted(models.Product) self.check_objects_are_soft_deleted(models.Product, ProductDoc)
def test_product_requirement_edit_unique(self): self.login_creator() self.product_two = base.ProductFactory() metrics = base.RequirementFactory.create_metrics(self.creator) requirement = base.RequirementFactory(created_by=self.creator, **metrics) product_requirement = base.ProductRequirementFactory( product=self.product, requirement=requirement, created_by=self.creator, relevance=self.relevance, ) product_to_test_against = base.ProductRequirementFactory( requirement=requirement, product=self.product_two, created_by=self.creator, relevance=self.relevance, ) data = self._DATA data['product'] = self.product_two.id data['requirement'] = product_requirement.requirement.id data['relevance'] = product_requirement.relevance.id resp = self.client.post( reverse('requirement:product:edit', kwargs={'requirement_pk': product_requirement.requirement.pk, 'pk': product_requirement.pk}), data) data = self._DATA self.assertEqual(resp.status_code, 200) self.assertEqual(resp.context['form'].errors, {'__all__': ['This relation already exists.']})
def test_list_product_json(self): base.ProductFactory() resp = self.client.get(reverse('product:json')) self.assertEqual(resp.status_code, 200) data = resp.json() self.assertIsNot(data['recordsTotal'], 0) self.assertEqual(data['recordsTotal'], data['recordsFiltered'])
def test_delete_product_related_objects(self): product = base.ProductFactory() metrics = base.RequirementFactory.create_metrics(self.creator) requirement = base.RequirementFactory(created_by=self.creator, **metrics) base.ProductRequirementFactory( product=product, requirement=requirement, created_by=self.creator ) self.client.post(reverse("product:delete", kwargs={"pk": product.pk})) self.check_objects_are_soft_deleted(models.ProductRequirement)
def setUp(self): super().setUp() metrics = base.RequirementFactory.create_metrics(self.creator) self.requirement = base.RequirementFactory(created_by=self.creator, **metrics) self.product = base.ProductFactory() level_of_definition = base.DefinitionLevelFactory() self.relevance = base.RelevanceFactory() criticality = base.CriticalityFactory() barriers = [base.BarrierFactory(), base.BarrierFactory()] self._DATA = { "note": "test note", "requirement": self.requirement.pk, "product": self.product.pk, "level_of_definition": level_of_definition.pk, "relevance": self.relevance.pk, "criticality": criticality.pk, "barriers": [barrier.pk for barrier in barriers], } user = base.UserFactory(username="******") self.client.force_login(user)
def setUp(self): super().setUp() metrics = base.RequirementFactory.create_metrics(self.creator) self.requirement = base.RequirementFactory(created_by=self.creator, **metrics) self.product = base.ProductFactory() level_of_definition = base.DefinitionLevelFactory() self.relevance = base.RelevanceFactory() criticality = base.CriticalityFactory() barriers = [base.BarrierFactory(), base.BarrierFactory()] self._DATA = { 'note': 'test note', 'requirement': self.requirement.pk, 'product': self.product.pk, 'level_of_definition': level_of_definition.pk, 'relevance': self.relevance.pk, 'criticality': criticality.pk, 'barriers': [barrier.pk for barrier in barriers] } user = base.UserFactory(username='******') self.client.force_login(user)
def test_product_requirement_edit_unique(self): self.login_creator() self.product_two = base.ProductFactory() metrics = base.RequirementFactory.create_metrics(self.creator) requirement = base.RequirementFactory(created_by=self.creator, **metrics) product_requirement = base.ProductRequirementFactory( product=self.product, requirement=requirement, created_by=self.creator, relevance=self.relevance, ) base.ProductRequirementFactory( requirement=requirement, product=self.product_two, created_by=self.creator, relevance=self.relevance, ) data = self._DATA data["product"] = self.product_two.id data["requirement"] = product_requirement.requirement.id data["relevance"] = product_requirement.relevance.id resp = self.client.post( reverse( "requirement:product:edit", kwargs={ "requirement_pk": product_requirement.requirement.pk, "pk": product_requirement.pk, }, ), data, ) data = self._DATA self.assertEqual(resp.status_code, 200) self.assertEqual(resp.context["form"].errors, {"__all__": ["This relation already exists."]})
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_get_edit_product(self): product = base.ProductFactory() resp = self.client.get( reverse('product:edit', kwargs={'pk': product.pk})) self.assertEqual(resp.status_code, 200)
def test_detail_product(self): product = base.ProductFactory() resp = self.client.get( reverse('product:detail', kwargs={'pk': product.pk})) self.assertEqual(resp.context['product'], product)
def test_list_products(self): base.ProductFactory() resp = self.client.get(reverse('product:list')) self.assertTemplateUsed(resp, 'product/list.html')
def test_get_delete_product(self): product = base.ProductFactory() resp = self.client.get(reverse("product:delete", kwargs={"pk": product.pk})) self.assertEqual(resp.status_code, 200)
def test_product_relation_delete_auth(self): product = base.ProductFactory() self.check_authenticated_user_redirect_all_methods( redirect_url=self.redirect_product_url_auth, url=reverse('product:delete', kwargs={'pk': product.pk}))
def test_product_edit_not_auth(self): product = base.ProductFactory() self.check_user_redirect_all_methods( redirect_url=self.redirect_product_url_non_auth, url=reverse('product:edit', kwargs={'pk': product.pk}))
def test_product_detail_not_auth(self): product = base.ProductFactory() resp = self.client.get(reverse("product:detail", kwargs={"pk": product.pk})) self.assertEqual(resp.status_code, 200)
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)
def test_detail_product(self): product = base.ProductFactory() resp = self.client.get(reverse("product:detail", kwargs={"pk": product.pk})) self.assertEqual(resp.context["product"], product)
def test_product_relation_edit_auth(self): product = base.ProductFactory() self.check_authenticated_user_redirect_all_methods( redirect_url=self.redirect_url, url=reverse("product:edit", kwargs={"pk": product.pk}), )
def test_product_delete_not_auth(self): product = base.ProductFactory() self.check_user_redirect_all_methods( redirect_url=self.redirect_url, url=reverse("product:delete", kwargs={"pk": product.pk}), )