def test_adds_required_error_if_unset(self): # this one is having trouble with translation field = field_base.Field({}) self.assertEqual(field.is_valid(), False) expected_error_message = "This field is required." error_message = field.errors['no_context'].pop() # must be cast as string to evaluate the lazy translation string self.assertEqual(str(error_message), expected_error_message)
def test_init_with_data(self): data = {"no_context": "some data"} field = field_base.Field(data) self.assertTrue(field.is_bound()) self.assertTrue(field.is_valid()) self.assertDictEqual(field.raw_input_data, data) self.assertEqual(field.raw_input_value, "some data") self.assertEqual(field.parsed_data, "some data")
def test_init(self): field = field_base.Field() self.assertFalse(field.is_multivalue) self.assertEqual(field.context_key, base.DEFAULT_CONTEXT_KEY) self.assertEqual(field.get_input_name(), base.DEFAULT_CONTEXT_KEY) self.assertEqual(field.get_html_class_name(), base.DEFAULT_CONTEXT_KEY) self.assertFalse(field.is_bound()) with self.assertRaises(NotImplementedError): field.is_valid()
def test_defaults_to_recommended_false(self): field = field_base.Field({}) self.assertEqual(field.recommended, False)
def test_defaults_to_required(self): field = field_base.Field({}) self.assertEqual(field.required, True)