Example #1
0
 def setUp(self):
     super(AddRemoveReviewerTests, self).setUp()
     self.locale = locale(locale='es', save=True)
     self.user = user(save=True)
     self.locale.leaders.add(self.user)
     self.reviewer = user(save=True)
     self.client.login(username=self.user.username, password='******')
Example #2
0
    def setUp(self, switch_is_active):
        switch_is_active.return_value = True

        super(KarmaAPITests, self).setUp()

        try:
            self.mgr = KarmaManager()
            redis_client('karma').flushdb()
        except RedisError:
            raise SkipTest

        self.user1 = user(save=True)
        self.user2 = user(save=True)
        self.user3 = user(save=True)

        TestAction1(user=self.user1).save()
        TestAction2(user=self.user2).save()
        TestAction2(user=self.user2).save()
        TestAction1(user=self.user3).save()
        TestAction1(user=self.user3).save()
        TestAction1(user=self.user3).save()
        self.mgr.update_top()

        self.client.login(username=self.user1.username, password='******')
        add_permission(self.user1, models.Title, 'view_dashboard')
Example #3
0
 def setUp(self):
     super(AddRemoveLeaderTests, self).setUp()
     self.locale = locale(locale='es', save=True)
     self.user = user(save=True)
     add_permission(self.user, Locale, 'change_locale')
     self.leader = user(save=True)
     self.client.login(username=self.user.username, password='******')
Example #4
0
    def test_watch_thread_then_reply(self, get_current):
        """The event fires and sends emails when watching a thread."""
        get_current.return_value.domain = 'testserver'

        t = thread(save=True)
        f = t.forum
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_thread_as(t, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client,
             'forums.reply', {'content': 'a post'},
             args=[t.forum.slug, t.id])

        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0],
                 to=[watcher.email],
                 subject='Re: {f} - {t}'.format(f=f, t=t))
        body = REPLY_EMAIL.format(username=poster.username,
                                  forum_slug=f.slug,
                                  thread=t.title,
                                  thread_id=t.id,
                                  post_id=p.id)
        starts_with(mail.outbox[0].body, body)
Example #5
0
 def setUp(self):
     super(AddRemoveLeaderTests, self).setUp()
     self.user = user(save=True)
     add_permission(self.user, GroupProfile, 'change_groupprofile')
     self.leader = user(save=True)
     self.group_profile = group_profile(group=group(save=True), save=True)
     self.client.login(username=self.user.username, password='******')
    def test_watch_both_then_new_post(self, get_current):
        """Watching both forum and thread.

        Replying to a thread should send ONE email."""
        get_current.return_value.domain = 'testserver'

        t = thread(save=True)
        f = t.forum
        forum_post(thread=t, save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_forum_as(f, watcher, turn_on=True)
        self._toggle_watch_thread_as(t, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client, 'forums.reply', {'content': 'a post'},
             args=[f.slug, t.id])

        eq_(1, len(mail.outbox))
        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0], to=[watcher.email],
                 subject='Re: {f} - {t}'.format(f=f, t=t))
        body = REPLY_EMAIL.format(
            username=poster.username,
            forum_slug=f.slug,
            thread_title=t.title,
            thread_id=t.id,
            post_id=p.id)
        starts_with(mail.outbox[0].body, body)
