Beispiel #1
0
    def test_new_short_thread_errors(self):
        """Posting a short new thread shows errors."""
        f = ForumFactory()
        u = UserFactory()

        self.client.login(username=u.username, password="******")
        response = post(
            self.client,
            "forums.new_thread",
            {
                "title": "wha?",
                "content": "wha?"
            },
            args=[f.slug],
        )

        doc = pq(response.content)
        errors = doc("ul.errorlist li a")
        eq_(
            errors[0].text,
            "Your title is too short (4 characters). " +
            "It must be at least 5 characters.",
        )
        eq_(
            errors[1].text,
            "Your message is too short (4 characters). " +
            "It must be at least 5 characters.",
        )
Beispiel #2
0
    def test_canonical_url(self):
        """Verify the canonical URL is set correctly."""
        f = forum(save=True)

        response = get(self.client, 'forums.threads', args=[f.slug])
        eq_('/forums/%s' % f.slug,
            pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
Beispiel #3
0
    def test_canonical_url(self):
        """Verify the canonical URL is set correctly."""
        f = ForumFactory()

        response = get(self.client, 'forums.threads', args=[f.slug])
        eq_('%s/en-US/forums/%s' % (settings.CANONICAL_URL, f.slug),
            pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
Beispiel #4
0
 def test_mobile_0(self):
     response = self.client.get(u'/en-US/?mobile=0')
     eq_(response.status_code, 200)
     eq_(self.client.cookies.get(mobility.middleware.COOKIE).value, 'off')
     # Make sure a mobile template was not used.
     doc = pq(response.content)
     eq_(len(doc('header.slide-on-exposed')), 0)
Beispiel #5
0
 def test_mobile_0(self):
     response = self.client.get(u"/en-US/?mobile=0")
     eq_(response.status_code, 200)
     eq_(self.client.cookies.get(mobility.middleware.COOKIE).value, "off")
     # Make sure a mobile template was not used.
     doc = pq(response.content)
     eq_(len(doc("#mobile-warning")), 1)
     eq_(len(doc("header.slide-on-exposed")), 0)
Beispiel #6
0
 def test_mobile_1(self):
     response = self.client.get(u'/en-US/?mobile=1', follow=True)
     eq_(response.status_code, 200)
     eq_(self.client.cookies.get(mobility.middleware.COOKIE).value, 'on')
     # Make sure a mobile template was used
     doc = pq(response.content)
     eq_(len(doc('#mobile-warning')), 0)
     eq_(len(doc('header.slide-on-exposed')), 1)
Beispiel #7
0
 def test_mobile_1(self):
     response = self.client.get(u'/en-US/?mobile=1', follow=True)
     eq_(response.status_code, 200)
     eq_(self.client.cookies.get(mobility.middleware.COOKIE).value, 'on')
     # Make sure a mobile template was used
     doc = pq(response.content)
     eq_(len(doc('#mobile-warning')), 0)
     eq_(len(doc('header.slide-on-exposed')), 1)
Beispiel #8
0
    def test_last_post_link_has_post_id(self):
        """Make sure the last post url links to the last post (#post-<id>)."""
        p = PostFactory()

        response = get(self.client, "forums.forums")
        doc = pq(response.content)
        last_post_link = doc(".forums .last-post a:not(.username)")[0]
        href = last_post_link.attrib["href"]
        eq_(href.split("#")[1], "post-%s" % p.id)
Beispiel #9
0
    def test_links_nofollow(self):
        """Links posted should have rel=nofollow."""
        p = PostFactory(content="linking http://test.org")
        t = p.thread
        f = t.forum

        response = get(self.client, "forums.posts", args=[f.slug, t.pk])
        doc = pq(response.content)
        eq_("nofollow", doc("ol.posts div.content a")[0].attrib["rel"])
Beispiel #10
0
    def test_long_title_truncated_in_crumbs(self):
        """A very long thread title gets truncated in the breadcrumbs"""
        t = ThreadFactory(title='A thread with a very very very very long title')
        PostFactory(thread=t)

        response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id])
        doc = pq(response.content)
        crumb = doc('#breadcrumbs li:last-child')
        eq_(crumb.text(), 'A thread with a very very very very...')
Beispiel #11
0
    def test_links_nofollow(self):
        """Links posted should have rel=nofollow."""
        p = forum_post(content='linking http://test.org', save=True)
        t = p.thread
        f = t.forum

        response = get(self.client, 'forums.posts', args=[f.slug, t.pk])
        doc = pq(response.content)
        eq_('nofollow', doc('ol.posts div.content a')[0].attrib['rel'])
