示例#1
0
 def test_required_fields_type_valid(self):
     form = RequiredFieldsForm({
         'estimated_value': 1000,
         'entities': Organization.objects.get(id=1),
         'type': CommodityType.objects.get(id=1),
         'code': Code.objects.get(id=1)
     })
     form.is_valid()
     self.assertEqual(CommodityType.objects.get(id=1), form.data['type'])
示例#2
0
 def test_required_fields_blank(self):
     form = RequiredFieldsForm(data={
         'estimated_value': None,
         'entities': None,
         'type': None,
         'code': None
     })
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['estimated_value'],
                      ['This field is required.'])
     self.assertEqual(form.errors['entities'], ['This field is required.'])
     self.assertEqual(form.errors['type'], ['This field is required.'])
     self.assertEqual(form.errors['code'], [generic_error])
示例#3
0
 def test_required_fields_wrong_data_one(self):
     form = RequiredFieldsForm(
         data={
             'estimated_value': -1676,
             'entities': 'Missing dept',
             'type': 'missing type',
             'code': 'missing code'
         })
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['estimated_value'],
                      ['Ensure this value is greater than or equal to 0.'])
     self.assertEqual(form.errors['entities'], [generic_error])
     self.assertEqual(form.errors['type'], [generic_error])
     self.assertEqual(form.errors['code'], [generic_error])
示例#4
0
 def test_required_fields_wrong_data_two(self):
     form = RequiredFieldsForm(
         data={
             'estimated_value': 'dsfdsf',
             'entities': 'Missing dept',
             'type': 'missing type',
             'code': 'missing code'
         })
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['estimated_value'],
                      ['Enter a whole number.'])
     self.assertEqual(form.errors['entities'], [generic_error])
     self.assertEqual(form.errors['type'], [generic_error])
     self.assertEqual(form.errors['code'], [generic_error])
示例#5
0
 def test_required_fields_labels(self):
     form = RequiredFieldsForm()
     self.assertIn(str(estimated_value_label), form.as_p())
     self.assertIn(str(entities_label), form.as_p())
     self.assertIn(str(type_label), form.as_p())
     self.assertIn(str(code_label), form.as_p())