コード例 #1
0
    def test_routing_syntax_error(self):
        # create expression which will cause error in compilation
        err_expr = ExpressionFactory.create(
            _type=self.exp_routing_type,
            name="error expression",
            code=f'abc location in areas."{self.area._type.name}"."{self.area.code}"'
        )

        routing_expr = RoutingExpressionFactory.create(
            _expression=err_expr,
            _department=self.department,
            is_active=True,
            order=1
        )
        # test signal inside center
        signal_inside = SignalFactory.create(
            location__geometrie=geos.Point(4.88, 52.36)
        )
        self.assertIsNone(signal_inside.routing_assignment)
        # simulate apply routing rules
        self.dsl_service.process_routing_rules(signal_inside)
        signal_inside.refresh_from_db()

        # routing rule will be de-activated due to syntax/compilation errors
        routing_expr.refresh_from_db()
        self.assertFalse(routing_expr.is_active)

        # 2nd rule should still work
        self.assertIsNotNone(signal_inside.routing_assignment)
        self.assertEqual(len(signal_inside.routing_assignment.departments.all()), 1)
        routing_dep = signal_inside.routing_assignment.departments.first()
        self.assertEqual(routing_dep.id, self.department.id)
コード例 #2
0
    def test_routing_runtime_error(self):
        # create expression which will cause error in compilation
        err_expr = ExpressionFactory.create(
            _type=self.exp_routing_type,
            name="runtime error expressin",
            code='unknown_abc > 1'
        )

        routing_expr = RoutingExpressionFactory.create(
            _expression=err_expr,
            _department=self.department,
            is_active=True,
            order=1
        )
        # test signal inside center
        signal_inside = SignalFactory.create(
            location__geometrie=geos.Point(4.88, 52.36)
        )
        self.assertIsNone(signal_inside.routing_assignment)
        # simulate apply routing rules
        self.dsl_service.process_routing_rules(signal_inside)
        signal_inside.refresh_from_db()

        # runtime errors should not effect is_active status
        routing_expr.refresh_from_db()
        self.assertTrue(routing_expr.is_active)

        # 2nd rule should still work
        self.assertIsNotNone(signal_inside.routing_assignment)
        self.assertEqual(len(signal_inside.routing_assignment.departments.all()), 1)
        routing_dep = signal_inside.routing_assignment.departments.first()
        self.assertEqual(routing_dep.id, self.department.id)
コード例 #3
0
    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()
コード例 #4
0
    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)
コード例 #5
0
    def setUp(self):
        self.expression_read = Permission.objects.get(
            codename='sia_expression_read')
        self.expression_write = Permission.objects.get(
            codename='sia_expression_write')
        self.sia_read_write_user.user_permissions.add(self.expression_read)
        self.sia_read_write_user.user_permissions.add(self.expression_write)

        self.exp_routing_type = ExpressionTypeFactory.create(name="routing")
        self.exp_int_id = ExpressionContextFactory.create(
            _type=self.exp_routing_type,
            identifier_type=ExpressionContext.CTX_NUMBER)
        self.exp_str_id = ExpressionContextFactory.create(
            _type=self.exp_routing_type,
            identifier_type=ExpressionContext.CTX_STRING)
        self.sample_int_expr = ExpressionFactory.create(
            _type=self.exp_routing_type,
            code="{} > 1".format(self.exp_int_id.identifier))
コード例 #6
0
    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)
コード例 #7
0
    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
        )
コード例 #8
0
    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()