Пример #1
0
 def test_type_is_required(self):
     form_data = self.form_data
     form_data['type'] = ''
     location_form = LocationForm(form_data)
     self.assertFalse(location_form.is_valid())
     self.assertEquals(location_form.errors['type'],
                       ['This field is required.'])
Пример #2
0
 def test_form_should_be_invalid_if_location_already_exists(self):
     Location.objects.create(name=self.form_data['name'],
                             type=self.district,
                             tree_parent=self.uganda)
     location_form = LocationForm(self.form_data)
     self.assertFalse(location_form.is_valid())
     self.assertEquals(location_form.errors['__all__'],
                       ['This location already exists.'])
Пример #3
0
    def test_valid_if_editing_instance(self):
        data = self.form_data.copy()
        data['type'] = self.district
        data['tree_parent'] = self.uganda

        Location.objects.create(**data)
        location_form = LocationForm(initial=data, data=self.form_data)
        self.assertTrue(location_form.is_valid())
Пример #4
0
    def test_valid_if_editing_instance(self):
        data = self.form_data.copy()
        data['type'] = self.district
        data['tree_parent'] = self.uganda

        Location.objects.create(**data)
        location_form = LocationForm(initial=data, data=self.form_data)
        self.assertTrue(location_form.is_valid())
Пример #5
0
 def test_valid(self):
     location_form = LocationForm(self.form_data)
     self.assertTrue(location_form.is_valid())
Пример #6
0
 def test_form_should_be_invalid_if_location_already_exists(self):
     Location.objects.create(name=self.form_data['name'], type=self.district, tree_parent=self.uganda)
     location_form = LocationForm(self.form_data)
     self.assertFalse(location_form.is_valid())
     self.assertEquals(location_form.errors['__all__'], ['This location already exists.'])
Пример #7
0
 def test_type_is_required(self):
     form_data = self.form_data
     form_data['type']=''
     location_form = LocationForm(form_data)
     self.assertFalse(location_form.is_valid())
     self.assertEquals(location_form.errors['type'], ['This field is required.'])
Пример #8
0
 def test_valid(self):
     location_form = LocationForm(self.form_data)
     self.assertTrue(location_form.is_valid())