def test_03_contents(self): # first try a valid csv sheet = reapplication.open_csv("valid.csv") fcs, skip = reapplication.validate_csv_contents(sheet) assert len(fcs) == 3 assert len(skip) == 0 # check that we can't validate something with an issn we don't recognise sheet = reapplication.open_csv("valid.csv") models.Suggestion.find_by_issn = dont_find_by_issn with self.assertRaises(reapplication.CsvValidationException): try: fcs = reapplication.validate_csv_contents(sheet) except reapplication.CsvValidationException as e: assert e.message == "Unable to locate a reapplication with the issn 1234-5678; spreadsheet is invalid" raise e sheet = reapplication.open_csv("valid.csv") models.Suggestion.find_by_issn = find_many_by_issn with self.assertRaises(reapplication.CsvValidationException): try: fcs = reapplication.validate_csv_contents(sheet) except reapplication.CsvValidationException as e: assert e.message == "Unable to locate a unique reapplication with the issn 1234-5678; please contact an administrator" raise e sheet = reapplication.open_csv("invalid.csv") models.Suggestion.find_by_issn = mock_find_by_issn with self.assertRaises(reapplication.ContentValidationException): try: fcs = reapplication.validate_csv_contents(sheet) except reapplication.ContentValidationException as e: assert e.message == "One or more records in the CSV failed to validate" assert len(e.errors.keys()) == 2 assert "1234-5678" in e.errors.keys() assert "2345-6789" in e.errors.keys() assert e.errors["1234-5678"].form.errors.keys() == ["url"] assert e.errors["2345-6789"].form.errors.keys() == ["country"] raise e
def test_16_error_report_cell_refs_columns(self): sheet = reapplication.open_csv("invalid.csv") with self.assertRaises(reapplication.ContentValidationException): try: fcs, skip = reapplication.validate_csv_contents(sheet) except reapplication.ContentValidationException as e: report = reapplication.generate_spreadsheet_error_object(sheet, e) assert report["6529-5440"].has_key(56), report["6529-5440"] assert report["6529-5440"][56] == ( "6529-5440", "53) Enter the URL where this information can be found **", 56, "AO", # the 41st column should be AO. AA is the 27th, AO is 14 after that (O is the 15th letter in the alphabet) "Invalid URL." ), report["6529-5440"][56] raise e
def test_15_error_report_cell_refs_rows(self): sheet = reapplication.open_csv("invalid.csv") with self.assertRaises(reapplication.ContentValidationException): try: fcs, skip = reapplication.validate_csv_contents(sheet) except reapplication.ContentValidationException as e: report = reapplication.generate_spreadsheet_error_object(sheet, e) assert report["4567-8901"].has_key(56), report["4567-8901"] assert report["4567-8901"][56] == ( "4567-8901", "53) Enter the URL where this information can be found **", 56, "E", "Invalid URL." ), report["4567-8901"][56] raise e
def test_04_conditional_fields(self): sheet = reapplication.open_csv("valid.csv") models.Suggestion.find_by_issn = find_conditional_by_issn fcs, skip = reapplication.validate_csv_contents(sheet) assert len(fcs) == 3 assert len(skip) == 0