Example #7
0
    def setUp(self, switch_is_active):
        switch_is_active.return_value = True

        super(KarmaManagerTests, self).setUp()

        try:
            self.mgr = KarmaManager()
            redis_client('karma').flushdb()
        except RedisError:
            raise SkipTest

        self.user1 = user(save=True)
        self.user2 = user(save=True)
        self.user3 = user(save=True)

        today = date.today()

        # user1 actions (3 + 3 + 7):
        TestAction1(user=self.user1, day=today).save()
        TestAction1(user=self.user1, day=today).save()
        TestAction2(user=self.user1, day=today).save()

        # user2 actions (3 + 7 + 7):
        TestAction1(user=self.user2, day=today - timedelta(days=8)).save()
        TestAction2(user=self.user2, day=today - timedelta(days=32)).save()
        TestAction2(user=self.user2, day=today - timedelta(days=360)).save()

        # user3 actions (3 + 3 + 3 + 7):
        TestAction1(user=self.user3, day=today - timedelta(days=10)).save()
        TestAction1(user=self.user3, day=today - timedelta(days=40)).save()
        TestAction1(user=self.user3, day=today - timedelta(days=190)).save()
        TestAction2(user=self.user3, day=today - timedelta(days=3)).save()
Example #8
0
 def test_sorting_creator(self):
     """Sorting threads by creator."""
     thread(creator=user(username='******', save=True), save=True)
     thread(creator=user(username='******', save=True), save=True)
     threads = sort_threads(Thread.objects, 3, 1)
     self.assert_(threads[0].creator.username >=
                  threads[1].creator.username)
Example #9
0
    def setUp(self, switch_is_active):
        switch_is_active.return_value = True

        super(KarmaManagerTests, self).setUp()

        try:
            self.mgr = KarmaManager()
            redis_client('karma').flushdb()
        except RedisError:
            raise SkipTest

        self.user1 = user(save=True)
        self.user2 = user(save=True)
        self.user3 = user(save=True)

        today = date.today()

        # user1 actions (3 + 3 + 7):
        TestAction1(user=self.user1, day=today).save()
        TestAction1(user=self.user1, day=today).save()
        TestAction2(user=self.user1, day=today).save()

        # user2 actions (3 + 7 + 7):
        TestAction1(user=self.user2, day=today - timedelta(days=8)).save()
        TestAction2(user=self.user2, day=today - timedelta(days=32)).save()
        TestAction2(user=self.user2, day=today - timedelta(days=360)).save()

        # user3 actions (3 + 3 + 3 + 7):
        TestAction1(user=self.user3, day=today - timedelta(days=10)).save()
        TestAction1(user=self.user3, day=today - timedelta(days=40)).save()
        TestAction1(user=self.user3, day=today - timedelta(days=190)).save()
        TestAction2(user=self.user3, day=today - timedelta(days=3)).save()
Example #10
0
 def test_for_user_not_in_group(self):
     """Checks the locale dashboard doesn't load for user not in group."""
     user(username='******', save=True)
     self.client.login(username='******', password='******')
     response = self.client.get(
         reverse('dashboards.group', args=[self.g.pk], locale='en-US'))
     eq_(404, response.status_code)
Example #11
0
    def test_watch_forum_then_new_thread(self, get_current):
        """Watching a forum and creating a new thread should send email."""
        get_current.return_value.domain = 'testserver'

        f = forum(save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_forum_as(f, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client,
             'forums.new_thread', {
                 'title': 'a title',
                 'content': 'a post'
             },
             args=[f.slug])

        t = Thread.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0],
                 to=[watcher.email],
                 subject='{f} - {t}'.format(f=f, t=t))
        body = NEW_THREAD_EMAIL.format(username=poster.username,
                                       forum_slug=f.slug,
                                       thread=t.title,
                                       thread_id=t.id)
        starts_with(mail.outbox[0].body, body)
