コード例 #1
0
ファイル: test_helpers.py プロジェクト: Andisutra80/kitsune
 def test_group_link_with_profile(self):
     g = GroupFactory()
     g.save()
     p = GroupProfile.objects.create(group=g, slug='foo')
     text = group_link(g)
     doc = pq(text)
     eq_(reverse('groups.profile', args=[p.slug]),
         doc('a')[0].attrib['href'])
     eq_(g.name, doc('a')[0].text)
コード例 #2
0
ファイル: test_templatetags.py プロジェクト: ziegeer/kitsune
 def test_group_link_with_profile(self):
     g = GroupFactory()
     g.save()
     p = GroupProfile.objects.create(group=g, slug='foo')
     text = group_link(g)
     doc = pq(text)
     eq_(reverse('groups.profile', args=[p.slug]),
         doc('a')[0].attrib['href'])
     eq_(g.name, doc('a')[0].text)
コード例 #3
0
ファイル: test_templatetags.py プロジェクト: zu83/kitsune
 def test_group_link_with_profile(self):
     g = GroupFactory()
     g.save()
     p = GroupProfile.objects.create(group=g, slug="foo")
     text = group_link(g)
     doc = pq(text)
     eq_(reverse("groups.profile", args=[p.slug]),
         doc("a")[0].attrib["href"])
     eq_(g.name, doc("a")[0].text)
コード例 #4
0
ファイル: test_templatetags.py プロジェクト: zu83/kitsune
 def test_group_avatar(self):
     g = GroupFactory()
     g.save()
     p = GroupProfile.objects.create(group=g, slug="foo")
     url = group_avatar(p)
     eq_(settings.STATIC_URL + settings.DEFAULT_AVATAR, url)
     p.avatar = Mock()
     p.avatar.url = "/foo/bar"
     url = group_avatar(p)
     eq_("/foo/bar", url)
コード例 #5
0
ファイル: test_helpers.py プロジェクト: Andisutra80/kitsune
 def test_group_avatar(self):
     g = GroupFactory()
     g.save()
     p = GroupProfile.objects.create(group=g, slug='foo')
     url = group_avatar(p)
     eq_(settings.STATIC_URL + settings.DEFAULT_AVATAR, url)
     p.avatar = Mock()
     p.avatar.url = '/foo/bar'
     url = group_avatar(p)
     eq_('/foo/bar', url)
コード例 #6
0
ファイル: test_tasks.py プロジェクト: ziegeer/kitsune
    def _setup_announcement(self, visible_dates=True):
        g = GroupFactory()
        u1 = UserFactory(groups=[g])
        u2 = UserFactory(groups=[g])
        self.user = u2

        return AnnouncementFactory(creator=u1, group=g, visible_dates=visible_dates)
コード例 #7
0
    def setUp(self):
        url = reverse('forums.threads', args=[u'test-forum'])
        self.context = {'request': RequestFactory().get(url)}

        self.group = GroupFactory()

        # Set up forum_1
        f = self.forum_1 = ForumFactory()
        ct = ContentType.objects.get_for_model(self.forum_1)
        permission_names = [
            'forums_forum.thread_edit_forum',
            'forums_forum.post_edit_forum',
            'forums_forum.post_delete_forum',
            'forums_forum.thread_delete_forum',
            'forums_forum.thread_sticky_forum',
            'forums_forum.thread_move_forum',
        ]
        for name in permission_names:
            PermissionFactory(codename=name,
                              content_type=ct,
                              object_id=f.id,
                              group=self.group)

        # Set up forum_2
        f = self.forum_2 = ForumFactory()
        PermissionFactory(codename='forums_forum.thread_move_forum',
                          content_type=ct,
                          object_id=f.id,
                          group=self.group)
