Exemplo n.º 1
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)
Exemplo n.º 2
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')
Exemplo n.º 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, 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'}))
Exemplo n.º 4
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'}))
Exemplo n.º 5
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)
Exemplo n.º 6
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()
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 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)")
Exemplo n.º 11
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)
Exemplo n.º 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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
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"}))
Exemplo n.º 21
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)
Exemplo n.º 22
0
 def test_lang(self):
     link = LinkFactory()
     link.author = self.user
     self.assertEqual(link.get_lang(), 'English')