Esempio n. 1
0
 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,
         ])
Esempio n. 2
0
 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):
     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()
Esempio n. 4
0
 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/')
Esempio n. 5
0
 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()
Esempio n. 6
0
    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]
        )
Esempio n. 7
0
 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)
Esempio n. 8
0
 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/')
Esempio n. 9
0
    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])
Esempio n. 10
0
 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)
Esempio n. 11
0
 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')
Esempio n. 12
0
 def test_public_manager(self):
     "The public manager does NOT include private bookmarks"
     public_bookmark_1 = BookmarkFactory(is_private=False)
     private_bookmark = BookmarkFactory(is_private=True)
     public_bookmark_2 = BookmarkFactory(is_private=False)
     bookmarks = Bookmark.public_objects.all()
     self.assertEqual(len(bookmarks), 2)
     self.assertEqual(bookmarks[0].pk, public_bookmark_2.pk)
     self.assertEqual(bookmarks[1].pk, public_bookmark_1.pk)
Esempio n. 13
0
 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')
Esempio n. 14
0
 def test_home_privacy(self):
     """Only public bookmarks should appear."""
     public_bookmark_1 = BookmarkFactory(is_private=False)
     private_bookmark = BookmarkFactory(is_private=True)
     public_bookmark_2 = BookmarkFactory(is_private=False)
     response = self.client.get(reverse('pinboard:home'))
     bookmarks = response.context['bookmark_list']
     self.assertEqual(len(bookmarks), 2)
     self.assertEqual(bookmarks[0].pk, public_bookmark_2.pk)
     self.assertEqual(bookmarks[1].pk, public_bookmark_1.pk)
Esempio n. 15
0
 def test_tag_list_context(self):
     "Sends the correct data to templates"
     bookmark_1 = BookmarkFactory()
     bookmark_1.tags.set('fish', 'carp')
     bookmark_2 = BookmarkFactory()
     bookmark_2.tags.set('fish', 'cod')
     response = self.client.get(reverse('pinboard:tag_list'))
     self.assertIn('account_list', response.context)
     self.assertIn('tag_list', response.context)
     self.assertEqual(len(response.context['tag_list']), 3)
Esempio n. 16
0
    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()
Esempio n. 17
0
 def test_tag_list_privacy_bookmarks(self):
     "Doesn't display tags from private bookmarks"
     bookmark_1 = BookmarkFactory(is_private=True)
     bookmark_1.tags.set('fish', 'carp')
     bookmark_2 = BookmarkFactory(is_private=False)
     bookmark_2.tags.set('fish', 'cod')
     response = self.client.get(reverse('pinboard:tag_list'))
     self.assertEqual(len(response.context['tag_list']), 2)
     self.assertEqual(response.context['tag_list'][0].name, 'fish')
     self.assertEqual(response.context['tag_list'][1].name, 'cod')
Esempio n. 18
0
    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()
Esempio n. 19
0
 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)
Esempio n. 20
0
 def test_tags_privacy_bookmarks(self):
     "Doesn't display tags from private bookmarks"
     bookmark_1 = BookmarkFactory(is_private=True)
     bookmark_1.tags.set('fish', 'carp')
     bookmark_2 = BookmarkFactory(is_private=False)
     bookmark_2.tags.set('fish', 'cod')
     tags = ditto_pinboard.popular_bookmark_tags()
     self.assertEqual(len(tags), 2)
     self.assertEqual(tags[0].name, 'fish')
     self.assertEqual(tags[0].num_times, 1)
     self.assertEqual(tags[1].name, 'cod')
     self.assertEqual(tags[1].num_times, 1)
Esempio n. 21
0
 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.")
Esempio n. 22
0
    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)
Esempio n. 23
0
 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)
Esempio n. 24
0
 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."
         )
Esempio n. 25
0
 def test_tags(self):
     "Contains the correct data"
     bookmark_1 = BookmarkFactory()
     bookmark_1.tags.set('fish', 'carp')
     bookmark_2 = BookmarkFactory()
     bookmark_2.tags.set('fish', 'cod')
     tags = ditto_pinboard.popular_bookmark_tags()
     self.assertEqual(len(tags), 3)
     self.assertEqual(tags[0].name, 'fish')
     self.assertEqual(tags[0].num_times, 2)
     self.assertEqual(tags[1].name, 'carp')
     self.assertEqual(tags[1].num_times, 1)
     self.assertEqual(tags[2].name, 'cod')
     self.assertEqual(tags[2].num_times, 1)