コード例 #8
0
ファイル: test_views.py プロジェクト: yoyo2011/kitsune
    def test_new_contributor(self, get_current):
        """Verify that interested contributors are added to group."""
        get_current.return_value.domain = 'su.mo.com'
        group_name = 'Registered as contributor'
        GroupFactory(name=group_name)
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'foobar22',
            'interested': 'yes'
        }
        response = self.client.post(reverse('users.register', locale='en-US'),
                                    data,
                                    follow=True)
        eq_(200, response.status_code)
        u = User.objects.get(username='******')
        eq_(group_name, u.groups.all()[0].name)

        # Activate user and verify email is sent.
        key = RegistrationProfile.objects.all()[0].activation_key
        url = reverse('users.activate', args=[u.id, key])
        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)
        eq_(2, len(mail.outbox))
        assert mail.outbox[1].subject.find('Welcome to') == 0
        assert u.username in mail.outbox[1].body
コード例 #9
0
ファイル: test_views.py プロジェクト: MShaffar19/kitsune
    def test_move_thread(self):
        """Move a thread."""
        t = ThreadFactory()
        f = ForumFactory()
        u = UserFactory()
        g = GroupFactory()

        # Give the user permission to move threads between the two forums.
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename="forums_forum.thread_move_forum",
                          content_type=ct,
                          object_id=f.id,
                          group=g)
        PermissionFactory(
            codename="forums_forum.thread_move_forum",
            content_type=ct,
            object_id=t.forum.id,
            group=g,
        )
        g.user_set.add(u)

        self.client.login(username=u.username, password="******")
        response = post(self.client,
                        "forums.move_thread", {"forum": f.id},
                        args=[t.forum.slug, t.id])
        eq_(200, response.status_code)
        t = Thread.objects.get(pk=t.pk)
        eq_(f.id, t.forum.id)
コード例 #10
0
    def test_create_new_contributor(self, message_mock):
        """
        Test that a new contributor can be created through Firefox Accounts
        if is_contributor is True in session
        """
        GroupFactory(name=CONTRIBUTOR_GROUP)
        claims = {
            'email': '*****@*****.**',
            'uid': 'abc123',
            'avatar': 'http://example.com/avatar',
            'locale': 'en-US'
        }

        request_mock = Mock(spec=HttpRequest)
        request_mock.LANGUAGE_CODE = 'en'
        request_mock.session = {
            'is_contributor': True
        }
        self.backend.claims = claims
        self.backend.request = request_mock
        users = User.objects.all()
        eq_(users.count(), 0)
        self.backend.create_user(claims)
        users = User.objects.all()
        eq_(CONTRIBUTOR_GROUP, users[0].groups.all()[0].name)
        ok_('is_contributor' not in request_mock.session)
        message_mock.success.assert_called()
コード例 #11
0
ファイル: test_urls.py プロジェクト: ziegeer/kitsune
    def test_delete_post_belongs_to_thread_and_forum(self):
        # Delete post action - post belongs to thread and thread
        # belongs to forum.
        f = ForumFactory()
        t = ThreadFactory(forum=f)
        # Post belongs to a different forum and thread.
        p = PostFactory()
        u = p.author

        # Give the user the permission to delete posts.
        g = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename='forums_forum.post_delete_forum',
                          content_type=ct, object_id=p.thread.forum_id, group=g)
        PermissionFactory(codename='forums_forum.post_delete_forum',
                          content_type=ct, object_id=f.id, group=g)
        g.user_set.add(u)

        self.client.login(username=u.username, password='******')

        # Post isn't in the passed forum:
        r = get(self.client, 'forums.delete_post',
                args=[f.slug, p.thread.id, p.id])
        eq_(404, r.status_code)

        # Post isn't in the passed thread:
        r = get(self.client, 'forums.delete_post',
                args=[p.thread.forum.slug, t.id, p.id])
        eq_(404, r.status_code)
