Esempio n. 1
0
 def test_string_data_validator_short_string_with_min_and_max_lengths_fail_string_to_long(
         self):
     sdv = StringDataValidator()
     result = sdv.validate(data=self.short_str, min_length=1, max_length=2)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, bool)
     self.assertFalse(result)
Esempio n. 2
0
 def test_string_data_validator_short_string_with_start_with_alpha_and_start_with_space(
         self):
     sdv = StringDataValidator()
     result = sdv.validate(data=' {}'.format(self.short_str),
                           start_with_alpha=False)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, bool)
     self.assertTrue(result)
Esempio n. 3
0
 def test_string_data_validator_short_string_with_start_with_alpha_but_start_with_numeric(
         self):
     sdv = StringDataValidator()
     result = sdv.validate(data='1{}'.format(self.short_str),
                           start_with_alpha=True)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, bool)
     self.assertFalse(result)
Esempio n. 4
0
 def test_string_data_validator_none_value_with_contain_at_least_one_space_but_doesnt(
         self):
     sdv = StringDataValidator()
     result = sdv.validate(data=self.short_str,
                           contain_at_least_one_space=True)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, bool)
     self.assertFalse(result)
Esempio n. 5
0
 def test_generic_data_container_tuple_with_string_validator_and_unsupported_data_expecting_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=tuple,
                                data_validator=StringDataValidator())
     with self.assertRaises(Exception):
         gdc.store(data='This must fail', start_with_alpha=False)
Esempio n. 6
0
 def test_generic_data_container_string_with_string_validator_and_invalid_string_must_raise_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=str,
                                data_validator=StringDataValidator())
     input_str = ' abc'
     with self.assertRaises(Exception):
         gdc.store(data=input_str, start_with_alpha=True)
Esempio n. 7
0
 def test_generic_data_container_string_with_string_validator_and_valid_string(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=str,
                                data_validator=StringDataValidator())
     input_str = 'abc'
     gdc.store(data=input_str, start_with_alpha=True)
     self.assertEqual(gdc.data, 'abc')
Esempio n. 8
0
 def test_generic_data_container_float_with_invalid_validator_expect_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=float,
                                data_validator=StringDataValidator())
     l = 1001.001
     with self.assertRaises(Exception):
         gdc.store(data=l, min_value=0.0, max_value=3000.0)
Esempio n. 9
0
 def test_string_data_validator_data_container_all_defaults(self):
     self.data_container = GenericDataContainer(
         result_set_name='Test',
         data_type=str,
         data_validator=StringDataValidator())
     result = self.data_container.store(data=self.short_str)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, int)
     self.assertEqual(len(self.short_str), result)
Esempio n. 10
0
 def test_generic_data_container_list_with_string_validator_and_one_invalid_object_must_raise_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=list,
                                data_validator=StringDataValidator())
     l = ['Item 1', 1, 'This item will be ignored']
     result = gdc.store(data=l[0], start_with_alpha=False)
     self.assertEqual(1, result)
     with self.assertRaises(Exception):
         result = gdc.store(data=l[1], start_with_alpha=False)
Esempio n. 11
0
 def test_generic_data_container_decimal_with_invalid_validator_and_valid_decimal_expect_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=Decimal,
                                data_validator=StringDataValidator())
     l = Decimal(1001.01)
     with self.assertRaises(Exception):
         gdc.store(data=l,
                   min_value=Decimal(0.0),
                   max_value=Decimal(9999.0))
Esempio n. 12
0
 def test_generic_data_container_list_with_string_validator_and_valid_strings(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=list,
                                data_validator=StringDataValidator())
     l = ['Item 1', 'Item 2']
     qty = 0
     for item in l:
         qty = qty + 1
         result = gdc.store(data=item, start_with_alpha=False)
         self.assertEqual(qty, result,
                          'Item "{}" failed to be stored'.format(qty))
Esempio n. 13
0
 def test_generic_data_container_tuple_with_string_validator_and_valid_strings(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=tuple,
                                data_validator=StringDataValidator())
     l = (
         'Item 1',
         'Item 2',
     )
     result = gdc.store(data=l, start_with_alpha=False)
     self.assertEqual(len(l), result,
                      'Item "{}" failed to be stored'.format(len(l)))
Esempio n. 14
0
 def test_generic_data_container_tuple_with_string_validator_and_data_validation_fail_expecting_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=tuple,
                                data_validator=StringDataValidator())
     l = (
         'Item 1',
         'Item 2',
         3,
     )
     with self.assertRaises(Exception):
         gdc.store(data=l, start_with_alpha=False)
Esempio n. 15
0
 def test_init_string_data_validator(self):
     sdv = StringDataValidator()
     self.assertIsNotNone(sdv)
     self.assertIsInstance(sdv, DataValidator)
     self.assertIsInstance(sdv, StringDataValidator)
Esempio n. 16
0
 def test_string_data_validator_none_value_with_can_be_none_is_true(self):
     sdv = StringDataValidator()
     result = sdv.validate(data=None, can_be_none=True)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, bool)
     self.assertTrue(result)
Esempio n. 17
0
 def test_string_data_validator_short_string_with_start_with_alpha(self):
     sdv = StringDataValidator()
     result = sdv.validate(data=self.short_str, min_length=2, max_length=5)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, bool)
     self.assertTrue(result)
Esempio n. 18
0
 def test_string_data_validator_short_string_all_defaults(self):
     sdv = StringDataValidator()
     result = sdv.validate(data=self.short_str)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, bool)
     self.assertTrue(result)