Example #12
0
    def test_active_contributors(self):
        """Test active contributors API call."""
        # 2 en-US revisions by 2 contributors:
        r1 = revision(creator=user(save=True), save=True)
        r2 = revision(creator=user(save=True), save=True)
        # A translation with 2 contributors (translator + reviewer):
        d = document(parent=r1.document, locale='es', save=True)
        revision(document=d, reviewed=datetime.now(),
                 reviewer=r1.creator, creator=r2.creator, save=True)
        # 1 active support forum contributor:
        # A user with 10 answers
        u1 = user(save=True)
        for x in range(10):
            answer(save=True, creator=u1)
        # A user with 9 answers
        u2 = user(save=True)
        for x in range(9):
            answer(save=True, creator=u2)
        # A user with 1 answer
        u3 = user(save=True)
        answer(save=True, creator=u3)

        # An AoA reply (1 contributor):
        reply(save=True)

        r = self._get_api_result('kpi_active_contributors')
        eq_(r['objects'][0]['en_us'], 2)
        eq_(r['objects'][0]['non_en_us'], 2)
        eq_(r['objects'][0]['support_forum'], 1)
        eq_(r['objects'][0]['aoa'], 1)
Example #13
0
 def test_sorting_creator(self):
     """Sorting threads by creator."""
     thread(creator=user(username='******', save=True), save=True)
     thread(creator=user(username='******', save=True), save=True)
     threads = sort_threads(Thread.objects, 3, 1)
     self.assert_(
         threads[0].creator.username >= threads[1].creator.username)
Example #14
0
    def test_watch_both_then_new_post(self, get_current):
        """Watching both forum and thread.

        Replying to a thread should send ONE email."""
        get_current.return_value.domain = 'testserver'

        t = thread(save=True)
        f = t.forum
        forum_post(thread=t, save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_forum_as(f, watcher, turn_on=True)
        self._toggle_watch_thread_as(t, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client,
             'forums.reply', {'content': 'a post'},
             args=[f.slug, t.id])

        eq_(1, len(mail.outbox))
        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0],
                 to=[watcher.email],
                 subject='Re: {f} - {t}'.format(f=f, t=t))
        body = REPLY_EMAIL.format(username=poster.username,
                                  forum_slug=f.slug,
                                  thread=t.title,
                                  thread_id=t.id,
                                  post_id=p.id)
        starts_with(mail.outbox[0].body, body)
Example #15
0
 def test_for_user_not_in_group(self):
     """Checks the locale dashboard doesn't load for user not in group."""
     user(username='******', save=True)
     self.client.login(username='******', password='******')
     response = self.client.get(reverse('dashboards.group',
                                        args=[self.g.pk], locale='en-US'))
     eq_(404, response.status_code)
Example #16
0
    def test_active_answerers(self):
        """Test active answerers API call."""
        # A user with 10 answers
        u1 = user(save=True)
        for x in range(10):
            answer(save=True, creator=u1)

        # A user with 9 answers
        u2 = user(save=True)
        for x in range(9):
            answer(save=True, creator=u2)

        # A user with 1 answer
        u3 = user(save=True)
        answer(save=True, creator=u3)

        # There should be only one active contributor.
        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'kpi_active_answerers',
                              'api_name': 'v1'})

        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['contributors'], 1)
Example #17
0
    def setUp(self):
        """Have a user watch for revision approval. Log in."""
        self.ready_watcher = user(email='*****@*****.**', save=True)
        ReadyRevisionEvent.notify(self.ready_watcher)

        readyer = user(save=True)
        add_permission(readyer, Revision, 'mark_ready_for_l10n')
        self.client.login(username=readyer.username, password='******')
Example #18
0
 def setUp(self):
     super(AddRemoveContributorTests, self).setUp()
     self.user = user(save=True)
     self.contributor = user(save=True)
     add_permission(self.user, Document, 'change_document')
     self.client.login(username=self.user.username, password='******')
     self.revision = revision(save=True)
     self.document = self.revision.document
Example #19
0
    def setUp(self):
        """Have a user watch for revision approval. Log in."""
        self.ready_watcher = user(email='*****@*****.**', save=True)
        ReadyRevisionEvent.notify(self.ready_watcher)

        readyer = user(save=True)
        add_permission(readyer, Revision, 'mark_ready_for_l10n')
        self.client.login(username=readyer.username, password='******')
