def test_when_empty_filters_returns_no_error(self): filters = "" validator = Validator("", filters, "", "Coventry University", "", "0", 100, "0", "en") output_filters, output_error_object = validator.validate_filters() self.assertEqual({}, output_filters) self.assertEqual([], output_error_object)
def test_when_a_filter_is_selected_prefixed_with_hyphen_returns_no_error(self): filters = "-sandwich_year" validator = Validator("", filters, "Coventry University", "", "", "0", 100, "0", "en") output_filters, output_error_object = validator.validate_filters() expected_filters = {"sandwich_year": False} self.assertEqual(expected_filters, output_filters) self.assertEqual([], output_error_object)
def test_when_a_filter_is_selected_returns_no_error(self): filters = "distance_learning" validator = Validator("", filters, "Coventry University", "", "", "0", 100, "0", "en") output_filters, output_error_object = validator.validate_filters() expected_filters = {"distance_learning": True} self.assertEqual(expected_filters, output_filters) self.assertEqual([], output_error_object)
def test_when_there_both_part_time_and_full_time_filters_set_returns_error(self): filters = "full_time,-part_time" validator = Validator("", filters, "Coventry University", "", "", "0", 100, "0", "en") output_filters, output_error_object = validator.validate_filters() expected_error_object = [ { "error": "cannot have both part_time and full_time filters set", "error_values": [{"filters": "part_time,full_time"}], } ] self.assertEqual({}, output_filters) self.assertEqual(expected_error_object, output_error_object)
def test_when_there_are_invalid_filters_returns_error(self): filters = "salary,distance_learning,PaRt-Time" validator = Validator("", filters, "Coventry University", "", "", "0", 100, "0", "en") output_filters, output_error_object = validator.validate_filters() expected_error_object = [ { "error": "invalid filters", "error_values": [{"filters": "salary,PaRt-Time"}], } ] self.assertEqual({}, output_filters) self.assertEqual(expected_error_object, output_error_object)
def test_when_there_are_duplicate_filters_returns_error(self): filters = "-distance_learning,distance_learning" validator = Validator("", filters, "", "Coventry University", "", "0", 100, "0", "en") output_filters, output_error_object = validator.validate_filters() expected_error_object = [ { "error": "use of the same filter option more than once", "error_values": [{"filters": "distance_learning"}], } ] self.assertEqual({}, output_filters) self.assertEqual(expected_error_object, output_error_object)
def test_when_all_filters_are_selected_returns_no_error(self): filters = "-distance_learning,honours_award,foundation_year,sandwich_year,year_abroad,-full_time" validator = Validator("", filters, "Coventry University", "", "", "0", 100, "0", "en") output_filters, output_error_object = validator.validate_filters() expected_filters = { "distance_learning": False, "foundation_year": True, "full_time": False, "honours_award": True, "sandwich_year": True, "year_abroad": True, } self.assertEqual(expected_filters, output_filters) self.assertEqual([], output_error_object)