Beispiel #12
0
    def test_posts_fr(self):
        """Posts render for [fr] locale."""
        t = ThreadFactory()

        response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id],
                       locale='fr')
        eq_(200, response.status_code)
        eq_('/forums/{f}/{t}'.format(f=t.forum.slug, t=t.id),
            pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
Beispiel #13
0
    def test_posts_fr(self):
        """Posts render for [fr] locale."""
        t = ThreadFactory()

        response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id],
                       locale='fr')
        eq_(200, response.status_code)
        eq_('{c}/fr/forums/{f}/{t}'.format(c=settings.CANONICAL_URL, f=t.forum.slug, t=t.id),
            pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
Beispiel #14
0
    def test_long_title_truncated_in_crumbs(self):
        """A very long thread title gets truncated in the breadcrumbs"""
        t = ThreadFactory(title='A thread with a very very very very long title')
        PostFactory(thread=t)

        response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id])
        doc = pq(response.content)
        crumb = doc('#breadcrumbs li:last-child')
        eq_(crumb.text(), 'A thread with a very very very very...')
Beispiel #15
0
    def test_links_nofollow(self):
        """Links posted should have rel=nofollow."""
        p = PostFactory(content='linking http://test.org')
        t = p.thread
        f = t.forum

        response = get(self.client, 'forums.posts', args=[f.slug, t.pk])
        doc = pq(response.content)
        eq_('nofollow', doc('ol.posts div.content a')[0].attrib['rel'])
Beispiel #16
0
    def test_canonical_url(self):
        """Verify the canonical URL is set correctly."""
        f = ForumFactory()

        response = get(self.client, "forums.threads", args=[f.slug])
        eq_(
            "%s/en-US/forums/%s" % (settings.CANONICAL_URL, f.slug),
            pq(response.content)('link[rel="canonical"]')[0].attrib["href"],
        )
Beispiel #17
0
    def test_display_order(self):
        """Verify the display_order is respected."""
        forum1 = forum(display_order=1, save=True)
        forum2 = forum(display_order=2, save=True)

        # forum1 should be listed first
        r = get(self.client, 'forums.forums')
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(forum1.name, doc('ol.forums > li a').first().text())

        forum1.display_order = 3
        forum1.save()

        # forum2 should be listed first
        r = get(self.client, 'forums.forums')
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(forum2.name, doc('ol.forums > li a').first().text())
Beispiel #18
0
    def test_last_post_link_has_post_id(self):
        """Make sure the last post url links to the last post (#post-<id>).
        """
        p = forum_post(save=True)

        response = get(self.client, 'forums.forums')
        doc = pq(response.content)
        last_post_link = doc('ol.forums div.last-post a:not(.username)')[0]
        href = last_post_link.attrib['href']
        eq_(href.split('#')[1], 'post-%s' % p.id)
Beispiel #19
0
    def test_last_thread_post_link_has_post_id(self):
        """Make sure the last post url links to the last post (#post-<id>)."""
        t = ThreadFactory()
        last = PostFactory(thread=t)

        response = get(self.client, "forums.threads", args=[t.forum.slug])
        doc = pq(response.content)
        last_post_link = doc(".threads .last-post a:not(.username)")[0]
        href = last_post_link.attrib["href"]
        eq_(href.split("#")[1], "post-%s" % last.id)
Beispiel #20
0
    def test_edit_thread_template(self):
        """The edit-thread template should render."""
        t = forum_post(save=True).thread
        creator = t.creator

        self.client.login(username=creator.username, password='******')
        res = get(self.client, 'forums.edit_thread', args=[t.forum.slug, t.id])

        doc = pq(res.content)
        eq_(len(doc('form.edit-thread')), 1)
Beispiel #21
0
    def test_display_order(self):
        """Verify the display_order is respected."""
        forum1 = ForumFactory(display_order=1)
        forum2 = ForumFactory(display_order=2)

        # forum1 should be listed first
        r = get(self.client, "forums.forums")
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(forum1.name, doc(".forums tr a").first().text())

        forum1.display_order = 3
        forum1.save()

        # forum2 should be listed first
        r = get(self.client, "forums.forums")
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(forum2.name, doc(".forums tr a").first().text())
Beispiel #22
0
    def test_edit_thread_template(self):
        """The edit-thread template should render."""
        t = ThreadFactory()
        creator = t.creator

        self.client.login(username=creator.username, password="******")
        res = get(self.client, "forums.edit_thread", args=[t.forum.slug, t.id])

        doc = pq(res.content)
        eq_(len(doc("form.edit-thread")), 1)
