示例#1
0
 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'")
示例#2
0
 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:')
示例#3
0
 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.*')
示例#4
0
 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.*')
示例#5
0
 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')
示例#6
0
 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'")
示例#7
0
 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)
示例#8
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'")
示例#9
0
 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')
示例#10
0
 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'")
示例#11
0
 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.*')
示例#12
0
 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')
示例#13
0
 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'")
示例#14
0
 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)")
示例#15
0
 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')
示例#16
0
 def test_init(self):
     sheet = OPWorkbook(self.valid_workbook, self.get_config()).description
     self.assertIsInstance(sheet, ValidatableSheet)
示例#17
0
    def test_handles_unicode(self):
        workbook = OPWorkbook(self.valid_workbook_unicode, self.get_config())

        workbook.validate_description()
        workbook.validate_pages()
示例#18
0
 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())
示例#19
0
 def test_untrimmed_workbook(self):
     wkbk = OPWorkbook(self.untrimmed_workbook,
                       json.load(open(self.bibliophilly_json)))
     wkbk.validate()
     self.assertFalse(wkbk.has_metadata_errors())
示例#20
0
 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())
示例#21
0
 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)
示例#22
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)
示例#23
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)
示例#24
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)
示例#25
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)
示例#26
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)
示例#27
0
 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')
示例#28
0
 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)
示例#29
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)
示例#30
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)