Example #20
0
 def setUp(self):
     super(AddRemoveContributorTests, self).setUp()
     self.user = user(save=True)
     self.contributor = user(save=True)
     add_permission(self.user, Document, 'change_document')
     self.client.login(username=self.user.username, password='******')
     self.revision = revision(save=True)
     self.document = self.revision.document
Example #21
0
 def setUp(self):
     """Have a user watch for revision approval. Log in."""
     self.approved_watcher = user(email='*****@*****.**', save=True)
     ApproveRevisionInLocaleEvent.notify(self.approved_watcher,
                                         locale='en-US')
     approver = user(save=True)
     add_permission(approver, Revision, 'review_revision')
     add_permission(approver, Revision, 'mark_ready_for_l10n')
     self.client.login(username=approver.username, password='******')
Example #22
0
 def test_sorting_creator(self):
     """Sorting threads by creator."""
     u1 = user(username='******', save=True)
     u2 = user(username='******', save=True)
     thread(creator=u1, save=True)
     thread(creator=u2, save=True)
     threads = sort_threads(Thread.objects, 3, 1)
     self.assertEqual(threads[0].creator.username, u1.username)
     self.assertEqual(threads[1].creator.username, u2.username)
Example #23
0
    def setUp(self):
        # create active and inactive users
        self.active_user = user(save=True,
                                username='******',
                                is_active=True)

        self.inactive_user = user(save=True,
                                  username='******',
                                  is_active=False)
Example #24
0
 def test_sorting_creator(self):
     """Sorting threads by creator."""
     u1 = user(username='******', save=True)
     u2 = user(username='******', save=True)
     thread(creator=u1, save=True)
     thread(creator=u2, save=True)
     threads = sort_threads(Thread.objects, 3, 1)
     self.assertEqual(threads[0].creator.username, u1.username)
     self.assertEqual(threads[1].creator.username, u2.username)
Example #25
0
 def setUp(self):
     """Have a user watch for revision approval. Log in."""
     self.approved_watcher = user(email='*****@*****.**', save=True)
     ApproveRevisionInLocaleEvent.notify(self.approved_watcher,
                                         locale='en-US')
     approver = user(save=True)
     add_permission(approver, Revision, 'review_revision')
     add_permission(approver, Revision, 'mark_ready_for_l10n')
     self.client.login(username=approver.username, password='******')
Example #26
0
 def test_two_approved_revision(self):
     u1 = user(save=True)
     r1 = revision(save=True, is_approved=True, creator=u1)
     d = r1.document
     u2 = user(save=True)
     revision(save=True, is_approved=True, creator=u2, document=d)
     d.contributors.clear()
     _init_contributors()
     assert u1 in d.contributors.all()
     assert u2 in d.contributors.all()
Example #27
0
 def setUp(self):
     super(ThreadPermissionsTests, self).setUp()
     self.doc = document(save=True)
     self.u = user(save=True)
     self.thread = thread(document=self.doc, creator=self.u, save=True)
     self.post = self.thread.new_post(creator=self.thread.creator,
                                      content='foo')
     # Login for testing 403s
     u2 = user(save=True)
     self.client.login(username=u2.username, password='******')
Example #28
0
    def setUp(self):
        super(FlaggedQueueTestCase, self).setUp()
        q = question(creator=user(save=True), save=True)
        self.answer = answer(question=q, creator=user(save=True), save=True)

        self.flagger = user(save=True)
        u = user(save=True)
        add_permission(u, FlaggedObject, 'can_moderate')

        self.client.login(username=u.username, password='******')
Example #29
0
 def setUp(self):
     super(ThreadPermissionsTests, self).setUp()
     self.doc = document(save=True)
     self.u = user(save=True)
     self.thread = thread(document=self.doc, creator=self.u, save=True)
     self.post = self.thread.new_post(creator=self.thread.creator,
                                      content='foo')
     # Login for testing 403s
     u2 = user(save=True)
     self.client.login(username=u2.username, password='******')