コード例 #12
0
    def test_edit_post_moderator(self):
        """Editing post as a moderator works."""
        p = PostFactory()
        t = p.thread
        f = t.forum

        # Create the moderator group, give it the edit permission
        # and add a moderator.
        moderator_group = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(
            codename="forums_forum.post_edit_forum",
            content_type=ct,
            object_id=f.id,
            group=moderator_group,
        )
        moderator = UserFactory()
        moderator_group.user_set.add(moderator)

        self.client.login(username=moderator.username, password="******")

        r = post(
            self.client,
            "forums.edit_post",
            {"content": "More new content"},
            args=[f.slug, t.id, p.id],
        )
        eq_(200, r.status_code)

        edited_p = Post.objects.get(pk=p.pk)
        eq_("More new content", edited_p.content)
コード例 #13
0
    def test_user_groups_change(self):
        group = GroupFactory()
        self.user.groups.add(group)

        self.assertIn(group.id, self.get_doc().group_ids)

        self.user.groups.remove(group)

        self.assertNotIn(group.id, self.get_doc().group_ids)
コード例 #14
0
ファイル: test_templatetags.py プロジェクト: zu83/kitsune
    def test_right_group_profile(self):
        """Make sure we get the right group profile."""
        g1 = GroupFactory(pk=100)
        g1.save()
        eq_(100, g1.pk)
        g2 = GroupFactory(pk=101)
        g2.save()
        eq_(101, g2.pk)
        p = GroupProfileFactory(pk=100, group=g2, slug="foo")
        eq_(100, p.pk)

        eq_(group_link(g1), g1.name)
コード例 #15
0
    def test_ga_custom_variable_on_admin_login(self):
        """After logging in, there should be a ga-push data attr on body."""
        user_ = UserFactory()

        # Add user to Administrators and so should be "Contributor - Admin":
        user_.groups.add(GroupFactory(name='Administrators'))
        response = self.client.post(reverse('users.login'), {
            'username': user_.username,
            'password': '******'
        },
                                    follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        assert '"Contributor - Admin"' in doc('body').attr('data-ga-push')
コード例 #16
0
ファイル: test_views.py プロジェクト: rootmeb/kitsune
    def test_edit_thread_moderator(self):
        """Editing post as a moderator works."""
        t = ThreadFactory()
        f = t.forum
        u = UserFactory()
        g = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename='forums_forum.thread_edit_forum', content_type=ct,
                          object_id=f.id, group=g)
        g.user_set.add(u)

        self.client.login(username=u.username, password='******')
        r = post(self.client, 'forums.edit_thread',
                 {'title': 'new title'}, args=[f.slug, t.id])
        eq_(200, r.status_code)
        edited_t = Thread.objects.get(id=t.id)
        eq_('new title', edited_t.title)
コード例 #17
0
ファイル: test_helpers.py プロジェクト: Andisutra80/kitsune
    def test_right_group_profile(self):
        """Make sure we get the right group profile."""
        g1 = GroupFactory(pk=100)
        g1.save()
        eq_(100, g1.pk)
        g2 = GroupFactory(pk=101)
        g2.save()
        eq_(101, g2.pk)
        p = GroupProfileFactory(pk=100, group=g2, slug='foo')
        eq_(100, p.pk)

        eq_(group_link(g1), g1.name)
コード例 #18
0
ファイル: test_urls.py プロジェクト: ziegeer/kitsune
    def test_delete_thread_belongs_to_forum(self):
        """Delete thread action - thread belongs to forum."""
        f = ForumFactory()
        t = ThreadFactory()  # Thread belongs to a different forum
        u = UserFactory()

        # Give the user the permission to delete threads.
        g = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename='forums_forum.thread_delete_forum',
                          content_type=ct, object_id=f.id, group=g)
        PermissionFactory(codename='forums_forum.thread_delete_forum',
                          content_type=ct, object_id=t.forum.id, group=g)
        g.user_set.add(u)

        self.client.login(username=u.username, password='******')
        r = get(self.client, 'forums.delete_thread', args=[f.slug, t.id])
        eq_(404, r.status_code)
