def test_url_constraint(self): """Ensures bookmarks have unique URLs within an Account""" account = AccountFactory() bookmark_1 = BookmarkFactory( account=account, url='http://www.example.com') bookmark_1.save() with self.assertRaises(IntegrityError): bookmark_2 = BookmarkFactory( account=account, url='http://www.example.com')
def test_url_constraint(self): """Ensures bookmarks have unique URLs within an Account""" account = AccountFactory() bookmark_1 = BookmarkFactory(account=account, url='http://www.example.com') bookmark_1.save() with self.assertRaises(IntegrityError): bookmark_2 = BookmarkFactory(account=account, url='http://www.example.com')
def test_url_unconstrained(self): """URLs do not have to be unique for different Accounts' Bookmarks""" account_1 = AccountFactory() bookmark_1 = BookmarkFactory( account=account_1, url='http://www.example.com') bookmark_1.save() account_2 = AccountFactory() try: bookmark_2 = BookmarkFactory( account=account_2, url='http://www.example.com') except IntegrityError: self.fail("It looks like there's a Unique constraint on Bookmark.url, which there shouldn't be.")
def test_url_unconstrained(self): """URLs do not have to be unique for different Accounts' Bookmarks""" account_1 = AccountFactory() bookmark_1 = BookmarkFactory(account=account_1, url='http://www.example.com') bookmark_1.save() account_2 = AccountFactory() try: bookmark_2 = BookmarkFactory(account=account_2, url='http://www.example.com') except IntegrityError: self.fail( "It looks like there's a Unique constraint on Bookmark.url, which there shouldn't be." )
def test_save(self): """Calls the parent save() method when saving, so it actually saves""" bookmark = BookmarkFactory(title='My title') bookmark.save() b = Bookmark.objects.get(title='My title') self.assertEqual(b.pk, bookmark.pk)