Test-Driven Development with Python by Harry Percival

Test-Driven Development with Python by Harry Percival

Author:Harry Percival
Language: eng
Format: epub, mobi
ISBN: 9781449364823
Publisher: O’Reilly Media, Inc.
Published: 2014-10-26T16:00:00+00:00


Experimenting with Duplicate Item Validation at the Views Layer

Let’s try running our FT, just to see where we are:

selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate element: {"method":"id","selector":"id_list_table"}' ; Stacktrace:

In case you didn’t see it as it flew past, the site is 500ing.[16] A quick unit test at the view level ought to clear this up:

lists/tests/test_views.py (ch12l014).

class ListViewTest(TestCase): [...] def test_for_invalid_input_shows_error_on_page(self): [...] def test_duplicate_item_validation_errors_end_up_on_lists_page(self): list1 = List.objects.create() item1 = Item.objects.create(list=list1, text='textey') response = self.client.post( '/lists/%d/' % (list1.id,), data={'text': 'textey'} ) expected_error = escape("You've already got this in your list") self.assertContains(response, expected_error) self.assertTemplateUsed(response, 'list.html') self.assertEqual(Item.objects.all().count(), 1)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.