コード例 #19
0
    def test_discussion_forum_with_restricted_forums(self):
        """Tests who can see restricted forums in search form."""
        # This is a long test, but it saves us from doing the setup
        # twice.
        forum1 = ForumFactory(name=u'ou812forum')
        thread1 = ThreadFactory(forum=forum1, title=u'audio 2')
        PostFactory(thread=thread1)

        forum2 = RestrictedForumFactory(name=u'restrictedkeepout')
        thread2 = ThreadFactory(forum=forum2, title=u'audio 2')
        PostFactory(thread=thread2)

        self.refresh()

        # Get the Advanced Search Form as an anonymous user
        response = self.client.get(reverse('search.advanced'), {'a': '2'})
        eq_(200, response.status_code)

        # Regular forum should show up
        assert 'ou812forum' in response.content

        # Restricted forum should not show up
        assert 'restrictedkeepout' not in response.content

        u = UserFactory()
        g = GroupFactory()
        g.user_set.add(u)
        ct = ContentType.objects.get_for_model(forum2)
        PermissionFactory(
            codename='forums_forum.view_in_forum',
            content_type=ct,
            object_id=forum2.id,
            group=g)

        # Get the Advanced Search Form as a logged in user
        self.client.login(username=u.username, password='******')
        response = self.client.get(reverse('search.advanced'), {'a': '2'})
        eq_(200, response.status_code)

        # Both forums should show up for authorized user
        assert 'ou812forum' in response.content
        assert 'restrictedkeepout' in response.content
コード例 #20
0
ファイル: test_urls.py プロジェクト: zu83/kitsune
    def test_sticky_thread_belongs_to_forum(self):
        """Sticky action - thread belongs to forum."""
        f = ForumFactory()
        t = ThreadFactory()  # Thread belongs to a different forum
        u = UserFactory()

        # Give the user the permission to sticky threads.
        g = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename="forums_forum.thread_sticky_forum",
                          content_type=ct,
                          object_id=f.id,
                          group=g)
        PermissionFactory(
            codename="forums_forum.thread_sticky_forum",
            content_type=ct,
            object_id=t.forum.id,
            group=g,
        )
        g.user_set.add(u)

        self.client.login(username=u.username, password="******")
        r = post(self.client, "forums.sticky_thread", {}, args=[f.slug, t.id])
        eq_(404, r.status_code)
コード例 #21
0
    def test_group_delete(self):
        group = GroupFactory()
        self.user.groups.add(group)
        group.delete()

        self.assertEqual(self.get_doc().group_ids, [])
コード例 #22
0
    def test_forums_search_authorized_forums_specifying_forums(self):
        """Only authorized people can search certain forums they specified"""
        # Create two threads: one in a restricted forum and one not.
        forum1 = ForumFactory(name=u'ou812forum')
        thread1 = ThreadFactory(forum=forum1)
        PostFactory(thread=thread1, content=u'audio')

        forum2 = RestrictedForumFactory(name=u'restrictedkeepout')
        thread2 = ThreadFactory(forum=forum2)
        PostFactory(thread=thread2, content=u'audio restricted')

        self.refresh()

        # Do a search as an anonymous user and specify both
        # forums. Should only see the post from the unrestricted
        # forum.
        response = self.client.get(reverse('search.advanced'), {
            'author': '',
            'created': '0',
            'created_date': '',
            'updated': '0',
            'updated_date': '',
            'sortby': '0',
            'forum': [forum1.id, forum2.id],
            'a': '1',
            'w': '4',
            'q': 'audio',
            'format': 'json'
        })

        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content['total'], 1)

        # Do a search as an authorized user and specify both
        # forums. Should see both posts.
        u = UserFactory()
        g = GroupFactory()
        g.user_set.add(u)
        ct = ContentType.objects.get_for_model(forum2)
        PermissionFactory(
            codename='forums_forum.view_in_forum',
            content_type=ct,
            object_id=forum2.id,
            group=g)

        self.client.login(username=u.username, password='******')
        response = self.client.get(reverse('search.advanced'), {
            'author': '',
            'created': '0',
            'created_date': '',
            'updated': '0',
            'updated_date': '',
            'sortby': '0',
            'forum': [forum1.id, forum2.id],
            'a': '1',
            'w': '4',
            'q': 'audio',
            'format': 'json'
        })

        # Sees both results
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content['total'], 2)
コード例 #23
0
ファイル: test_views.py プロジェクト: ziegeer/kitsune
 def setUp(self):
     super(JoinContributorsTests, self).setUp()
     self.user = UserFactory()
     self.client.login(username=self.user.username, password='******')
     GroupFactory(name='Contributors')