Beispiel #23
0
    def test_last_post_link_has_post_id(self):
        """Make sure the last post url links to the last post (#post-<id>).
        """
        p = PostFactory()

        response = get(self.client, 'forums.forums')
        doc = pq(response.content)
        last_post_link = doc('ol.forums div.last-post a:not(.username)')[0]
        href = last_post_link.attrib['href']
        eq_(href.split('#')[1], 'post-%s' % p.id)
Beispiel #24
0
    def test_display_order(self):
        """Verify the display_order is respected."""
        forum1 = ForumFactory(display_order=1)
        forum2 = ForumFactory(display_order=2)

        # forum1 should be listed first
        r = get(self.client, 'forums.forums')
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(forum1.name, doc('ol.forums > li a').first().text())

        forum1.display_order = 3
        forum1.save()

        # forum2 should be listed first
        r = get(self.client, 'forums.forums')
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(forum2.name, doc('ol.forums > li a').first().text())
Beispiel #25
0
    def test_posts_fr(self):
        """Posts render for [fr] locale."""
        t = ThreadFactory()

        response = get(self.client, "forums.posts", args=[t.forum.slug, t.id], locale="fr")
        eq_(200, response.status_code)
        eq_(
            "{c}/fr/forums/{f}/{t}".format(c=settings.CANONICAL_URL, f=t.forum.slug, t=t.id),
            pq(response.content)('link[rel="canonical"]')[0].attrib["href"],
        )
Beispiel #26
0
    def test_edit_thread_template(self):
        """The edit-post template should render."""
        p = PostFactory()
        u = p.author

        self.client.login(username=u.username, password="******")
        res = get(self.client, "forums.edit_post", args=[p.thread.forum.slug, p.thread.id, p.id],)

        doc = pq(res.content)
        eq_(len(doc("form.edit-post")), 1)
Beispiel #27
0
    def test_is_listed(self):
        """Verify is_listed is respected."""
        forum1 = forum(is_listed=True, save=True)
        forum2 = forum(is_listed=True, save=True)

        # Both forums should be listed.
        r = get(self.client, 'forums.forums')
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(2, len(doc('ol.forums > li')))

        forum1.is_listed = False
        forum1.save()

        # Only forum2 should be listed.
        r = get(self.client, 'forums.forums')
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(1, len(doc('ol.forums > li')))
        eq_(forum2.name, doc('ol.forums > li a').text())
Beispiel #28
0
    def test_last_thread_post_link_has_post_id(self):
        """Make sure the last post url links to the last post (#post-<id>).
        """
        t = forum_post(save=True).thread
        last = forum_post(thread=t, save=True)

        response = get(self.client, 'forums.threads', args=[t.forum.slug])
        doc = pq(response.content)
        last_post_link = doc('ol.threads div.last-post a:not(.username)')[0]
        href = last_post_link.attrib['href']
        eq_(href.split('#')[1], 'post-%s' % last.id)
Beispiel #29
0
    def test_is_listed(self):
        """Verify is_listed is respected."""
        forum1 = ForumFactory(is_listed=True)
        forum2 = ForumFactory(is_listed=True)

        # Both forums should be listed.
        r = get(self.client, "forums.forums")
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(2, len(doc(".forums tr")))

        forum1.is_listed = False
        forum1.save()

        # Only forum2 should be listed.
        r = get(self.client, "forums.forums")
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(1, len(doc(".forums tr")))
        eq_(forum2.name, doc(".forums tr a").text())
Beispiel #30
0
    def test_empty_reply_errors(self):
        """Posting an empty reply shows errors."""
        u = UserFactory()
        t = ThreadFactory()

        self.client.login(username=u.username, password="******")
        response = post(self.client, "forums.reply", {"content": ""}, args=[t.forum.slug, t.id])

        doc = pq(response.content)
        error_msg = doc("ul.errorlist li a")[0]
        eq_(error_msg.text, "Please provide a message.")