Esempio n. 26
0
    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()
Esempio n. 27
0
    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()
Esempio n. 28
0
 def test_tag_detail_privacy(self):
     "Does not display private bookmarks"
     bookmark = BookmarkFactory(is_private=True)
     bookmark.tags.set('fish')
     response = self.client.get(
         reverse('pinboard:tag_detail', kwargs={'slug': 'fish'}))
     self.assertEquals(response.status_code, 404)
Esempio n. 29
0
 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])
Esempio n. 30
0
 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]
     )
Esempio n. 31
0
    def test_no_update_bookmarks(self):
        """Ensure that if no values have changed, we don't update a bookmark.
        """
        account = Account.objects.get(pk=1)
        fetch_time = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)

        # Add a Bookmark into the DB before we fetch anything.
        bookmark = BookmarkFactory(
                        account=account,
                        title='Fontello - icon fonts generator',
                        is_private=False,
                        to_read=False,
                        description='Create your own icon font using only the icons you need, select from Font Awesome and other free libraries.',
                        url='http://fontello.com/',
                        raw='{"extended": "Create your own icon font using only the icons you need, select from Font Awesome and other free libraries.", "hash": "df25b37a14ed631a0111a647e53fc24e", "description": "Fontello - icon fonts generator", "tags": "fonts icons webdevelopment webdesign", "href": "http://fontello.com/", "meta": "20e8a3c17e9424c7fb6121d0c6961861", "time": "2015-06-18T09:48:31Z", "shared": "yes", "toread": "no"}',
                        fetch_time=fetch_time)

        bookmarks_from_json = self.get_bookmarks_from_json()
        bookmarks_data = bookmarks_from_json['bookmarks']

        BookmarksFetcher()._save_bookmarks(
                            account=account,
                            bookmarks_data=bookmarks_data,
                            fetch_time=fetch_time)

        self.assertEqual(Bookmark.objects.all().count(), 2)

        bookmarks = Bookmark.objects.all()

        # Nothing has changed, and so the fetch_time should be the original:
        self.assertEqual(bookmarks[0].fetch_time, fetch_time)
Esempio n. 32
0
 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'))
Esempio n. 33
0
 def test_tags_limit_default(self):
     "It should return 10 tags by default"
     bookmark = BookmarkFactory()
     bookmark.tags.set('1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
                       '11')
     tags = ditto_pinboard.popular_bookmark_tags()
     self.assertEqual(len(tags), 10)
Esempio n. 34
0
 def test_case_insensitive_tags(self):
     "Creating tags named 'dog' and 'DOG' should not create different slugs."
     bookmark = BookmarkFactory()
     bookmark.tags.set('dog', 'cat', 'DOG')
     self.assertEqual(sorted([tag.slug for tag in bookmark.tags.all()]), [
         'cat',
         'dog',
     ])
Esempio n. 35
0
 def test_empty_years(self):
     "It should include years for which there are no bookmarks."
     # Add a photo in 2018, leaving a gap for 2017:
     BookmarkFactory(post_time=datetime_from_str('2018-01-01 12:00:00'))
     bookmarks = ditto_pinboard.annual_bookmark_counts()
     self.assertEqual(len(bookmarks), 4)
     self.assertEqual(bookmarks[2]['year'], 2017)
     self.assertEqual(bookmarks[2]['count'], 0)
Esempio n. 36
0
 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])
Esempio n. 37
0
 def test_tags_private(self):
     "Doesn't fetch private tags"
     bookmark = BookmarkFactory()
     bookmark.tags.set('ispublic', '.isprivate', 'alsopublic')
     bookmark_reloaded = Bookmark.objects.get(pk=bookmark.pk)
     self.assertEqual(len(bookmark_reloaded.tags.all()), 2)
     self.assertEqual(bookmark_reloaded.tags.names().first(), 'alsopublic')
     self.assertEqual(bookmark_reloaded.tags.all()[0].name, 'alsopublic')
     self.assertEqual(bookmark_reloaded.tags.all()[1].name, 'ispublic')
Esempio n. 38
0
    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)
Esempio n. 39
0
 def test_bookmark_detail_fails(self):
     "Returns a 404 if a non-existent bookmark's page is requested"
     bookmark = BookmarkFactory()
     response = self.client.get(
         reverse('pinboard:bookmark_detail',
                 kwargs={
                     'username': bookmark.account.username,
                     'hash': '1234567890ab'
                 }))
     self.assertEquals(response.status_code, 404)