コード例 #24
0
ファイル: test_base.py プロジェクト: Shibetendo64/kitsune
 def setUp(self):
     self.profile = ProfileFactory()
     group = GroupFactory()
     self.profile.user.groups.add(group)
     self.prepare().save()
     self.profile.user.groups.remove(group)
コード例 #25
0
ファイル: test_search_advanced.py プロジェクト: zu83/kitsune
    def test_forums_search_authorized_forums_specifying_forums(self):
        """Only authorized people can search certain forums they specified"""
        # Create two threads: one in a restricted forum and one not.
        forum1 = ForumFactory(name="ou812forum")
        thread1 = ThreadFactory(forum=forum1)
        PostFactory(thread=thread1, content="audio")

        forum2 = RestrictedForumFactory(name="restrictedkeepout")
        thread2 = ThreadFactory(forum=forum2)
        PostFactory(thread=thread2, content="audio restricted")

        self.refresh()

        # Do a search as an anonymous user and specify both
        # forums. Should only see the post from the unrestricted
        # forum.
        response = self.client.get(
            reverse("search.advanced"),
            {
                "author": "",
                "created": "0",
                "created_date": "",
                "updated": "0",
                "updated_date": "",
                "sortby": "0",
                "forum": [forum1.id, forum2.id],
                "a": "1",
                "w": "4",
                "q": "audio",
                "format": "json",
            },
        )

        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content["total"], 1)

        # Do a search as an authorized user and specify both
        # forums. Should see both posts.
        u = UserFactory()
        g = GroupFactory()
        g.user_set.add(u)
        ct = ContentType.objects.get_for_model(forum2)
        PermissionFactory(codename="forums_forum.view_in_forum",
                          content_type=ct,
                          object_id=forum2.id,
                          group=g)

        self.client.login(username=u.username, password="******")
        response = self.client.get(
            reverse("search.advanced"),
            {
                "author": "",
                "created": "0",
                "created_date": "",
                "updated": "0",
                "updated_date": "",
                "sortby": "0",
                "forum": [forum1.id, forum2.id],
                "a": "1",
                "w": "4",
                "q": "audio",
                "format": "json",
            },
        )

        # Sees both results
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content["total"], 2)
コード例 #26
0
 def setUp(self):
     super(AnnouncementModelTests, self).setUp()
     self.creator = UserFactory()
     self.group = GroupFactory()
     self.locale = LocaleFactory(locale='es')
     self.creator.groups.add(self.group)
コード例 #27
0
ファイル: test_templatetags.py プロジェクト: zu83/kitsune
 def test_group_link_no_profile(self):
     g = GroupFactory()
     text = group_link(g)
     eq_(g.name, text)
コード例 #28
0
ファイル: test_views.py プロジェクト: ziegeer/kitsune
 def setUp(self):
     self.user = UserFactory()
     self.client.login(username=self.user.username, password='******')
     GroupFactory(name=CONTRIBUTOR_GROUP)
     super(MakeContributorTests, self).setUp()
コード例 #29
0
ファイル: test_templatetags.py プロジェクト: zu83/kitsune
 def setUp(self):
     super(KarmaTitleHelperTests, self).setUp()
     self.user = UserFactory()
     self.group = GroupFactory(name="group")
     self.user.groups.add(self.group)