def test_can_be_instantiated_with_preparsed_data(self): valid, invalid, blank, missing = mock.get_dict_examples( 'name', 'Marzipan', None) field = NameField(valid) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), 'Marzipan') for input_data in [blank, missing]: field = NameField(input_data) self.assertFalse(field.is_valid()) self.assertEqual(field.get_current_value(), '') for input_data in [blank, missing]: field = NameField(input_data, required=False) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), '')
def test_can_be_instantiated_with_preparsed_data(self): valid, invalid, blank, missing = mock.get_dict_examples( 'name', 'Marzipan', None) field = NameField(valid) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), 'Marzipan') for input_data in [blank, missing]: field = NameField(input_data) self.assertFalse(field.is_valid()) self.assertEqual(field.get_current_value(), '') for input_data in [blank, missing]: field = NameField(input_data, required=False) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), '')
def test_can_be_instantiated_with_preparsed_data(self): valid, invalid, blank, missing = mock.get_dict_examples( 'fruit', 'apples', 'bananas') field = SingleFruit(valid) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), 'apples') field = SingleFruit(invalid) self.assertFalse(field.is_valid()) self.assertEqual(field.get_current_value(), 'bananas') for input_data in [blank, missing]: field = SingleFruit(input_data, required=False) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), '')
def test_can_be_instantiated_with_preparsed_data(self): valid, invalid, blank, missing = mock.get_dict_examples( 'fruit', 'apples', 'bananas') field = SingleFruit(valid) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), 'apples') field = SingleFruit(invalid) self.assertFalse(field.is_valid()) self.assertEqual(field.get_current_value(), 'bananas') for input_data in [blank, missing]: field = SingleFruit(input_data, required=False) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), '')
def test_can_be_instantiated_with_preparsed_data(self): valid, invalid, blank, missing = mock.get_dict_examples( 'fruit', ['oranges', 'apples'], ['bananas']) field = MultipleFruit(valid) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), ['oranges', 'apples']) field = MultipleFruit(invalid) self.assertFalse(field.is_valid()) self.assertEqual(field.get_current_value(), ['bananas']) field = MultipleFruit(blank, required=False) with self.assertRaises(TypeError): field.is_valid() field = MultipleFruit(missing, required=False) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), [])
def test_can_be_instantiated_with_preparsed_data(self): valid, invalid, blank, missing = mock.get_dict_examples( 'fruit', ['oranges', 'apples'], ['bananas']) field = MultipleFruit(valid) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), ['oranges', 'apples']) field = MultipleFruit(invalid) self.assertFalse(field.is_valid()) self.assertEqual(field.get_current_value(), ['bananas']) field = MultipleFruit(blank, required=False) with self.assertRaises(TypeError): field.is_valid() field = MultipleFruit(missing, required=False) self.assertTrue(field.is_valid()) self.assertEqual(field.get_current_value(), [])