Example #30
0
    def setUp(self):
        super(FlaggedQueueTestCase, self).setUp()
        q = question(creator=user(save=True), save=True)
        self.answer = answer(question=q,
                             creator=user(save=True),
                             save=True)

        self.flagger = user(save=True)
        u = user(save=True)
        add_permission(u, FlaggedObject, 'can_moderate')

        self.client.login(username=u.username, password='******')
Example #31
0
    def test_watch_other_thread_then_reply(self):
        """Watching a different thread than the one we're replying to shouldn't
        notify."""
        u_b = user(username='******', save=True)
        _t = thread(save=True)
        self._toggle_watch_thread_as(u_b.username, _t, turn_on=True)
        u = user(save=True)
        t2 = thread(save=True)
        self.client.login(username=u.username, password='******')
        post(self.client, 'wiki.discuss.reply', {'content': 'a post'},
             args=[t2.document.slug, t2.id])

        assert not mail.outbox
Example #32
0
    def _setup_announcement(self, visible_dates=True):
        g = group(save=True)
        u1 = user(save=True)
        u2 = user(save=True)
        u1.groups.add(g)
        u2.groups.add(g)
        # Create profiles for these users
        profile(user=u1)
        profile(user=u2)
        self.user = u2

        return announcement(creator=u1, group=g, save=True,
                            visible_dates=visible_dates)
