def test_when_all_query_params_are_bad(self): limit = 200 offset = "-30" filters = "illusion,Part_Time,full_time,-full_time" institution = "" length_of_course = "-2,8,twenty" countries = "bolivia,-england,england" subjects = 32 language = 'bad' validator = Validator( countries, filters, institution, length_of_course, subjects, limit, 100, offset, language ) expected_result = {} output_result, output_error_object = validator.validate() expected_error_object = [ { "error": "limit cannot exceed maximum value of 100", "error_values": [{"limit": 200}], }, { "error": "offset needs to be a positive number, offset cannot be lower than 0", "error_values": [{"offset": "-30"}], }, { "error": "use of the same filter option more than once", "error_values": [{"filters": "full_time"}], }, { "error": "invalid filters", "error_values": [{"filters": "illusion,Part_Time"}], }, { "error": "use of the same countries more than once", "error_values": [{"countries": "england"}], }, {"error": "invalid countries", "error_values": [{"countries": "bolivia"}]}, { "error": "length_of_course values needs to be a number", "error_values": [{"length_of_course": "twenty"}], }, { "error": "length_of_course values needs to be numbers between the range of 1 and 7", "error_values": [{"length_of_course": "-2,8"}], }, { 'error': 'missing value for mandatory field: institution', 'error_values': [{'institution': ''}], }, { 'error': 'value of language is not supported', 'error_values': [{'language': 'bad'}], } ] print(f"output: {output_error_object}") self.assertEqual(expected_result, output_result) self.assertEqual(expected_error_object, output_error_object)
def test_when_all_query_params_are_set(self): limit = 5 offset = "30" filters = "distance_learning,honours_award,-foundation_year,sandwich_year,-year_abroad,full_time" institution = "Coventry University" length_of_course = "3,4" countries = "england,wales" subjects = "CAH09-01-01,CAH09-01-02" language = "en" validator = Validator( countries, filters, institution, length_of_course, subjects, limit, 100, offset, language ) expected_result = { "countries": ["XF", "XI"], "distance_learning": True, "foundation_year": False, "full_time": True, "honours_award": True, "language": "en", "length_of_course": ["3", "4"], "limit": 5, "offset": 30, "sandwich_year": True, "subjects": ["CAH09-01-01", "CAH09-01-02"], "year_abroad": False, } output_result, output_error_object = validator.validate() self.assertEqual(expected_result, output_result) self.assertEqual([], output_error_object)