Esempio n. 40
0
 def test_bookmark_detail_privacy(self):
     "Does not display private bookmarks"
     bookmark = BookmarkFactory(is_private=True)
     response = self.client.get(
         reverse('pinboard:bookmark_detail',
                 kwargs={
                     'username': bookmark.account.username,
                     'hash': bookmark.url_hash
                 }))
     self.assertEquals(response.status_code, 404)
Esempio n. 41
0
    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))
Esempio n. 42
0
 def test_tag_detail_templates(self):
     "Uses the correct templates"
     bookmark = BookmarkFactory()
     bookmark.tags.set('fish')
     response = self.client.get(
         reverse('pinboard:tag_detail', kwargs={'slug': 'fish'}))
     self.assertEquals(response.status_code, 200)
     self.assertTemplateUsed(response, 'pinboard/tag_detail.html')
     self.assertTemplateUsed(response, 'pinboard/base.html')
     self.assertTemplateUsed(response, 'ditto/base.html')
Esempio n. 43
0
 def test_tags(self):
     "Can save and recall tags"
     bookmark = BookmarkFactory()
     bookmark.tags.set('banana', 'cherry', 'apple')
     bookmark_reloaded = Bookmark.objects.get(pk=bookmark.pk)
     self.assertEqual(len(bookmark_reloaded.tags.all()), 3)
     self.assertIsInstance(bookmark_reloaded.tags.first(), BookmarkTag)
     self.assertEqual(bookmark_reloaded.tags.names().first(), 'apple')
     self.assertEqual(bookmark_reloaded.tags.all()[0].name, 'apple')
     self.assertEqual(bookmark_reloaded.tags.all()[2].name, 'cherry')
Esempio n. 44
0
 def test_tags_privacy_tags(self):
     "Doesn't display private .tags"
     bookmark = BookmarkFactory()
     bookmark.tags.set('ispublic', '.notpublic', 'alsopublic')
     tags = ditto_pinboard.popular_bookmark_tags()
     self.assertEqual(len(tags), 2)
     # Tags are ordered by popularity, so can't be sure
     # which is 'alsopublic' and which is 'ispublic':
     tag_names = [tag.name for tag in tags]
     self.assertIn('alsopublic', tag_names)
     self.assertIn('ispublic', tag_names)
Esempio n. 45
0
 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]
     )
Esempio n. 46
0
    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)
Esempio n. 47
0
    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},
        ])
Esempio n. 48
0
class BookmarkNextPrevTestCase(TestCase):

    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_next_public_by_post_time(self):
        self.assertEqual(self.bookmark_1.get_next_public_by_post_time(),
                        self.bookmark_2)

    def test_next_public_by_post_time_none(self):
        self.assertIsNone(self.bookmark_2.get_next_public_by_post_time())

    def test_previous_public_by_post_time(self):
        self.assertEqual(self.bookmark_2.get_previous_public_by_post_time(),
                        self.bookmark_1)

    def test_previous_public_by_post_time_none(self):
        self.assertIsNone(self.bookmark_1.get_previous_public_by_post_time())

    def test_next(self):
        self.assertEqual(self.bookmark_1.get_next(),self.bookmark_2)

    def test_next_none(self):
        self.assertIsNone(self.bookmark_2.get_next())

    def test_previous(self):
        self.assertEqual(self.bookmark_2.get_previous(), self.bookmark_1)

    def test_previous_none(self):
        self.assertIsNone(self.bookmark_1.get_previous())
Esempio n. 49
0
 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)
Esempio n. 50
0
 def test_get_absolute_url(self):
     bookmark = BookmarkFactory(accountAccountFactory(username='******'),
                         url_hash='12345678abc')
     self.assertEqual(bookmark.get_absolute_url(),
                                             '/pinboard/bob/12345678abc/')
Esempio n. 51
0
 def test_slugs_match_tags_false(self):
     "Returns false if a list of slugs is different to bookmark's tags"
     bookmark = BookmarkFactory()
     bookmark.tags.set('banana', 'cherry')
     self.assertFalse(bookmark.slugs_match_tags(['banana', 'apple']))
Esempio n. 52
0
 def test_slugs_match_tags_true(self):
     "Returns true if a list of slugs is the same to bookmark's tags"
     bookmark = BookmarkFactory()
     bookmark.tags.set('banana', 'cherry')
     self.assertTrue(bookmark.slugs_match_tags(['cherry', 'banana']))