Beispiel #31
0
    def test_edit_thread_template(self):
        """The edit-post template should render."""
        p = PostFactory()
        u = p.author

        self.client.login(username=u.username, password='******')
        res = get(self.client, 'forums.edit_post',
                  args=[p.thread.forum.slug, p.thread.id, p.id])

        doc = pq(res.content)
        eq_(len(doc('form.edit-post')), 1)
Beispiel #32
0
    def test_edit_thread_template(self):
        """The edit-thread template should render."""
        t = ThreadFactory()
        creator = t.creator

        self.client.login(username=creator.username, password='******')
        res = get(self.client, 'forums.edit_thread',
                  args=[t.forum.slug, t.id])

        doc = pq(res.content)
        eq_(len(doc('form.edit-thread')), 1)
Beispiel #33
0
    def test_is_listed(self):
        """Verify is_listed is respected."""
        forum1 = ForumFactory(is_listed=True)
        forum2 = ForumFactory(is_listed=True)

        # Both forums should be listed.
        r = get(self.client, 'forums.forums')
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(2, len(doc('ol.forums > li')))

        forum1.is_listed = False
        forum1.save()

        # Only forum2 should be listed.
        r = get(self.client, 'forums.forums')
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(1, len(doc('ol.forums > li')))
        eq_(forum2.name, doc('ol.forums > li a').text())
Beispiel #34
0
    def test_last_thread_post_link_has_post_id(self):
        """Make sure the last post url links to the last post (#post-<id>).
        """
        t = ThreadFactory()
        last = PostFactory(thread=t)

        response = get(self.client, 'forums.threads', args=[t.forum.slug])
        doc = pq(response.content)
        last_post_link = doc('ol.threads div.last-post a:not(.username)')[0]
        href = last_post_link.attrib['href']
        eq_(href.split('#')[1], 'post-%s' % last.id)
Beispiel #35
0
    def test_empty_reply_errors(self):
        """Posting an empty reply shows errors."""
        u = UserFactory()
        t = ThreadFactory()

        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.reply', {'content': ''},
                        args=[t.forum.slug, t.id])

        doc = pq(response.content)
        error_msg = doc('ul.errorlist li a')[0]
        eq_(error_msg.text, 'Please provide a message.')
Beispiel #36
0
    def test_empty_thread_errors(self):
        """Posting an empty thread shows errors."""
        f = ForumFactory()
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.new_thread',
                        {'title': '', 'content': ''}, args=[f.slug])
        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text, 'Please provide a title.')
        eq_(errors[1].text, 'Please provide a message.')
Beispiel #37
0
    def test_edit_thread_template(self):
        """The edit-post template should render."""
        p = forum_post(save=True)
        u = p.author

        self.client.login(username=u.username, password='******')
        res = get(self.client,
                  'forums.edit_post',
                  args=[p.thread.forum.slug, p.thread.id, p.id])

        doc = pq(res.content)
        eq_(len(doc('form.edit-post')), 1)
Beispiel #38
0
    def test_empty_reply_errors(self):
        """Posting an empty reply shows errors."""
        u = UserFactory()
        t = ThreadFactory()

        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.reply', {'content': ''},
                        args=[t.forum.slug, t.id])

        doc = pq(response.content)
        error_msg = doc('ul.errorlist li a')[0]
        eq_(error_msg.text, 'Please provide a message.')
Beispiel #39
0
    def test_empty_thread_errors(self):
        """Posting an empty thread shows errors."""
        f = ForumFactory()
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.new_thread',
                        {'title': '', 'content': ''}, args=[f.slug])
        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text, 'Please provide a title.')
        eq_(errors[1].text, 'Please provide a message.')
Beispiel #40
0
    def test_empty_thread_errors(self):
        """Posting an empty thread shows errors."""
        f = ForumFactory()
        u = UserFactory()

        self.client.login(username=u.username, password="******")
        response = post(
            self.client, "forums.new_thread", {"title": "", "content": ""}, args=[f.slug],
        )
        doc = pq(response.content)
        errors = doc("ul.errorlist li a")
        eq_(errors[0].text, "Please provide a title.")
        eq_(errors[1].text, "Please provide a message.")
Beispiel #41
0
    def test_edit_thread_errors(self):
        """Editing thread with too short of a title shows errors."""
        t = ThreadFactory()
        creator = t.creator

        self.client.login(username=creator.username, password='******')
        response = post(self.client, 'forums.edit_thread',
                        {'title': 'wha?'}, args=[t.forum.slug, t.id])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text,
            'Your title is too short (4 characters). ' +
            'It must be at least 5 characters.')
