Ejemplo n.º 1
0
    def test_when_limit_is_within_max_limit(self):
        limit = "10"
        max_limit = 100
        validator = Validator("", "", "Coventry University", "", "", limit, max_limit, "0", "en")

        expected_result = 10
        output_result, output_error_object = validator.validate_limit()
        self.assertEqual(expected_result, output_result)
        self.assertEqual([], output_error_object)
Ejemplo n.º 2
0
    def test_when_limit_is_not_a_number(self):
        limit = "twenty"
        max_limit = 100
        validator = Validator("", "", "Coventry University", "", "", limit, max_limit, "0", "en")

        expected_result = 0
        expected_error_object = [
            {
                "error": "limit value needs to be a number",
                "error_values": [{"limit": limit}],
            }
        ]
        output_result, output_error_object = validator.validate_limit()

        self.assertEqual(expected_result, output_result)
        self.assertEqual(expected_error_object, output_error_object)
Ejemplo n.º 3
0
    def test_when_limit_is_a_negative_number(self):
        limit = "-20"
        max_limit = 100
        validator = Validator("", "", "Coventry University", "", "", limit, max_limit, "0", "en")

        expected_result = -20
        expected_error_object = [
            {
                "error": "limit needs to be a positive number, limit cannot be lower than 0",
                "error_values": [{"limit": "-20"}],
            }
        ]
        output_result, output_error_object = validator.validate_limit()

        self.assertEqual(expected_result, output_result)
        self.assertEqual(expected_error_object, output_error_object)
Ejemplo n.º 4
0
    def test_when_limit_is_outside_max_limit(self):
        limit = "200"
        max_limit = 100
        validator = Validator("", "", "Coventry University", "", "", limit, max_limit, "0", "en")

        expected_result = 200
        expected_error_object = [
            {
                "error": "limit cannot exceed maximum value of 100",
                "error_values": [{"limit": "200"}],
            }
        ]
        output_result, output_error_object = validator.validate_limit()

        self.assertEqual(expected_result, output_result)
        self.assertEqual(expected_error_object, output_error_object)