コード例 #1
0
 def test_field_example_value_is_array_raises(self):
     field = {
         'field_details': {
             'name': 'test',
             'example': ['bob', 'alice']
         }
     }
     with self.assertRaisesRegex(ValueError, 'contains an object or array'):
         cleaner.check_example_value(field)
コード例 #2
0
 def test_example_value_mismatch_with_pattern(self):
     field = {
         'field_details': {
             'name': 'test',
             'example': 'AA',
             'pattern': 'A{3}'
         }
     }
     with self.assertRaisesRegex(
             ValueError, 'does not match the regex defined in the pattern'):
         cleaner.check_example_value(field)
コード例 #3
0
 def test_example_field_value_is_array_warns_strict_disabled(self):
     field = {
         'field_details': {
             'name': 'test',
             'example': ['bob', 'alice']
         }
     }
     try:
         with self.assertWarnsRegex(UserWarning,
                                    'contains an object or array'):
             cleaner.check_example_value(field, strict=False)
     except Exception:
         self.fail(
             "cleaner.check_example_value() raised Exception unexpectedly.")
コード例 #4
0
 def test_example_value_mismatch_with_pattern_strict_disabled(self):
     field = {
         'field_details': {
             'name': 'test',
             'example': 'AA',
             'pattern': 'A{3}'
         }
     }
     try:
         with self.assertWarnsRegex(
                 UserWarning,
                 'does not match the regex defined in the pattern'):
             cleaner.check_example_value(field, strict=False)
     except Exception:
         self.fail(
             "clean.check_example_value() raised Exception unexpectedly.")