Beispiel #42
0
    def test_preview_reply(self):
        """Preview a reply."""
        t = ThreadFactory()
        u = t.creator

        content = 'Full of awesome.'
        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.reply',
                        {'content': content, 'preview': 'any string'},
                        args=[t.forum.slug, t.id])
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(content, doc('#post-preview div.content').text())
        eq_(1, t.post_set.count())
Beispiel #43
0
    def test_preview_reply(self):
        """Preview a reply."""
        t = ThreadFactory()
        u = t.creator

        content = 'Full of awesome.'
        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.reply',
                        {'content': content, 'preview': 'any string'},
                        args=[t.forum.slug, t.id])
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(content, doc('#post-preview div.content').text())
        eq_(1, t.post_set.count())
Beispiel #44
0
    def test_edit_thread_errors(self):
        """Editing thread with too short of a title shows errors."""
        t = ThreadFactory()
        creator = t.creator

        self.client.login(username=creator.username, password='******')
        response = post(self.client, 'forums.edit_thread',
                        {'title': 'wha?'}, args=[t.forum.slug, t.id])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text,
            'Your title is too short (4 characters). ' +
            'It must be at least 5 characters.')
Beispiel #45
0
    def test_preview(self):
        """Preview the thread post."""
        f = ForumFactory()
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        content = 'Full of awesome.'
        response = post(self.client, 'forums.new_thread',
                        {'title': 'Topic', 'content': content,
                         'preview': 'any string'}, args=[f.slug])
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(content, doc('#post-preview div.content').text())
        eq_(0, f.thread_set.count())  # No thread was created.
Beispiel #46
0
    def test_preview(self):
        """Preview the thread post."""
        f = ForumFactory()
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        content = 'Full of awesome.'
        response = post(self.client, 'forums.new_thread',
                        {'title': 'Topic', 'content': content,
                         'preview': 'any string'}, args=[f.slug])
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(content, doc('#post-preview div.content').text())
        eq_(0, f.thread_set.count())  # No thread was created.
Beispiel #47
0
    def test_edit_post_errors(self):
        """Changing post content works."""
        p = PostFactory()
        t = p.thread
        u = p.author

        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.edit_post',
                        {'content': 'wha?'}, args=[t.forum.slug, t.id, p.id])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text,
            'Your message is too short (4 characters). ' +
            'It must be at least 5 characters.')
Beispiel #48
0
    def test_youtube_in_post(self):
        """Verify youtube video embedding."""
        u = UserFactory()
        t = ThreadFactory()

        self.client.login(username=u.username, password='******')
        response = post(
            self.client,
            'forums.reply',
            {'content': '[[V:http://www.youtube.com/watch?v=oHg5SJYRHA0]]'},
            args=[t.forum.slug, t.id])

        doc = pq(response.content)
        assert doc('iframe')[0].attrib['src'].startswith(
            '//www.youtube.com/embed/oHg5SJYRHA0')
Beispiel #49
0
    def test_youtube_in_post(self):
        """Verify youtube video embedding."""
        u = user(save=True)
        t = forum_post(save=True).thread

        self.client.login(username=u.username, password='******')
        response = post(
            self.client,
            'forums.reply',
            {'content': '[[V:http://www.youtube.com/watch?v=oHg5SJYRHA0]]'},
            args=[t.forum.slug, t.id])

        doc = pq(response.content)
        assert doc('iframe')[0].attrib['src'].startswith(
            '//www.youtube.com/embed/oHg5SJYRHA0')
Beispiel #50
0
    def test_new_short_thread_errors(self):
        """Posting a short new thread shows errors."""
        f = ForumFactory()
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.new_thread',
                        {'title': 'wha?', 'content': 'wha?'}, args=[f.slug])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text,
            'Your title is too short (4 characters). ' +
            'It must be at least 5 characters.')
        eq_(errors[1].text,
            'Your message is too short (4 characters). ' +
            'It must be at least 5 characters.')
Beispiel #51
0
 def test_canonical_url(self):
     response = get(self.client, 'forums.forums')
     eq_('/forums',
         pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
Beispiel #52
0
 def test_canonical_url(self):
     response = get(self.client, 'forums.forums')
     eq_('{}/en-US/forums'.format(settings.CANONICAL_URL),
         pq(response.content)('link[rel="canonical"]')[0].attrib['href'])