Beispiel #1
0
    def test_ajax_add_to_list_or_create(self):
        resp = self.client.get(reverse("ajax-add-to-list-or-create"))
        self.assertEqual(resp.content, json.dumps({"result": "fail"}))

        self.client.login(username=self.user.username, password="******")
        resp = self.client.get(reverse("ajax-add-to-list-or-create"))
        self.assertEqual(resp.content, json.dumps({"result": "fail"}))

        link = LinkFactory()
        link.author = self.user
        link.save()
        cache.delete("link_%s" % link.pk)
        alist = ListFactory()
        alist.owner = self.user
        alist.save()
        resp = self.client.post(reverse("ajax-add-to-list-or-create"), {"lk": link.pk, "ls": alist.pk})
        self.assertEqual(resp.content, json.dumps({"result": "added"}))

        resp = self.client.post(reverse("ajax-add-to-list-or-create"), {"lk": link.pk, "ls": alist.pk})
        self.assertEqual(resp.content, json.dumps({"result": "removed"}))

        resp = self.client.post(reverse("ajax-add-to-list-or-create"), {"lk": link.pk, "t": "toread"})
        self.assertEqual(resp.content, json.dumps({"result": "added"}))

        resp = self.client.post(reverse("ajax-add-to-list-or-create"), {"lk": link.pk, "t": "bookmark"})
        self.assertEqual(resp.content, json.dumps({"result": "added"}))

        resp = self.client.post(reverse("ajax-add-to-list-or-create"), {"lk": link.pk, "t": "something"})
        self.assertEqual(resp.status_code, 404)
