예제 #1
0
파일: views_test.py 프로젝트: tom2288/resrc
    def test_new_link_ajax_view(self):
        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')

        resp = self.client.post(
            reverse('new-link'), {
                'title':
                'Building static websites with Middleman, deploying to Heroku',
                'url': 'http://12devs.co.uk/articles/204/',
                'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
                'ajax': '1',
                'id': 91329123,
            })
        self.assertEqual(resp.status_code, 404)

        alist = ListFactory()
        alist.owner = user
        alist.save()
        alist = List.objects.get(owner=user)
        link = Link.objects.get(url="http://12devs.co.uk/articles/204/")

        resp = self.client.post(
            reverse('new-link'), {
                'title':
                'Building static websites with Middleman, deploying to Heroku',
                'url': 'http://12devs.co.uk/articles/204/',
                'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
            })
        self.assertEqual(resp.status_code, 302)
예제 #2
0
    def test_new_link_ajax_view(self):
        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')

        resp = self.client.post(reverse('new-link'), {
            'title': 'Building static websites with Middleman, deploying to Heroku',
            'url': 'http://12devs.co.uk/articles/204/',
            'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
            'ajax': '1',
            'id': 91329123,
        })
        self.assertEqual(resp.status_code, 404)

        alist = ListFactory()
        alist.owner = user
        alist.save()
        alist = List.objects.get(owner=user)
        link = Link.objects.get(url="http://12devs.co.uk/articles/204/")

        resp = self.client.post(reverse('new-link'), {
            'title': 'Building static websites with Middleman, deploying to Heroku',
            'url': 'http://12devs.co.uk/articles/204/',
            'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
        })
        self.assertEqual(resp.status_code, 302)
예제 #3
0
파일: views_test.py 프로젝트: tom2288/resrc
    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)
예제 #4
0
파일: views_test.py 프로젝트: tom2288/resrc
    def test_new_link_invalid(self):
        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')

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

        resp = self.client.post(
            reverse('new-link'), {
                'url': 'http://12devs.co.uk/articles/204/',
                'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
            })

        self.assertEqual(resp.status_code, 200)

        resp = self.client.post(
            reverse('new-link'), {
                'url': 'http://12devs.co.uk/articles/204/',
                'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
                'ajax': '1'
            })

        self.assertEqual(resp.status_code, 200)
예제 #5
0
파일: views_test.py 프로젝트: tom2288/resrc
    def test_new_link_ajax_exists(self):
        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')

        alist = ListFactory()
        alist.owner = user
        alist.md_content = '#titre'
        alist.save()

        resp = self.client.post(
            reverse('new-link'), {
                'title':
                'Building static websites with Middleman, deploying to Heroku',
                'url': 'http://12devs.co.uk/articles/204/',
                'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
                'ajax': '1',
                'id': alist.pk,
            })

        resp = self.client.post(
            reverse('new-link'), {
                'title':
                'Building static websites with Middleman, deploying to Heroku',
                'url': 'http://12devs.co.uk/articles/204/',
                'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
            })
        self.assertEqual(resp.status_code, 302)
예제 #6
0
    def test_new_list_view(self):
        resp = self.client.get(reverse('new-list'))
        self.assertEqual(resp.status_code, 302)

        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')
        resp = self.client.get(reverse('new-list'))
        self.assertEqual(resp.status_code, 200)
예제 #7
0
파일: views_test.py 프로젝트: tom2288/resrc
    def test_new_link_view(self):
        resp = self.client.get(reverse('new-link'))
        self.assertEqual(resp.status_code, 302)

        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')
        resp = self.client.get(reverse('new-link'))
        self.assertEqual(resp.status_code, 200)
예제 #8
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)
예제 #9
0
    def test_gravatar_default(self):
        user = UserFactory()
        user.save()
        p = G(Profile, user=user)
        p.email = '*****@*****.**'
        p.save()
        self.assertEqual(gravatar(p.email), \
            '<img src="http://www.gravatar.com/avatar.php?size=80&gravatar_id=0d4907cea9d97688aa7a5e722d742f71" alt="gravatar" />')

        self.assertEqual(gravatar(p.email, 80, 'Hello'), \
            '<img src="http://www.gravatar.com/avatar.php?size=80&gravatar_id=0d4907cea9d97688aa7a5e722d742f71" alt="gravatar for Hello" />')
예제 #10
0
    def test_gravatar_default(self):
        user = UserFactory()
        user.save()
        p = G(Profile, user=user)
        p.email = '*****@*****.**'
        p.save()
        self.assertEqual(gravatar(p.email), \
            '<img src="http://www.gravatar.com/avatar.php?size=80&gravatar_id=0d4907cea9d97688aa7a5e722d742f71" alt="gravatar" />')

        self.assertEqual(gravatar(p.email, 80, 'Hello'), \
            '<img src="http://www.gravatar.com/avatar.php?size=80&gravatar_id=0d4907cea9d97688aa7a5e722d742f71" alt="gravatar for Hello" />')
예제 #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)
예제 #12
0
    def test_single_slug_view(self):
        alist = ListFactory()
        alist.save()
        resp = self.client.get(reverse('list-single-slug', kwargs={'list_pk': alist.pk, 'list_slug': alist.slug}))
        self.assertEqual(resp.status_code, 200)

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

        resp = self.client.get(reverse('list-single-slug', kwargs={'list_pk': alist.pk, 'list_slug': alist.slug + "x"}))
        self.assertEqual(resp.status_code, 404)
예제 #13
0
    def test_new_link_invalid(self):
        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')

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

        resp = self.client.post(reverse('new-link'), {
            'url': 'http://12devs.co.uk/articles/204/',
            'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
        })

        self.assertEqual(resp.status_code, 200)

        resp = self.client.post(reverse('new-link'), {
            'url': 'http://12devs.co.uk/articles/204/',
            'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
            'ajax': '1'
        })

        self.assertEqual(resp.status_code, 200)
예제 #14
0
    def test_new_link_ajax_exists(self):
        user = UserFactory()
        user.save()
        self.client.login(username=user.username, password='******')

        alist = ListFactory()
        alist.owner = user
        alist.md_content = '#titre'
        alist.save()

        resp = self.client.post(reverse('new-link'), {
            'title': 'Building static websites with Middleman, deploying to Heroku',
            'url': 'http://12devs.co.uk/articles/204/',
            'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
            'ajax': '1',
            'id': alist.pk,
        })

        resp = self.client.post(reverse('new-link'), {
            'title': 'Building static websites with Middleman, deploying to Heroku',
            'url': 'http://12devs.co.uk/articles/204/',
            'tags': 'Ruby, "Static Site Generator", "Ruby on Rails"',
        })
        self.assertEqual(resp.status_code, 302)
예제 #15
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'}))
예제 #16
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'}))