def setUp(self): account_1 = AccountFactory(username='******') account_2 = AccountFactory(username='******') self.bookmarks_1 = BookmarkFactory.create_batch(6, account=account_1) self.bookmarks_2 = BookmarkFactory.create_batch(6, account=account_2) self.bookmarks_1[5].is_private = True self.bookmarks_1[5].save()
def test_account_tag_detail_context(self): "Sends the correct data to templates" account_1 = AccountFactory() account_2 = AccountFactory() bookmarks_1 = BookmarkFactory.create_batch(3, account=account_1) bookmarks_1[0].tags.set('Fish', 'carp') bookmarks_1[1].tags.set('Fish', 'cod') bookmarks_1[2].tags.set('mammals', 'dog') bookmarks_2 = BookmarkFactory.create_batch(3, account=account_2) bookmarks_2[0].tags.set('Fish', 'carp') bookmarks_2[1].tags.set('Fish', 'cod') bookmarks_2[2].tags.set('mammals', 'dog') response = self.client.get( reverse('pinboard:account_tag_detail', kwargs={ 'username': account_1.username, 'tag_slug': 'fish' })) self.assertIn('account', response.context) self.assertEqual(account_1.pk, response.context['account'].pk) self.assertIn('tag', response.context) self.assertEqual(response.context['tag'].name, 'Fish') self.assertIn('bookmark_list', response.context) self.assertEqual(len(response.context['bookmark_list']), 2) self.assertEqual( [bookmark.pk for bookmark in response.context['bookmark_list']], [2, 1])
def setUp(self): self.user_1 = AccountFactory(username='******', url='https://pinboard.in/u:philgyford', api_token='philgyford:1234567890ABCDEFGHIJ') self.user_2 = AccountFactory(username='******', url='https://pinboard.in/u:testuser', api_token='testuser:ABCDEFGHIJ1234567890')
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 setUp(self): account_1 = AccountFactory(username='******') account_2 = AccountFactory(username='******') self.bookmarks_1 = BookmarkFactory.create_batch(6, account=account_1) self.bookmarks_2 = BookmarkFactory.create_batch(6, account=account_2) post_time = datetime.datetime(2015, 3, 18, 12, 0, 0).replace(tzinfo=pytz.utc) self.bookmarks_1[3].post_time = post_time self.bookmarks_1[3].save() self.bookmarks_1[5].is_private = True self.bookmarks_1[5].post_time = post_time + datetime.timedelta(hours=1) self.bookmarks_1[5].save() self.bookmarks_2[4].post_time = post_time + datetime.timedelta(hours=2) self.bookmarks_2[4].save()
def test_get_absolute_url(self): "Has the correct URL on this site" account = AccountFactory(username='******') bookmark = BookmarkFactory(account=account, url='http://www.example.com') self.assertEqual(bookmark.get_absolute_url(), '/pinboard/billy/847310eb455f/')
def setUp(self): account_1 = AccountFactory(username='******') account_2 = AccountFactory(username='******') # Bookmarks in 2015 and 2016 for account_1: BookmarkFactory.create_batch(3, post_time=datetime_from_str('2015-01-01 12:00:00'), account=account_1) BookmarkFactory.create_batch(2, post_time=datetime_from_str('2016-01-01 12:00:00'), account=account_1) # And one for account_2 in 2015: BookmarkFactory(account=account_2, post_time=datetime_from_str('2015-01-01 12:00:00')) # And one private bookmark for account_1 in 2015: BookmarkFactory(account=account_1, is_private=True, post_time=datetime_from_str('2015-01-01 12:00:00'))
def test_account_detail_context(self): "Sends the correct data to templates" account_1 = AccountFactory() account_2 = AccountFactory() bookmarks_1 = BookmarkFactory.create_batch(3, account=account_1) bookmarks_2 = BookmarkFactory.create_batch(3, account=account_2) response = self.client.get( reverse('pinboard:account_detail', kwargs={'username': account_1.username})) self.assertIn('account', response.context) self.assertEqual(account_1.pk, response.context['account'].pk) self.assertIn('bookmark_list', response.context) self.assertEqual(len(response.context['bookmark_list']), 3) self.assertEqual( [bookmark.pk for bookmark in response.context['bookmark_list']], [3, 2, 1])
def test_to_read_context(self): """The Pinboard 'to read' page sends the correct data to templates. Also tests privacy.""" accounts = AccountFactory.create_batch(3) bookmarks_1 = BookmarkFactory.create_batch(2, account=accounts[0]) bookmarks_2 = BookmarkFactory.create_batch(2, account=accounts[1]) bookmarks_1[0].to_read = True bookmarks_1[0].save() bookmarks_1[1].to_read = True bookmarks_1[1].is_private = True bookmarks_1[1].save() bookmarks_2[1].to_read = True bookmarks_2[1].save() response = self.client.get(reverse('pinboard:toread')) self.assertIn('account_list', response.context) self.assertIn('bookmark_list', response.context) # Three accounts, only two of which have bookmarks: self.assertEqual( [account.pk for account in response.context['account_list']], [1,2,3] ) # Bookmarks for both accounts that have them: self.assertEqual( [bookmark.pk for bookmark in response.context['bookmark_list']], [bookmarks_2[1].pk, bookmarks_1[0].pk,] )
def test_to_read_context(self): """The Pinboard 'to read' page sends the correct data to templates. Also tests privacy.""" accounts = AccountFactory.create_batch(3) bookmarks_1 = BookmarkFactory.create_batch(2, account=accounts[0]) bookmarks_2 = BookmarkFactory.create_batch(2, account=accounts[1]) bookmarks_1[0].to_read = True bookmarks_1[0].save() bookmarks_1[1].to_read = True bookmarks_1[1].is_private = True bookmarks_1[1].save() bookmarks_2[1].to_read = True bookmarks_2[1].save() response = self.client.get(reverse('pinboard:toread')) self.assertIn('account_list', response.context) self.assertIn('bookmark_list', response.context) # Three accounts, only two of which have bookmarks: self.assertEqual( [account.pk for account in response.context['account_list']], [1, 2, 3]) # Bookmarks for both accounts that have them: self.assertEqual( [bookmark.pk for bookmark in response.context['bookmark_list']], [ bookmarks_2[1].pk, bookmarks_1[0].pk, ])
def test_account_detail_fails(self): "Requests for non-existent accounts 404" account = AccountFactory() response = self.client.get( reverse('pinboard:account_detail', kwargs={'username': '******'})) self.assertEquals(response.status_code, 404)
def test_public_bookmarks_count(self): account = AccountFactory() public_bookmarks = BookmarkFactory.create_batch(3, account=account, is_private=False) private_bookmarks = BookmarkFactory.create_batch(2, account=account, is_private=True) self.assertEqual(account.public_bookmarks_count, 3)
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_home_context(self): "The Pinboard home page sends the correct data to templates" account_1 = AccountFactory(username='******') account_2 = AccountFactory(username='******') account_3 = AccountFactory(username='******') bookmarks_1 = BookmarkFactory.create_batch(5, account=account_1) bookmarks_2 = BookmarkFactory.create_batch(5, account=account_2) response = self.client.get(reverse('pinboard:home')) self.assertIn('account_list', response.context) self.assertIn('bookmark_list', response.context) # Three accounts, only two of which have bookmarks: self.assertEqual( [account.pk for account in response.context['account_list']], [1, 2, 3]) # Bookmarks for both accounts that have them: self.assertEqual( [bookmark.pk for bookmark in response.context['bookmark_list']], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1])
def setUp(self): accounts = AccountFactory.create_batch(3) self.bookmarks_1 = BookmarkFactory.create_batch(2, account=accounts[0]) self.bookmarks_2 = BookmarkFactory.create_batch(2, account=accounts[1]) self.bookmarks_1[0].to_read = True self.bookmarks_1[0].is_private = True self.bookmarks_1[0].save() self.bookmarks_2[1].to_read = True self.bookmarks_2[1].save()
def test_account_detail_templates(self): "Uses the correct templates" account = AccountFactory() response = self.client.get( reverse('pinboard:account_detail', kwargs={'username': account.username})) self.assertEquals(response.status_code, 200) self.assertTemplateUsed(response, 'pinboard/account_detail.html') self.assertTemplateUsed(response, 'pinboard/base.html') self.assertTemplateUsed(response, 'ditto/base.html')
def setUp(self): accounts = AccountFactory.create_batch(3) self.bookmarks_1 = BookmarkFactory.create_batch(2, account=accounts[0]) self.bookmarks_2 = BookmarkFactory.create_batch(2, account=accounts[1]) self.bookmarks_1[0].to_read = True self.bookmarks_1[0].is_private = True self.bookmarks_1[0].save() self.bookmarks_2[1].to_read = True self.bookmarks_2[1].save()
def test_account_detail_privacy(self): "It does not show private Bookmarks" account = AccountFactory() public_bookmark = BookmarkFactory(account=account, is_private=False) private_bookmark = BookmarkFactory(account=account, is_private=True) response = self.client.get( reverse('pinboard:account_detail', kwargs={'username': account.username})) self.assertEqual(len(response.context['bookmark_list']), 1) self.assertTrue(response.context['bookmark_list'][0].pk, public_bookmark.pk)
def test_account_tag_detail_fails_2(self): "Returns a 404 if a non-existent tag is requested" account = AccountFactory() bookmark = BookmarkFactory(account=account) bookmark.tags.set('fish') response = self.client.get( reverse('pinboard:account_tag_detail', kwargs={ 'username': account.username, 'tag_slug': 'mammals' })) self.assertEquals(response.status_code, 404)
def setUp(self): dt = datetime.datetime.strptime( '2016-04-08 12:00:00', '%Y-%m-%d %H:%M:%S').replace(tzinfo=pytz.utc) account = AccountFactory() self.bookmark_1 = BookmarkFactory(account=account, post_time=dt) self.private_bookmark = BookmarkFactory(account=account, is_private=True, post_time=dt + datetime.timedelta(days=1)) # Bookmark by a different user: account_2 = AccountFactory() self.other_bookmark = BookmarkFactory(account=account_2, post_time=dt + datetime.timedelta(days=2)) self.bookmark_2 = BookmarkFactory(account=account, post_time=dt + datetime.timedelta(days=3))
def test_ordering(self): "Bookmarks are ordered correctly, most-recently-posted first" account = AccountFactory(username='******') post_time = datetime.datetime.strptime( '2015-01-01 12:00:00', "%Y-%m-%d %H:%M:%S").replace(tzinfo=pytz.utc) bookmark_1 = BookmarkFactory(account=account, post_time=post_time) bookmark_2 = BookmarkFactory(account=account, post_time=(post_time + datetime.timedelta(days=1))) bookmarks = Bookmark.objects.all() # Should be most recent first: self.assertEqual(bookmarks[0].pk, bookmark_2.pk) self.assertEqual(bookmarks[1].pk, bookmark_1.pk)
def test_account_tag_detail_templates(self): "Uses the correct templates" account = AccountFactory() bookmark = BookmarkFactory(account=account, title='Carp') bookmark.tags.set('fish', 'carp') response = self.client.get( reverse('pinboard:account_tag_detail', kwargs={ 'username': account.username, 'tag_slug': 'fish' })) self.assertEquals(response.status_code, 200) self.assertTemplateUsed(response, 'pinboard/account_tag_detail.html') self.assertTemplateUsed(response, 'pinboard/base.html') self.assertTemplateUsed(response, 'ditto/base.html')
def test_account_detail_context(self): "Sends the correct data to templates. Also tests privacy." accounts = AccountFactory.create_batch(2) bookmarks_1 = BookmarkFactory.create_batch(2, account=accounts[0]) bookmarks_2 = BookmarkFactory.create_batch(2, account=accounts[1]) bookmarks_1[0].to_read = True bookmarks_1[0].save() bookmarks_1[1].to_read = True bookmarks_1[1].is_private = True bookmarks_1[1].save() bookmarks_2[1].to_read = True bookmarks_2[1].save() response = self.client.get(reverse('pinboard:account_toread', kwargs={'username': accounts[0].username})) self.assertIn('account', response.context) self.assertEqual(accounts[0].pk, response.context['account'].pk) self.assertIn('bookmark_list', response.context) self.assertEqual(len(response.context['bookmark_list']), 1) self.assertEqual(response.context['bookmark_list'][0].pk, bookmarks_1[0].pk)
def test_account_detail_context(self): "Sends the correct data to templates. Also tests privacy." accounts = AccountFactory.create_batch(2) bookmarks_1 = BookmarkFactory.create_batch(2, account=accounts[0]) bookmarks_2 = BookmarkFactory.create_batch(2, account=accounts[1]) bookmarks_1[0].to_read = True bookmarks_1[0].save() bookmarks_1[1].to_read = True bookmarks_1[1].is_private = True bookmarks_1[1].save() bookmarks_2[1].to_read = True bookmarks_2[1].save() response = self.client.get( reverse('pinboard:account_toread', kwargs={'username': accounts[0].username})) self.assertIn('account', response.context) self.assertEqual(accounts[0].pk, response.context['account'].pk) self.assertIn('bookmark_list', response.context) self.assertEqual(len(response.context['bookmark_list']), 1) self.assertEqual(response.context['bookmark_list'][0].pk, bookmarks_1[0].pk)
def test_get_absolute_url(self): """Has the correct URL on this site""" account = AccountFactory(username='******') self.assertEqual(account.get_absolute_url(), '/pinboard/billy/')
def test_str(self): """The string representation of the Account is correct""" account = AccountFactory(username='******') self.assertEqual(account.__str__(), 'bill')
def test_ordering(self): """Multiple accounts are ordered alphabetically""" account_1 = AccountFactory(username='******') account_2 = AccountFactory(username='******') accounts = Account.objects.all() self.assertEqual(accounts[0].username, 'amanda')
def test_only_inactive_account(self): "Correctly reacts if only an inactive Account is tried" account = AccountFactory(username='******', is_active=False) with self.assertRaises(FetchError): result = RecentBookmarksFetcher().fetch(username='******')
def test_get_absolute_url(self): """Has the correct URL on this site""" account = AccountFactory(username='******') self.assertEqual(account.get_absolute_url(), '/pinboard/billy/')
def test_unique_url(self): """Ensures that Account URLs at Pinboard are unique""" account_1 = AccountFactory(url='https://pinboard.in/u:billy') with self.assertRaises(IntegrityError): account_2 = AccountFactory(url='https://pinboard.in/u:billy')
def test_unique_username(self): """Ensures that usernames are unique""" account_1 = AccountFactory(username='******') with self.assertRaises(IntegrityError): account_2 = AccountFactory(username='******')
def test_str(self): """The string representation of the Account is correct""" account = AccountFactory(username='******') self.assertEqual(account.__str__(), 'bill')
def test_inactive_accounts(self): "Correctly reacts fetching all accounts but all are inactive" account_1 = AccountFactory(username='******', is_active=False) account_2 = AccountFactory(username='******', is_active=False) with self.assertRaises(FetchError): result = RecentBookmarksFetcher().fetch()