(Again, since this is a model-layer test, it’s OK to use the ORM. You could conceivable
write this test using mocks, but there wouldn’t be much point).
lists/models.py (ch19l041).
@property
def
name
(
self
):
return
self
.
item_set
.
first
()
.
text
And that gets us to a passing FT!
$
python3 manage.py test functional_tests.test_my_lists
Ran 1 test in 21.428s
OK
Tidy Up: What to Keep from Our Integrated Test Suite
Now everything is working, we can remove some redundant tests, and decide whether
we want to keep any of our old integrated tests.
Removing Redundant Code at the Forms Layer
We can get rid of the test for the old save method on the
ItemForm
:
lists/tests/test_forms.py.
--- a/lists/tests/test_forms.py
+++ b/lists/tests/test_forms.py
@@ -23,14 +23,6 @@ class ItemFormTest(TestCase):
self.assertEqual(form.errors['text'], [EMPTY_LIST_ERROR])
- def test_form_save_handles_saving_to_a_list(self):
- list_ = List.objects.create()
- form = ItemForm(data={'text': 'do me'})
- new_item = form.save(for_list=list_)
- self.assertEqual(new_item, Item.objects.first())
- self.assertEqual(new_item.text, 'do me')
- self.assertEqual(new_item.list, list_)
-
And in our actual code, we can get rid of two redundant save methods in
forms.py
:
lists/forms.py.
--- a/lists/forms.py
+++ b/lists/forms.py
@@ -22,11 +22,6 @@ class ItemForm(forms.models.ModelForm):
self.fields['text'].error_messages['required'] = EMPTY_LIST_ERROR
- def save(self, for_list):
Tidy Up: What to Keep from Our Integrated Test Suite
|
359