Beispiel #2
0
    def test_edit_link_view(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        resp = self.client.get(reverse('link-edit', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 302)
        self.client.login(username=self.user2.username, password='******')
        resp = self.client.get(reverse('link-edit', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 404)
        self.client.login(username=self.user.username, password='******')
        resp = self.client.get(reverse('link-edit', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 200)

        resp = self.client.post(reverse('link-edit', kwargs={'link_pk': link.pk}), {
            'title': u'Building static websites with Middleman, deploying to Heroku',
            'url': 'http://12devs.co.uk/articles/204/',
            'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
            'language': 'en',
            'level': 'beginner'
        })
        self.assertEqual(resp.status_code, 302)

        resp = self.client.post(reverse('link-edit', kwargs={'link_pk': link.pk}), {
            'title': u'Building static websites with Middleman, deploying to Heroku',
            'url': 'http://12devs.co.uk/articles/204/',
            'tags': '"Static Site Generator", "Ruby on Rails"',
            'language': 'en',
            'level': 'beginner'
        })
        self.assertEqual(resp.status_code, 302)

        resp = self.client.post(reverse('link-edit', kwargs={'link_pk': link.pk}), {
            'title': u'Building static websites with Middleman, deploying to Heroku',
        })
        self.assertEqual(resp.status_code, 200)
Beispiel #3
0
    def test_ajax_create_list(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        cache.delete('link_%s' % link.pk)

        resp = self.client.get(reverse('ajax-create-list', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 403)

        self.client.login(username=self.user.username, password='******')
        resp = self.client.get(reverse('ajax-create-list', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 403)

        resp = self.client.post(reverse('ajax-create-list', kwargs={'link_pk': link.pk}), {
            'title': 'My list',
            'description': 'something',
            'private': True,
            'language': 'en'
        })
        self.assertEqual(resp.content, json.dumps({'result': 'success'}))

        resp = self.client.post(reverse('ajax-create-list', kwargs={'link_pk': link.pk}), {
            'title': 'My list',
            'description': 'something'
        })
        self.assertEqual(resp.content, json.dumps({'result': 'invalid'}))
Beispiel #4
0
    def test_get_tags(self):
        alist = ListFactory()
        alist.owner = self.user
        alist.save()

        link = LinkFactory()
        link.author = self.user
        link.save()
        self.assertEqual(link.get_categories(), "")

        link.tags.add('book')
        link.tags.add('article')
        link.tags.add('something')

        listlink = ListLinks.objects.create(
            alist=alist,
            links=link
        )
        listlink.add()

        self.assertEqual(alist.get_tags()[0], (u'article', u'article', 1))
        self.assertEqual(alist.get_tags()[1], (u'book', u'book', 1))
        self.assertEqual(alist.get_tags()[2], (u'something', u'something', 1))

        listlink.remove()
Beispiel #5
0
    def test_ajax_create_list(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        cache.delete('link_%s' % link.pk)

        resp = self.client.get(reverse('ajax-create-list', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 403)

        self.client.login(username=self.user.username, password='******')
        resp = self.client.get(reverse('ajax-create-list', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 403)

        resp = self.client.post(reverse('ajax-create-list', kwargs={'link_pk': link.pk}), {
            'title': 'My list',
            'description': 'something',
            'private': True,
            'language': 'en'
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'success'}))

        resp = self.client.post(reverse('ajax-create-list', kwargs={'link_pk': link.pk}), {
            'title': 'My list',
            'description': 'something'
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'invalid'}))
Beispiel #6
0
    def test_ajax_revise_link(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        resp = self.client.get(reverse('revise-link', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 403)
        self.client.login(username=self.user.username, password='******')
        resp = self.client.get(reverse('revise-link', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 403)

        resp = self.client.post(reverse('revise-link', kwargs={'link_pk': link.pk}), {
            'title': 'example',
            'url': 'http://example.com',
            'language': 'en',
            'level': 'beginner',
            'tags': 'Python'
        })
        self.assertEqual(resp.status_code, 200)

        resp = self.client.post(reverse('revise-link', kwargs={'link_pk': link.pk}), {
            'title': link.title,
            'url': link.url,
            'language': 'en',
            'level': 'beginner',
            'tags': 'Python'
        })
        self.assertEqual(resp.status_code, 200)
Beispiel #7
0
    def test_single_slug_view(self):
        link = LinkFactory()
        link.save()
        resp = self.client.get(
            reverse('link-single-slug',
                    kwargs={
                        'link_pk': link.pk,
                        'link_slug': link.slug
                    }))
        self.assertEqual(resp.status_code, 200)

        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')
        resp = self.client.get(
            reverse('link-single-slug',
                    kwargs={
                        'link_pk': link.pk,
                        'link_slug': link.slug
                    }))
        self.assertEqual(resp.status_code, 200)

        resp = self.client.get(
            reverse('link-single-slug',
                    kwargs={
                        'link_pk': link.pk,
                        'link_slug': link.slug + "x"
                    }))
        self.assertEqual(resp.status_code, 404)
Beispiel #8
0
 def test_single_view(self):
     link = LinkFactory()
     link.save()
     resp = self.client.get(
         reverse('link-single', kwargs={'link_pk': link.pk}))
     self.assertEqual(resp.status_code, 302)
     resp = self.client.get(reverse('link-single', kwargs={'link_pk': 77}))
     self.assertEqual(resp.status_code, 404)
Beispiel #9
0
 def test_single_view(self):
     link = LinkFactory()
     link.save()
     resp = self.client.get(
         reverse('link-single', kwargs={'link_pk': link.pk}))
     self.assertEqual(resp.status_code, 302)
     resp = self.client.get(reverse('link-single', kwargs={'link_pk': 77}))
     self.assertEqual(resp.status_code, 404)
Beispiel #10
0
    def test_categories(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        self.assertEqual(link.get_categories(), "")

        link.tags.add('book')
        link.tags.add('article')
        link.tags.add('something')
        self.assertEqual(link.get_categories(), "(book/article)")
Beispiel #11
0
 def test_ajax_own_lists(self):
     link = LinkFactory()
     link.save()
     link_pk = link.pk
     resp = self.client.get(reverse('ajax-own-lists', kwargs={'link_pk': link.pk}))
     self.assertEqual(resp.status_code, 404)
     user = UserFactory()
     user.save()
     self.client.login(username=user.username, password='******')
     resp = self.client.get(reverse('ajax-own-lists', kwargs={'link_pk': link.pk}))
     self.assertEqual(resp.status_code, 200)
Beispiel #12
0
    def test_ajax_own_list(self):
        link = LinkFactory()
        link.author = self.user
        link.save()

        resp = self.client.get(reverse('ajax-own-lists', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 403)

        self.client.login(username=self.user.username, password='******')
        resp = self.client.get(reverse('ajax-own-lists', kwargs={'link_pk': link.pk}))
        self.assertEqual(resp.status_code, 200)
Beispiel #13
0
    def test_ajax_own_list(self):
        link = LinkFactory()
        link.author = self.user
        link.save()

        resp = self.client.get(reverse("ajax-own-lists", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 403)

        self.client.login(username=self.user.username, password="******")
        resp = self.client.get(reverse("ajax-own-lists", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 200)
Beispiel #14
0
    def test_latest(self):
        link = LinkFactory()
        link.author = self.user
        link.title = 'A'
        link.save()
        link2 = LinkFactory()
        link.title = 'B'
        link2.author = self.user
        link2.save()

        self.assertEqual(Link.objects.latest(1, [1])[0]['title'],
            Link.objects.all()[0].title)
Beispiel #15
0
    def test_slug(self):
        """test link slug"""
        link = LinkFactory()
        link.save()
        self.assertEqual(link.do_unique_slug(), False)
        self.assertEqual(
            link.slug, 'single-page-simple-comprehensive-overview-of-javascript')

        link = LinkFactory()
        link.save()
        self.assertEqual(
            link.slug, 'single-page-simple-comprehensive-overview-of-javascript-1')
Beispiel #16
0
    def test_slug(self):
        """test link slug"""
        link = LinkFactory()
        link.author = self.user
        link.save()
        self.assertEqual(link.do_unique_slug(), False)
        self.assertEqual(
            link.slug, 'example-8')

        link = LinkFactory()
        link.author = self.user
        link.save()
        self.assertEqual(
            link.slug, 'example-9')
Beispiel #17
0
    def test_delete_link_from_list(self):
        alist = ListFactory()
        alist.save()

        link = LinkFactory()
        link.save()

        listlink = ListLinks.objects.create(alist=alist, links=link)
        listlink.save()
        self.assertTrue(
            listlink == ListLinks.objects.get(alist=alist, links=link))

        listlink.delete()
        with self.assertRaises(ListLinks.DoesNotExist):
            ListLinks.objects.get(alist=alist, links=link)
Beispiel #18
0
 def test_ajax_upvote_link(self):
     link = LinkFactory()
     link.author = self.user
     link.save()
     resp = self.client.get(reverse('link-upvote', kwargs={'link_pk': link.pk}))
     self.assertEqual(resp.status_code, 403)
     self.client.login(username=self.user.username, password='******')
     resp = self.client.get(reverse('link-upvote', kwargs={'link_pk': link.pk}))
     self.assertEqual(resp.status_code, 403)
     #vote
     resp = self.client.post(reverse('link-upvote', kwargs={'link_pk': link.pk}), {})
     self.assertEqual(resp.status_code, 200)
     #unvote
     resp = self.client.post(reverse('link-upvote', kwargs={'link_pk': link.pk}), {})
     self.assertEqual(resp.status_code, 200)
Beispiel #19
0
 def test_vote(self):
     """test link comment count"""
     link = LinkFactory()
     link.vote()
     link.save()
     self.assertEqual(link.upvotes, 1)
     from datetime import datetime
     hour = datetime.now().hour
     hours = {
         0: 'votes_h00', 1: 'votes_h00', 2: 'votes_h02', 3: 'votes_h02', 4: 'votes_h04',
         5: 'votes_h04', 6: 'votes_h06', 7: 'votes_h06', 8: 'votes_h08', 9: 'votes_h08',
         10: 'votes_h10', 11: 'votes_h10', 12: 'votes_h12', 13: 'votes_h12', 14: 'votes_h14',
         15: 'votes_h14', 16: 'votes_h16', 17: 'votes_h16', 18: 'votes_h18', 19: 'votes_h18',
         20: 'votes_h20', 21: 'votes_h20', 22: 'votes_h22', 23: 'votes_h22'}
     self.assertEqual(getattr(link, hours[hour]), 1)
Beispiel #20
0
 def test_ajax_upvote_link(self):
     link = LinkFactory()
     link.author = self.user
     link.save()
     resp = self.client.get(reverse("link-upvote", kwargs={"link_pk": link.pk}))
     self.assertEqual(resp.status_code, 403)
     self.client.login(username=self.user.username, password="******")
     resp = self.client.get(reverse("link-upvote", kwargs={"link_pk": link.pk}))
     self.assertEqual(resp.status_code, 403)
     # vote
     resp = self.client.post(reverse("link-upvote", kwargs={"link_pk": link.pk}), {})
     self.assertEqual(resp.status_code, 200)
     # unvote
     resp = self.client.post(reverse("link-upvote", kwargs={"link_pk": link.pk}), {})
     self.assertEqual(resp.status_code, 200)
Beispiel #21
0
    def test_vote(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        alist = ListFactory()
        alist.save()
        link.vote(self.user, alist.pk)

        link = LinkFactory()
        link.author = self.user2
        link.save()
        link.vote(self.user)

        link.unvote(self.user)
        self.assertEqual(self.profile.karma, 0)
        self.assertEqual(self.profile2.karma, 0)
Beispiel #22
0
    def test_single_slug_view(self):
        link = LinkFactory()
        link.save()
        resp = self.client.get(
            reverse('link-single-slug', kwargs={'link_pk': link.pk, 'link_slug': link.slug}))
        self.assertEqual(resp.status_code, 200)

        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')
        resp = self.client.get(
            reverse('link-single-slug', kwargs={'link_pk': link.pk, 'link_slug': link.slug}))
        self.assertEqual(resp.status_code, 200)

        resp = self.client.get(
            reverse('link-single-slug', kwargs={'link_pk': link.pk, 'link_slug': link.slug + "x"}))
        self.assertEqual(resp.status_code, 404)
Beispiel #23
0
    def test_get_tags(self):
        """test list tags"""
        alist = ListFactory()
        alist.save()
        self.assertEqual(list(alist.get_tags()), [])

        link = LinkFactory()
        link.save()

        tag = TagFactory()
        tag.save()

        link.tags.add(tag)
        link.save()

        listlink = ListLinks.objects.create(alist=alist, links=link)

        self.assertEqual(list(alist.get_tags()), [(u'Django', u'django', 1)])
Beispiel #24
0
    def test_delete_link_from_list(self):
        alist = ListFactory()
        alist.save()

        link = LinkFactory()
        link.save()

        listlink = ListLinks.objects.create(
            alist=alist,
            links=link
        )
        listlink.save()
        self.assertTrue(
            listlink == ListLinks.objects.get(alist=alist, links=link))

        listlink.delete()
        with self.assertRaises(ListLinks.DoesNotExist):
            ListLinks.objects.get(alist=alist, links=link)
Beispiel #25
0
    def test_ajax_add_to_list_or_create(self):
        resp = self.client.get(reverse('ajax-add-to-list-or-create'))
        self.assertEqual(resp.content, json.dumps({'result': 'fail'}))

        self.client.login(username=self.user.username, password='******')
        resp = self.client.get(reverse('ajax-add-to-list-or-create'))
        self.assertEqual(resp.content, json.dumps({'result': 'fail'}))

        link = LinkFactory()
        link.author = self.user
        link.save()
        cache.delete('link_%s' % link.pk)
        alist = ListFactory()
        alist.owner = self.user
        alist.save()
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': alist.pk
        })
        self.assertEqual(resp.content, json.dumps({'result': 'added'}))

        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': alist.pk
        })
        self.assertEqual(resp.content, json.dumps({'result': 'removed'}))

        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'toread'
        })
        self.assertEqual(resp.content, json.dumps({'result': 'added'}))

        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'bookmark'
        })
        self.assertEqual(resp.content, json.dumps({'result': 'added'}))

        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'something'
        })
        self.assertEqual(resp.status_code, 404)
Beispiel #26
0
    def test_ajax_add_to_list_or_create(self):
        resp = self.client.get(reverse('ajax-add-to-list-or-create'))
        self.assertEqual(resp.content, simplejson.dumps({'result': 'fail'}))

        self.client.login(username=self.user.username, password='******')
        resp = self.client.get(reverse('ajax-add-to-list-or-create'))
        self.assertEqual(resp.content, simplejson.dumps({'result': 'fail'}))

        link = LinkFactory()
        link.author = self.user
        link.save()
        cache.delete('link_%s' % link.pk)
        alist = ListFactory()
        alist.owner = self.user
        alist.save()
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': alist.pk
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': alist.pk
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'removed'}))

        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'toread'
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'bookmark'
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'something'
        })
        self.assertEqual(resp.status_code, 404)
Beispiel #27
0
    def test_personal_lists(self):
        a_personal_list = ListFactory()
        a_personal_list.save()
        a_default_list = ListFactory()
        a_default_list.title = "Bookmarks"
        a_default_list.save()

        link = LinkFactory()
        link.save()

        listlink = ListLinks.objects.create(alist=a_personal_list, links=link)
        listlink.save()

        listlink = ListLinks.objects.create(alist=a_default_list, links=link)
        listlink.save()

        self.assertEqual(
            list(List.objects.personal_lists(a_personal_list.owner)),
            [a_personal_list])
Beispiel #28
0
    def test_edit_link_view(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        resp = self.client.get(reverse("link-edit", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 302)
        self.client.login(username=self.user2.username, password="******")
        resp = self.client.get(reverse("link-edit", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 404)
        self.client.login(username=self.user.username, password="******")
        resp = self.client.get(reverse("link-edit", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 200)

        resp = self.client.post(
            reverse("link-edit", kwargs={"link_pk": link.pk}),
            {
                "title": u"Building static websites with Middleman, deploying to Heroku",
                "url": "http://12devs.co.uk/articles/204/",
                "tags": 'Ruby, "Static Site Generator", "Ruby on Rails"',
                "language": "en",
                "level": "beginner",
            },
        )
        self.assertEqual(resp.status_code, 302)

        resp = self.client.post(
            reverse("link-edit", kwargs={"link_pk": link.pk}),
            {
                "title": u"Building static websites with Middleman, deploying to Heroku",
                "url": "http://12devs.co.uk/articles/204/",
                "tags": '"Static Site Generator", "Ruby on Rails"',
                "language": "en",
                "level": "beginner",
            },
        )
        self.assertEqual(resp.status_code, 302)

        resp = self.client.post(
            reverse("link-edit", kwargs={"link_pk": link.pk}),
            {"title": u"Building static websites with Middleman, deploying to Heroku"},
        )
        self.assertEqual(resp.status_code, 200)
Beispiel #29
0
    def test_get_tags(self):
        """test list tags"""
        alist = ListFactory()
        alist.save()
        self.assertEqual(list(alist.get_tags()), [])

        link = LinkFactory()
        link.save()

        tag = TagFactory()
        tag.save()

        link.tags.add(tag)
        link.save()

        listlink = ListLinks.objects.create(
            alist=alist,
            links=link
        )

        self.assertEqual(list(alist.get_tags()), [(u'Django', u'django', 1)])
Beispiel #30
0
    def test_ajax_revise_link(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        resp = self.client.get(reverse("revise-link", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 403)
        self.client.login(username=self.user.username, password="******")
        resp = self.client.get(reverse("revise-link", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 403)

        resp = self.client.post(
            reverse("revise-link", kwargs={"link_pk": link.pk}),
            {"title": "example", "url": "http://example.com", "language": "en", "level": "beginner", "tags": "Python"},
        )
        self.assertEqual(resp.status_code, 200)

        resp = self.client.post(
            reverse("revise-link", kwargs={"link_pk": link.pk}),
            {"title": link.title, "url": link.url, "language": "en", "level": "beginner", "tags": "Python"},
        )
        self.assertEqual(resp.status_code, 200)
Beispiel #31
0
    def test_lists(self):
        readinglist = ListFactory()
        readinglist.title = "Reading list"
        readinglist.owner = self.user
        readinglist.save()

        alist = ListFactory()
        alist.owner = self.user
        alist.save()

        link = LinkFactory()
        link.author = self.user
        link.save()
        listlink = ListLinks.objects.create(
            alist=alist,
            links=link
        )
        listlink.add()

        self.assertEqual(List.objects.personal_lists(self.user)[0], alist)
        self.assertEqual(List.objects.my_list_titles(self.user, link.pk)[0], alist)
Beispiel #32
0
    def test_my_list_titles(self):
        a_personal_list = ListFactory()
        a_personal_list.save()
        a_default_list = ListFactory()
        a_default_list.title = "Bookmarks"
        a_default_list.save()

        link = LinkFactory()
        link.save()

        listlink = ListLinks.objects.create(alist=a_personal_list, links=link)
        listlink.save()

        listlink = ListLinks.objects.create(alist=a_default_list, links=link)
        listlink.save()

        self.assertEqual(
            list(
                List.objects.my_list_titles(a_personal_list.owner,
                                            link.pk).values_list('title',
                                                                 flat=True)),
            [a_personal_list.title])
Beispiel #33
0
    def test_ajax_create_list(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        cache.delete("link_%s" % link.pk)

        resp = self.client.get(reverse("ajax-create-list", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 403)

        self.client.login(username=self.user.username, password="******")
        resp = self.client.get(reverse("ajax-create-list", kwargs={"link_pk": link.pk}))
        self.assertEqual(resp.status_code, 403)

        resp = self.client.post(
            reverse("ajax-create-list", kwargs={"link_pk": link.pk}),
            {"title": "My list", "description": "something", "private": True, "language": "en"},
        )
        self.assertEqual(resp.content, json.dumps({"result": "success"}))

        resp = self.client.post(
            reverse("ajax-create-list", kwargs={"link_pk": link.pk}), {"title": "My list", "description": "something"}
        )
        self.assertEqual(resp.content, json.dumps({"result": "invalid"}))
Beispiel #34
0
    def test_search_view(self):
        link = LinkFactory()
        link.author = self.user
        link.save()
        resp = self.client.get(reverse('tags-search', kwargs={
            'tags': 'Ruby,Python',
            'operand': 'or',
            'excludes': ''
        }))
        resp = self.client.get(reverse('tags-search', kwargs={
            'tags': '',
            'operand': 'or',
            'excludes': ''
        }))
        self.assertEqual(resp.status_code, 200)

        self.client.login(username=self.user.username, password='******')
        resp = self.client.get(reverse('tags-search', kwargs={
            'tags': 'Ruby,Python',
            'operand': 'and',
            'excludes': ''
        }))
        self.assertEqual(resp.status_code, 200)
Beispiel #35
0
    def test_my_list_titles(self):
        a_personal_list = ListFactory()
        a_personal_list.save()
        a_default_list = ListFactory()
        a_default_list.title = "Bookmarks"
        a_default_list.save()

        link = LinkFactory()
        link.save()

        listlink = ListLinks.objects.create(
            alist=a_personal_list,
            links=link
        )
        listlink.save()

        listlink = ListLinks.objects.create(
            alist=a_default_list,
            links=link
        )
        listlink.save()

        self.assertEqual(
            list(List.objects.my_list_titles(a_personal_list.owner, link.pk).values_list('title', flat=True)), [a_personal_list.title])
Beispiel #36
0
    def test_user_lists(self):
        a_personal_list = ListFactory()
        a_personal_list.save()
        a_default_list = ListFactory()
        a_default_list.title = "Bookmarks"
        a_default_list.save()

        link = LinkFactory()
        link.save()

        listlink = ListLinks.objects.create(
            alist=a_personal_list,
            links=link
        )
        listlink.save()

        listlink = ListLinks.objects.create(
            alist=a_default_list,
            links=link
        )
        listlink.save()

        self.assertEqual(
            list(List.objects.user_lists(a_personal_list.owner, False)), [a_personal_list])
Beispiel #37
0
 def test_get_absolute_url(self):
     """test link absolute url"""
     link = LinkFactory()
     link.save()
     self.assertEqual(
         link.get_absolute_url(), '/lk/1/single-page-simple-comprehensive-overview-of-javascript/')
Beispiel #38
0
 def test_hash(self):
     """test link hash"""
     link = LinkFactory()
     link.save()
     self.assertEqual(link.hash2, '2i1kc0y52iw')
Beispiel #39
0
 def test_get_comment_count(self):
     """test link comment count"""
     link = LinkFactory()
     link.save()
     self.assertEqual(link.get_comment_count(), 0)
Beispiel #40
0
 def test_model(self):
     """test link model exists"""
     link = LinkFactory()
     link.save()
     self.assertTrue(link.pk)
Beispiel #41
0
    def test_ajax_add_to_list_or_create(self):
        import simplejson
        resp = self.client.get(reverse('ajax-add-to-list-or-create'))
        # not authenticated
        self.assertEqual(resp.content, simplejson.dumps({'result': 'fail'}))
        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')

        # authenticated but no post data
        resp = self.client.get(reverse('ajax-add-to-list-or-create'))
        self.assertEqual(resp.content, simplejson.dumps({'result': 'fail'}))

        link = LinkFactory()
        link.save()
        link2 = LinkFactory()
        link2.title = 'new link'
        link2.save()

        # authenticated and posting fake content
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'haxx0r',
        })
        self.assertEqual(resp.status_code, 404)

        # authenticated and adding link to default nonexistant bookmark list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'bookmark',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))


        # authenticated and adding link to default existing bookmark list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link2.pk,
            't': 'bookmark',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        # authenticated and adding link to default nonexistant reading list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'toread',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        # authenticated and adding link to default existing reading list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link2.pk,
            't': 'toread',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        # authenticated and removing link from default existing reading list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link2.pk,
            't': 'toread',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'removed'}))

        # authenticated and adding/remove link to un/existing own list list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': 43212234
        })
        self.assertEqual(resp.status_code, 404)

        alist = ListFactory()
        alist.save()
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': alist.pk
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': alist.pk
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'removed'}))
Beispiel #42
0
    def test_ajax_add_to_list_or_create(self):
        import simplejson
        resp = self.client.get(reverse('ajax-add-to-list-or-create'))
        # not authenticated
        self.assertEqual(resp.content, simplejson.dumps({'result': 'fail'}))
        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')

        # authenticated but no post data
        resp = self.client.get(reverse('ajax-add-to-list-or-create'))
        self.assertEqual(resp.content, simplejson.dumps({'result': 'fail'}))

        link = LinkFactory()
        link.save()
        link2 = LinkFactory()
        link2.title = 'new link'
        link2.save()

        # authenticated and posting fake content
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'haxx0r',
        })
        self.assertEqual(resp.status_code, 404)

        # authenticated and adding link to default nonexistant bookmark list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'bookmark',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        # authenticated and adding link to default existing bookmark list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link2.pk,
            't': 'bookmark',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        # authenticated and adding link to default nonexistant reading list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            't': 'toread',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        # authenticated and adding link to default existing reading list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link2.pk,
            't': 'toread',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))

        # authenticated and removing link from default existing reading list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link2.pk,
            't': 'toread',
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'removed'}))

        # authenticated and adding/remove link to un/existing own list list
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': 43212234
        })
        self.assertEqual(resp.status_code, 404)

        alist = ListFactory()
        alist.save()
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': alist.pk
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'added'}))
        resp = self.client.post(reverse('ajax-add-to-list-or-create'), {
            'lk': link.pk,
            'ls': alist.pk
        })
        self.assertEqual(resp.content, simplejson.dumps({'result': 'removed'}))