def setUp(self): self.dep1 = DepartmentFactory.create() self.dep2 = DepartmentFactory.create() self.user1 = UserFactory.create() self.user2 = UserFactory.create() self.user3 = UserFactory.create() self.user1.profile.departments.add(self.dep1, self.dep2) self.user2.profile.departments.add(self.dep2)
def setUp(self): email = '*****@*****.**' self.department_yes = DepartmentFactory.create(name='department_yes') self.department_no = DepartmentFactory.create(name='department_no') self.category_yes = CategoryFactory.create(departments=[self.department_yes]) self.category_no = CategoryFactory.create(departments=[self.department_no]) self.signal_yes = SignalFactory.create(category_assignment__category=self.category_yes, reporter__email=email) self.signal_no = SignalFactory.create(category_assignment__category=self.category_no, reporter__email=email) self.sia_read_write_user.profile.departments.add(self.department_yes)
def test_get_second_child_category(self): self.client.force_authenticate(user=self.sia_read_write_user) category = self.parent_category.children.first() department = DepartmentFactory.create(is_intern=False) category.departments.add(department, through_defaults={'is_responsible': False, 'can_view': True}) department = DepartmentFactory.create(is_intern=True) category.departments.add(department, through_defaults={'is_responsible': True, 'can_view': True}) url = f'/signals/v1/private/categories/{category.pk}' response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self._assert_category_data(category=category, data=response.json())
def setUp(self): user_model = get_user_model() self.superuser, _ = user_model.objects.get_or_create( email='*****@*****.**', is_superuser=True, defaults={ 'first_name': 'John', 'last_name': 'Doe', 'is_staff': True }) self.department = DepartmentFactory.create() parent_category = ParentCategoryFactory.create() self.category_1 = CategoryFactory.create(parent=parent_category, departments=[self.department]) ServiceLevelObjectiveFactory.create(category=self.category_1, n_days=2, use_calendar_days=True) self.category_2 = CategoryFactory.create(parent=parent_category, departments=[self.department]) ServiceLevelObjectiveFactory.create(category=self.category_2, n_days=3, use_calendar_days=False) self.category_3 = CategoryFactory.create(parent=parent_category, departments=[self.department]) ServiceLevelObjectiveFactory.create(category=self.category_3, n_days=4, use_calendar_days=False)
def test_SIG_3390_filter_directing_department(self): department = DepartmentFactory.create() parent_one = SignalFactory.create() SignalFactory.create_batch(1, parent=parent_one) directing_departments = SignalDepartments.objects.create( _signal=parent_one, created_by='*****@*****.**', relation_type='directing') directing_departments.departments.add(department) directing_departments.save() parent_one.directing_departments_assignment = directing_departments parent_one.save() parent_two = SignalFactory.create() SignalFactory.create_batch(2, parent=parent_two) parent_three = SignalFactory.create() directing_departments = SignalDepartments.objects.create( _signal=parent_three, created_by='*****@*****.**', relation_type='directing') parent_three.directing_departments_assignment = directing_departments parent_three.save() SignalFactory.create_batch(2, parent=parent_three) params = {'directing_department': ['null', department.code]} result_ids = self._request_filter_signals(params) self.assertEqual(3, len(result_ids))
def test_routing_expression_with_invalid_user_and_active(self): department = DepartmentFactory.create() expression = ExpressionFactory.create() user = UserFactory.create() routing_expression = RoutingExpression( _expression=expression, _department=department, _user=user, order=1, is_active=True, ) # User must be a member of the Department with self.assertRaises( ValidationError, msg= f'{user.username} is not part of department {department.name}' ): routing_expression.save() # Inactivate User is not allowed user.profile.departments.add(department) user.is_active = False user.save() with self.assertRaises(ValidationError, msg=f'{user.username} is not active'): routing_expression.save()
def setUp(self): self.department_read = Permission.objects.get( codename='sia_department_read') self.department_write = Permission.objects.get( codename='sia_department_write') self.sia_read_write_user.user_permissions.add(self.department_read) self.sia_read_write_user.user_permissions.add(self.department_write) self.department = DepartmentFactory.create() self.maincategory = ParentCategoryFactory.create() self.subcategory = CategoryFactory.create(parent=self.maincategory)
def test_department_filter_set(self): DepartmentFactory.create(can_direct=False) DepartmentFactory.create_batch(2, can_direct=True) n_can_direct = Department.objects.filter(can_direct=True).count() n_cannot_direct = Department.objects.filter(can_direct=False).count() self.client.force_authenticate(user=self.sia_read_write_user, ) # no filter response = self.client.get(self.list_endpoint) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['count'], Department.objects.count()) # filter can_direct=True response = self.client.get(self.list_endpoint, {'can_direct': True}) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['count'], n_can_direct) # filter can_direct=False response = self.client.get(self.list_endpoint, {'can_direct': False}) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['count'], n_cannot_direct)
def test_routing_expression_with_valid_user_and_not_active(self): department = DepartmentFactory.create() expression = ExpressionFactory.create() user = UserFactory.create() user.profile.departments.add(department) routing_expression = RoutingExpression( _expression=expression, _department=department, _user=user, order=1, is_active=False, ) routing_expression.save() self.assertEqual(routing_expression._department_id, department.id) self.assertEqual(routing_expression._user_id, user.id)
def setUp(self): self.department = DepartmentFactory.create() self.category = CategoryFactory.create(departments=[self.department]) self.signal = SignalFactory.create( category_assignment__category=self.category) self.attachment = ImageAttachmentFactory.create( _signal=self.signal, created_by='*****@*****.**') # Various Attachment delete permissions self.permission_delete_other = Permission.objects.get( codename='sia_delete_attachment_of_other_user') self.permission_delete_anonymous_user = Permission.objects.get( codename='sia_delete_attachment_of_anonymous_user') self.permission_delete_normal = Permission.objects.get( codename='sia_delete_attachment_of_normal_signal') self.permission_delete_parent = Permission.objects.get( codename='sia_delete_attachment_of_parent_signal') self.permission_delete_child = Permission.objects.get( codename='sia_delete_attachment_of_child_signal')
def test_routing_with_user_no_longer_active(self): department = DepartmentFactory.create() user = UserFactory.create() user.profile.departments.add(department) geometry = geos.MultiPolygon([ geos.Polygon.from_bbox([4.877157, 52.357204, 4.929686, 52.385239]) ], srid=4326) area = AreaFactory.create(geometry=geometry, name='centrum', code='centrum', _type__name='gebied', _type__code='stadsdeel') expression_routing_type = ExpressionTypeFactory.create(name="routing") expression = ExpressionFactory.create( _type=expression_routing_type, name="test outside", code=f'location in areas."{area._type.name}"."{area.code}"') routing_expression = RoutingExpressionFactory.create( _expression=expression, _department=department, _user=user) self.assertTrue(routing_expression.is_active) # In the mean time the user has been deactived user.is_active = False user.save() signal = SignalFactory.create( location__geometrie=geos.Point(4.88, 52.36)) self.assertIsNone(signal.user_assignment) # simulate applying routing rules dsl_service = SignalDslService() dsl_service.process_routing_rules(signal) signal.refresh_from_db() self.assertIsNone(signal.user_assignment) routing_expression.refresh_from_db() self.assertFalse(routing_expression.is_active)
def setUp(self): geometry = geos.MultiPolygon([geos.Polygon.from_bbox([4.877157, 52.357204, 4.929686, 52.385239])], srid=4326) self.area = AreaFactory.create( geometry=geometry, name='centrum', code='centrum', _type__name='gebied', _type__code='stadsdeel') self.exp_routing_type = ExpressionTypeFactory.create(name="routing") self.department = DepartmentFactory.create() self.location_expr = ExpressionFactory.create( _type=self.exp_routing_type, name="test outside", code=f'location in areas."{self.area._type.name}"."{self.area.code}"' ) RoutingExpressionFactory.create( _expression=self.location_expr, _department=self.department, is_active=True, order=2 )
def test_routing_expression_with_invalid_user_and_update_active(self): """ Validation of the User will only be triggered if a RoutingExpression is set to active. If a RoutingExpression is made with active is False and in the time between activation the User is no longer member of the associated Department this will trigger and the RoutingExpression must be fixed before saving. """ department = DepartmentFactory.create() expression = ExpressionFactory.create() user = UserFactory.create() routing_expression = RoutingExpression( _expression=expression, _department=department, _user=user, order=1, is_active=False, ) routing_expression.save() self.assertEqual(routing_expression._department_id, department.id) self.assertEqual(routing_expression._user_id, user.id) # User must be a member of the Department routing_expression.is_active = True with self.assertRaises(ValidationError): routing_expression.save() # Inactivate User and not a member of the Department is not allowed user.is_active = False user.save() with self.assertRaises(ValidationError): routing_expression.save() # Inactivate User is not allowed user.profile.departments.add(department) with self.assertRaises(ValidationError): routing_expression.save()
def setUp(self): self.department = DepartmentFactory.create() self.category = CategoryFactory.create(departments=[self.department]) self.signal = SignalFactory.create( category_assignment__category=self.category)