Example #33
0
    def test_watch_other_thread_then_reply(self):
        """Watching a different thread than the one we're replying to shouldn't
        notify."""
        t1 = thread(save=True)
        t2 = thread(save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_thread_as(t1, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client, 'forums.reply', {'content': 'a post'},
             args=[t2.forum.slug, t2.id])

        assert not mail.outbox
Example #34
0
    def _lock_workflow(self, doc, edit_url):
        """This is a big end to end feature test of document locking.

        This tests that when a user starts editing a page, it gets locked,
        users can steal locks, and that when a user submits the edit page, the
        lock is cleared.
        """
        _login = lambda u: self.client.login(username=u.username,
                                             password='******')
        assert_is_locked = lambda r: self.assertContains(
            r, 'id="unlock-button"')
        assert_not_locked = lambda r: self.assertNotContains(
            r, 'id="unlock-button"')

        u1 = user(save=True, password='******')
        u2 = user(save=True, password='******')

        # With u1, edit the document. No lock should be found.
        _login(u1)
        r = self.client.get(edit_url)
        # Now load it again, the page should not show as being locked (since u1 has the lock)
        r = self.client.get(edit_url)
        assert_not_locked(r)

        # With u2, edit the document. It should be locked.
        _login(u2)
        r = self.client.get(edit_url)
        assert_is_locked(r)
        # Simulate stealing the lock by clicking the button.
        _document_lock_steal(doc.id, u2.username)
        r = self.client.get(edit_url)
        assert_not_locked(r)

        # Now u1 should see the page as locked.
        _login(u1)
        r = self.client.get(edit_url)
        assert_is_locked(r)

        # Now u2 submits the page, clearing the held lock.
        _login(u2)
        r = self.client.post(edit_url)

        data = new_document_data()
        data.update({'title': doc.title, 'slug': doc.slug, 'form': 'doc'})
        self.client.post(edit_url, data)

        # And u1 should not see a lock warning.
        _login(u1)
        r = self.client.get(edit_url)
        assert_not_locked(r)
Example #35
0
 def test_flag_kbforum_post(self):
     u = user(save=True)
     t = thread(save=True)
     p = t.new_post(creator=u, content='foo')
     f = FlaggedObject(content_object=p, reason='spam', creator_id=u.id)
     f.save()
     # Make sure flagit queue page works
     u2 = user(save=True)
     add_permission(u2, FlaggedObject, 'can_moderate')
     self.client.login(username=u2.username, password='******')
     response = get(self.client, 'flagit.queue')
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(1, len(doc('#flagged-queue li')))
Example #36
0
 def test_based_on_approved(self):
     u1 = user()
     u1.save()
     r1 = revision(is_approved=False, creator=u1, is_ready_for_localization=False, save=True)
     u2 = user()
     u2.save()
     r2 = revision(
         document=r1.document, based_on=r1, is_approved=False, creator=u2, is_ready_for_localization=False, save=True
     )
     eq_(0, len(mail.outbox))
     self._review_revision(r=r2)
     eq_(3, len(mail.outbox))
     assert "has a new approved revision" in mail.outbox[0].subject
     assert "Your revision has been approved" in mail.outbox[1].subject
     assert "A revision you contributed to has" in mail.outbox[2].subject
Example #37
0
    def test_asked_by(self):
        """Check several author values, including test for (anon)"""
        author_vals = (
            ('DoesNotExist', 0),
            ('jsocol', 2),
            ('pcraciunoiu', 2),
        )

        # Set up all the question data---creats users, creates the
        # questions, shove it all in the index, then query it and see
        # what happens.
        for name, number in author_vals:
            u = user(username=name, save=True)
            for i in range(number):
                ques = question(title=u'audio', creator=u, save=True)
                ques.tags.add(u'desktop')
                ans = answer(question=ques, save=True)
                answervote(answer=ans, helpful=True, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 2, 'format': 'json'}

        for author, total in author_vals:
            qs.update({'asked_by': author})
            response = self.client.get(reverse('search'), qs)
            eq_(total, json.loads(response.content)['total'])
Example #38
0
 def setUp(self):
     super(PasswordResetTests, self).setUp()
     self.u = user(email="*****@*****.**", save=True)
     self.uidb36 = int_to_base36(self.u.id)
     self.token = default_token_generator.make_token(self.u)
     self.orig_debug = settings.DEBUG
     settings.DEBUG = True
Example #39
0
 def setUp(self):
     super(PasswordChangeTests, self).setUp()
     self.u = user(save=True)
     profile(user=self.u)
     self.url = reverse('users.pw_change')
     self.new_pw = 'fjdka387fvstrongpassword!'
     self.client.login(username=self.u.username, password='******')
Example #40
0
    def test_for_user_active(self, get_current):
        """Checks the locale dashboard loads for a user associated with it.
        """
        get_current.return_value.domain = 'testserver'
        # Create user/group and add user to group.
        u = user(username='******', save=True)
        u.groups.add(self.g)
        profile(user=u)
        # Create site-wide and group announcements and dashboard.
        announcement().save()
        content = 'stardate 12341'
        announcement(group=self.g, content=content).save()

        # Log in and check response.
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('dashboards.group',
                                           args=[self.g.pk]),
                                   follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        # The locale dash tab shows up.
        eq_(4, len(doc('#user-nav li')))
        # The locale dash tabs shows up and is active
        eq_(u'A group', doc('#user-nav li.selected').text())
        # The subtitle shows French.
        eq_(u'Deutsch', doc('article h2.subtitle').text())
        # The correct announcement shows up.
        self.assertContains(response, content)
Example #41
0
    def test_edit_post_moderator(self):
        """Editing post as a moderator works."""
        p = forum_post(save=True)
        t = p.thread
        f = t.forum

        # Create the moderator group, give it the edit permission
        # and add a moderator.
        moderator_group = group(save=True)
        ct = ContentType.objects.get_for_model(f)
        permission(codename='forums_forum.post_edit_forum',
                   content_type=ct,
                   object_id=f.id,
                   group=moderator_group,
                   save=True)
        moderator = user(save=True)
        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.uncached.get(pk=p.pk)
        eq_('More new content', edited_p.content)
Example #42
0
    def test_autowatch_reply(self, get_current):
        """Replying to a thread creates a watch."""
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = thread(save=True)
        t2 = thread(save=True)

        assert not NewPostEvent.is_notifying(u, t1)
        assert not NewPostEvent.is_notifying(u, t2)

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

        # If the poster has the forums_watch_after_reply setting set to True,
        # they will start watching threads they reply to.
        s = Setting.objects.create(user=u,
                                   name='forums_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'forums.reply', data, args=[t1.forum.slug, t1.pk])
        assert NewPostEvent.is_notifying(u, t1)

        # Setting forums_watch_after_reply back to False, now they shouldn't
        # start watching threads they reply to.
        s.value = 'False'
        s.save()
        post(self.client, 'forums.reply', data, args=[t2.forum.slug, t2.pk])
        assert not NewPostEvent.is_notifying(u, t2)
Example #43
0
    def test_filtered(self):
        """Make sure watches cull properly by additional filters."""
        # A watch with just the filter we're searching for:
        registered_user = user(email='*****@*****.**', save=True)
        exact_watch = watch(event_type=TYPE, user=registered_user, save=True)
        watch_filter(watch=exact_watch, name='color', value=1).save()

        # A watch with extra filters:
        extra_watch = watch(event_type=TYPE, email='*****@*****.**', save=True)
        watch_filter(watch=extra_watch, name='color', value=1).save()
        watch_filter(watch=extra_watch, name='flavor', value=2).save()

        # A watch with no row for the filter we're searching on:
        watch(event_type=TYPE, email='*****@*****.**').save()

        # A watch with a mismatching filter--shouldn't be found
        mismatch_watch = watch(event_type=TYPE,
                               email='*****@*****.**',
                               save=True)
        watch_filter(watch=mismatch_watch, name='color', value=3).save()

        self._emails_eq(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                        FilteredEvent(),
                        color=1)

        # Search on multiple filters to test joining the filters table twice.
        # We provide values that match for both filters, as [email protected]
        # suffices to test exclusion.
        self._emails_eq(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                        FilteredEvent(),
                        color=1,
                        flavor=2)
Example #44
0
    def test_asked_by(self):
        """Check several author values, including test for (anon)"""
        author_vals = (
            ('DoesNotExist', 0),
            ('jsocol', 2),
            ('pcraciunoiu', 2),
        )

        # Set up all the question data---creats users, creates the
        # questions, shove it all in the index, then query it and see
        # what happens.
        for name, number in author_vals:
            u = user(username=name, save=True)
            for i in range(number):
                ques = question(title=u'audio', creator=u, save=True)
                ques.tags.add(u'desktop')
                ans = answer(question=ques, save=True)
                answervote(answer=ans, helpful=True, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 2, 'format': 'json'}

        for author, total in author_vals:
            qs.update({'asked_by': author})
            response = self.client.get(reverse('search'), qs)
            eq_(total, json.loads(response.content)['total'])
Example #45
0
    def setUp(self):
        self.locale1 = locale(save=True, locale='es')

        self.u1 = user(save=True)
        self.u2 = user(save=True)
        self.u3 = user(save=True)

        self.u1.is_superuser = 1
        self.u1.save()

        self.locale1.leaders.add(self.u2)
        self.locale1.save()

        self.announcement = announcement(save=True, creator=self.u2,
            locale=self.locale1, content="Look at me!",
            show_after=datetime(2012, 01, 01, 0, 0, 0))
Example #46
0
    def test_filtered(self):
        """Make sure watches cull properly by additional filters."""
        # A watch with just the filter we're searching for:
        registered_user = user(email='*****@*****.**', save=True)
        exact_watch = watch(event_type=TYPE, user=registered_user, save=True)
        watch_filter(watch=exact_watch, name='color', value=1).save()

        # A watch with extra filters:
        extra_watch = watch(event_type=TYPE, email='*****@*****.**', save=True)
        watch_filter(watch=extra_watch, name='color', value=1).save()
        watch_filter(watch=extra_watch, name='flavor', value=2).save()

        # A watch with no row for the filter we're searching on:
        watch(event_type=TYPE, email='*****@*****.**').save()

        # A watch with a mismatching filter--shouldn't be found
        mismatch_watch = watch(event_type=TYPE, email='*****@*****.**',
                               save=True)
        watch_filter(watch=mismatch_watch, name='color', value=3).save()

        self._emails_eq(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                        FilteredEvent(), color=1)

        # Search on multiple filters to test joining the filters table twice.
        # We provide values that match for both filters, as [email protected]
        # suffices to test exclusion.
        self._emails_eq(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                        FilteredEvent(), color=1, flavor=2)
Example #47
0
    def test_for_user_active(self, get_current):
        """Checks the locale dashboard loads for a user associated with it."""
        get_current.return_value.domain = 'testserver'
        # Create user/group and add user to group.
        u = user(username='******', save=True)
        u.groups.add(self.g)
        profile(u).save()
        # Create site-wide and group announcements and dashboard.
        announcement().save()
        content = 'stardate 12341'
        announcement(group=self.g, content=content).save()

        # Log in and check response.
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('dashboards.group',
                                           args=[self.g.pk]), follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        # The locale dash tab shows up.
        eq_(4, len(doc('#doc-tabs li')))
        # The locale dash tabs shows up and is active
        eq_(u'A group', doc('#doc-tabs li.active').text())
        # The subtitle shows French.
        eq_(u'Deutsch', doc('#main h2.subtitle').text())
        # The correct announcement shows up.
        self.assertContains(response, content)
Example #48
0
    def test_post_ratelimit(self):
        """Verify that rate limiting kicks in after 4 threads or replies."""
        d = document(save=True)
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        # Create 2 threads:
        for i in range(2):
            response = post(self.client, 'wiki.discuss.new_thread',
                            {'title': 'Topic', 'content': 'hellooo'},
                            args=[d.slug])
            eq_(200, response.status_code)

        # Now 3 replies (only 2 should save):
        t = Thread.objects.all()[0]
        for i in range(3):
            response = post(self.client, 'wiki.discuss.reply',
                            {'content': 'hellooo'}, args=[d.slug, t.id])
            eq_(200, response.status_code)

        # And another thread that shouldn't save:
        response = post(self.client, 'wiki.discuss.new_thread',
                        {'title': 'Topic', 'content': 'hellooo'},
                        args=[d.slug])

        # We should only have 4 posts (each thread and reply creates a post).
        eq_(4, Post.objects.count())
Example #49
0
 def setUp(self):
     super(PasswordResetTests, self).setUp()
     self.u = user(email="*****@*****.**", save=True)
     self.uidb36 = int_to_base36(self.u.id)
     self.token = default_token_generator.make_token(self.u)
     self.orig_debug = settings.DEBUG
     settings.DEBUG = True
Example #50
0
 def test_no_perm_thread_delete(self):
     """User not in group cannot delete thread in any forum."""
     self.context['request'].user = user(save=True)
     assert not has_perm(self.context, 'forums_forum.thread_delete_forum',
                         self.forum_1)
     assert not has_perm(self.context, 'forums_forum.thread_delete_forum',
                         self.forum_2)
Example #51
0
 def setUp(self):
     super(PasswordChangeTests, self).setUp()
     self.u = user(save=True)
     profile(user=self.u)
     self.url = reverse('users.pw_change')
     self.new_pw = 'fjdka387fvstrongpassword!'
     self.client.login(username=self.u.username, password='******')
Example #52
0
 def test_no_perm_thread_delete(self):
     """User not in group cannot delete thread in any forum."""
     self.context['request'].user = user(save=True)
     assert not has_perm(self.context, 'forums_forum.thread_delete_forum',
                         self.forum_1)
     assert not has_perm(self.context, 'forums_forum.thread_delete_forum',
                         self.forum_2)