def test_value4_blank_if_toc4_empty(self): sheet = OPWorkbook(self.pages_invalid_workbook, self.pages_config).pages sheet.validate_blank('value4') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches(sheet.errors[0], r"'VALUE4' must be empty.* 'TAG4'.*'Car'")
def test_validate_blank_if_other_in_list_case_insensitive_invalid(self): sheet = OPWorkbook(self.empty_if_workbook, self.empty_if_config).description sheet.validate_blank('empty_if_field_4_is_cat_invalid') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches(sheet.errors[0], r'.* must be empty if.*is.*cat.*; found:')
def test_validate_blank_if_other_empty_invalid(self): sheet = OPWorkbook(self.empty_if_workbook, self.empty_if_config).description sheet.validate_blank('empty_if_field_1_empty_invalid') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches(sheet.errors[0], r'.* must be empty if.*is empty; found.*')
def test_validate_value_list_invalid(self): sheet = OPWorkbook(self.value_lists_workbook, self.value_lists_test_config).description sheet.validate_value_list('rights_cc_x_not_in_list') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches(sheet.errors[0], r'Rights CC-X.*not valid.*expected.*')
def test_validate_required_if_other_empty_invalid(self): sheet = OPWorkbook(self.required_values_workbook, self.requirements_config).description sheet.validate_requirement('required_if_field_1_empty_invalid') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches( sheet.errors[0], r'Required if field 1.* cannot be empty.*Field 1')
def test_empty_if_other_nonempty(self): sheet = OPWorkbook(self.pages_invalid_workbook, self.pages_config).pages sheet.validate_blank('serial_num') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches(sheet.errors[0], r"'SERIAL_NUM' must be empty.* 'FILE_NAME'")
def test_validate(self): for path in self.dummy_paths: touch(path) sheet = OPWorkbook(self.pages_workbook, self.pages_config).pages sheet.validate() if len(sheet.errors) > 0: pp(sheet.errors) self.assertEqual(len(sheet.errors), 0)
def test_required_based_on_value_list_tag3_value3(self): sheet = OPWorkbook(self.pages_invalid_workbook, self.pages_config).pages sheet.validate_requirement('value3') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches(sheet.errors[0], r"'VALUE3' cannot be empty.* 'TAG3'.*'TOC3'")
def test_validate_required_if_other_in_list_repeating(self): sheet = OPWorkbook(self.required_values_workbook, self.requirements_config).description sheet.validate_requirement('required_if_9_is_CAT') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches(sheet.errors[0], r'Required.* cannot be empty.*if.*CAT')
def test_value3_blank_if_toc3_empty(self): sheet = OPWorkbook(self.pages_invalid_workbook, self.pages_config).pages sheet.validate_blank('value3') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches( sheet.errors[0], r"'VALUE3' must be empty.* 'TAG3'.*'March 15'")
def test_validate_blank_if_other_in_list_repeating(self): sheet = OPWorkbook(self.empty_if_workbook, self.empty_if_config).description sheet.validate_blank('empty_if_5_is_cat') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches( sheet.errors[0], r'.* must be empty if.*is.*CAT.*; found:.*value 2.*')
def test_validate_repeating_false_more_than_one_value(self): sheet = OPWorkbook(self.repeating_workbook, self.repeating_config).description sheet.validate_repeating('non_repeating_field_invalid') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches( sheet.errors[0], r'More than one.*Non-repeating field invalid.*value1.*value2')
def test_value2_blank_if_toc2_empty(self): sheet = OPWorkbook(self.pages_invalid_workbook, self.pages_config).pages sheet.validate_blank('value2') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches( sheet.errors[0], r"'VALUE2' must be empty.* 'TAG2'.*'September 27'")
def test_validate_uniqueness(self): sheet = OPWorkbook(self.pages_invalid_workbook, self.pages_config).pages sheet.validate_uniqueness('file_name') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches( sheet.errors[0], r"'FILE_NAME' cannot have duplicate values; found:.*(2x)")
def test_validate_blank_if_other_nonempty_invalid(self): sheet = OPWorkbook(self.empty_if_workbook, self.empty_if_config).description sheet.validate_blank( 'empty_if_field_2_nonempty_first_and_third_present') self.assertEqual(len(sheet.errors), 2) self.assertRegexpMatches(sheet.errors[0], r'.* must be empty if.*has a value; found') self.assertRegexpMatches(sheet.errors[1], r'.* must be empty if.*has a value; found')
def test_init(self): sheet = OPWorkbook(self.valid_workbook, self.get_config()).description self.assertIsInstance(sheet, ValidatableSheet)
def test_handles_unicode(self): workbook = OPWorkbook(self.valid_workbook_unicode, self.get_config()) workbook.validate_description() workbook.validate_pages()
def test_validate_sheet_missing_optional_fields(self): sheet = OPWorkbook(self.missing_field_workbook, self.field_missing_config).description sheet.validate() self.assertFalse(sheet.has_errors())
def test_untrimmed_workbook(self): wkbk = OPWorkbook(self.untrimmed_workbook, json.load(open(self.bibliophilly_json))) wkbk.validate() self.assertFalse(wkbk.has_metadata_errors())
def test_muslimworld(self): config_dict = json.load(open(self.muslim_world_json)) wkbk = OPWorkbook(self.muslim_world_workbook, config_dict) attrs = [key for key in config_dict['sheet_config']['pages']['fields']] wkbk.validate() self.assertFalse(wkbk.has_metadata_errors())
def test_validate_repeating_true_more_than_one_value(self): sheet = OPWorkbook(self.repeating_workbook, self.repeating_config).description sheet.validate_repeating('repeating_field_multiple_values') self.assertEqual(len(sheet.errors), 0)
def test_validate_value_list_valid_value_lower_case(self): sheet = OPWorkbook(self.value_lists_workbook, self.value_lists_test_config).description sheet.validate_value_list('rights_pd_lower_case') self.assertEqual(len(sheet.errors), 0)
def test_validate_repeating_false_one_value(self): sheet = OPWorkbook(self.repeating_workbook, self.repeating_config).description sheet.validate_repeating('non_repeating_field_valid') self.assertEqual(len(sheet.errors), 0)
def test_validate_required_if_other_empty_valid(self): sheet = OPWorkbook(self.required_values_workbook, self.requirements_config).description sheet.validate_requirement('required_if_field_1_empty_valid') self.assertEqual(len(sheet.errors), 0)
def test_validate_value_list_with_value_empty(self): sheet = OPWorkbook(self.value_lists_workbook, self.value_lists_test_config).description sheet.validate_value_list('rights_4_blank') self.assertEqual(len(sheet.errors), 0)
def test_validate_required_if_other_empty_valid_repeating(self): sheet = OPWorkbook(self.required_values_workbook, self.requirements_config).description sheet.validate_requirement( 'required_if_field_2_nonempty_first_and_third_missing') self.assertEqual(len(sheet.errors), 2)
def test_validate_requirement_invalid(self): sheet = OPWorkbook(self.required_values_workbook, self.requirements_config).description sheet.validate_requirement('field_3_required_invalid') self.assertEqual(len(sheet.errors), 1) self.assertRegexpMatches(sheet.errors[0], r'Field 3.* cannot be empty')
def test_validate_blank_if_other_in_list_valid(self): sheet = OPWorkbook(self.empty_if_workbook, self.empty_if_config).description sheet.validate_blank('empty_if_3_is_cat_valid') self.assertEqual(len(sheet.errors), 0)
def test_validate_requirement_not_required_with_value(self): sheet = OPWorkbook(self.required_values_workbook, self.requirements_config).description sheet.validate_requirement('field_6_not_required_value') self.assertEqual(len(sheet.errors), 0)
def test_validate_required_if_other_in_list_differing_case(self): sheet = OPWorkbook(self.required_values_workbook, self.requirements_config).description sheet.validate_requirement('require_if_field_8_is_CAT_valid') self.assertEqual(len(sheet.errors), 0)