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_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_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 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 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 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_data(self): account = PinboardAccountFactory(username='******') BookmarkFactory.create_batch(3, account=account, post_time=make_datetime('2018-01-01 12:00:00')) result = PinboardGenerator( username='******').get_bookmarks_per_year() self.assertIn('data', result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data'][0]['label'], '2018') self.assertEqual(result['data'][0]['value'], 3)
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 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_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 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_pinboard_bookmarks(self): "It only returns public Bookmarks from the correct Account" a1 = PinboardAccountFactory(username='******') a2 = PinboardAccountFactory(username='******') BookmarkFactory.create_batch(3, account=a1, is_private=False) # These shouldn't be returned: BookmarkFactory(account=a1, is_private=True) BookmarkFactory(account=a2, is_private=False) r = RecentObjects( (('pinboard_bookmarks', 'bob',),) ) objects = r.get_objects() self.assertEqual(len(objects), 3) for obj in objects: self.assertEqual(obj['object'].account, a1) self.assertFalse(obj['object'].is_private)
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 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 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_years(self): "Should include all intermediate years." account = PinboardAccountFactory(username='******') BookmarkFactory(account=account, post_time=make_datetime('2014-01-01 12:00:00')) BookmarkFactory.create_batch(3, account=account, post_time=make_datetime('2016-01-01 12:00:00')) BookmarkFactory(account=account, post_time=make_datetime('2018-01-01 12:00:00')) result = PinboardGenerator( username='******').get_bookmarks_per_year() self.assertIn('data', result) self.assertEqual(result['data'], [ {'label': '2014', 'value': 1}, {'label': '2015', 'value': 0}, {'label': '2016', 'value': 3}, {'label': '2017', 'value': 0}, {'label': '2018', 'value': 1}, ])
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)