Exemplo n.º 1
0
    def test_it_works(self):
        u1 = profile().user
        u2 = profile().user

        r1 = revision(creator=u1, save=True)  # noqa
        r2 = revision(creator=u1, save=True)
        r3 = revision(creator=u2, save=True)

        r2.reviewer = u2
        r2.save()

        self.refresh()

        req = self.factory.get('/')
        data = self.api.get_data(req)

        eq_(data['count'], 2)

        eq_(data['results'][0]['user']['username'], u1.username)
        eq_(data['results'][0]['rank'], 1)
        eq_(data['results'][0]['revision_count'], 2)
        eq_(data['results'][0]['review_count'], 0)
        eq_(data['results'][0]['last_contribution_date'], r2.created.replace(microsecond=0))

        eq_(data['results'][1]['user']['username'], u2.username)
        eq_(data['results'][1]['rank'], 2)
        eq_(data['results'][1]['revision_count'], 1)
        eq_(data['results'][1]['review_count'], 1)
        eq_(data['results'][1]['last_contribution_date'], r3.created.replace(microsecond=0))
Exemplo n.º 2
0
    def test_answer_welcome_email(self):
        u1 = profile().user
        u2 = profile(first_answer_email_sent=True).user
        u3 = profile().user

        two_days = datetime.now() - timedelta(hours=48)

        q = question(creator=u1, save=True)
        answer(question=q, creator=u1, created=two_days, save=True)
        answer(question=q, creator=u2, created=two_days, save=True)
        answer(question=q, creator=u3, created=two_days, save=True)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u3 only.
        # u1 was the asker, and so did not make a contribution.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u3.email])

        # u3's flag should now be set.
        u3 = User.objects.get(id=u3.id)
        eq_(u3.profile.first_answer_email_sent, True)
Exemplo n.º 3
0
    def test_top_contributors_kb(self):
        d = document(locale='en-US', save=True)
        r1 = revision(document=d, save=True)
        r2 = revision(document=d, creator=r1.creator, save=True)
        r3 = revision(document=d, save=True)
        r4 = revision(document=d,
                      created=date.today() - timedelta(days=91),
                      save=True)

        for u in User.objects.all():
            profile(user=u)

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top, _ = top_contributors_kb()
        eq_(2, len(top))
        assert r4.creator_id not in [u['term'] for u in top]
        eq_(r1.creator_id, top[0]['term'])

        # If we specify an older start, then we get all 3.
        top, _ = top_contributors_kb(start=date.today() - timedelta(days=92))
        eq_(3, len(top))

        # If we also specify an older end date, we only get the creator for
        # the older revision.
        top, _ = top_contributors_kb(start=date.today() - timedelta(days=92),
                                     end=date.today() - timedelta(days=1))
        eq_(1, len(top))
        eq_(r4.creator_id, top[0]['term'])
Exemplo n.º 4
0
 def setUp(self):
     super(AnnouncementModelTests, self).setUp()
     self.creator = user(save=True)
     profile(user=self.creator)
     self.group = group(save=True)
     self.locale = locale(locale='es', save=True)
     self.creator.groups.add(self.group)
Exemplo n.º 5
0
 def setUp(self):
     super(AnnouncementModelTests, self).setUp()
     self.creator = user(save=True)
     profile(user=self.creator)
     self.group = group(save=True)
     self.locale = locale(locale='es', save=True)
     self.creator.groups.add(self.group)
Exemplo n.º 6
0
    def test_it_works(self):
        u1 = profile().user
        u2 = profile().user

        a1 = answer(creator=u1, save=True)  # noqa
        a2 = answer(creator=u1, save=True)
        a3 = answer(creator=u2, save=True)

        a1.question.solution = a1
        a1.question.save()
        answervote(answer=a3, helpful=True, save=True)

        self.refresh()

        req = self.factory.get('/')
        data = self.api.get_data(req)

        eq_(data['count'], 2)

        eq_(data['results'][0]['user']['username'], u1.username)
        eq_(data['results'][0]['rank'], 1)
        eq_(data['results'][0]['answer_count'], 2)
        eq_(data['results'][0]['solution_count'], 1)
        eq_(data['results'][0]['helpful_vote_count'], 0)
        eq_(data['results'][0]['last_contribution_date'], a2.created.replace(microsecond=0))

        eq_(data['results'][1]['user']['username'], u2.username)
        eq_(data['results'][1]['rank'], 2)
        eq_(data['results'][1]['answer_count'], 1)
        eq_(data['results'][1]['solution_count'], 0)
        eq_(data['results'][1]['helpful_vote_count'], 1)
        eq_(data['results'][1]['last_contribution_date'], a3.created.replace(microsecond=0))
Exemplo n.º 7
0
    def test_top_contributors(self):
        """Verify the top contributors appear."""
        d = document(locale='en-US', save=True)
        revision(document=d, save=True)
        d = document(locale='es', save=True)
        revision(document=d, save=True)
        revision(document=d, save=True)
        answer(save=True)
        answer(save=True)
        answer(save=True)
        reply(user=user(save=True), save=True)
        reply(user=user(save=True), save=True)
        reply(user=user(save=True), save=True)
        reply(user=user(save=True), save=True)

        for u in User.objects.all():
            profile(user=u)

        self.refresh()

        response = self.client.get(urlparams(reverse('community.home')))
        eq_(response.status_code, 200)
        doc = pq(response.content)
        eq_(1, len(doc('ul.kb > li')))
        eq_(2, len(doc('ul.l10n > li')))
        eq_(3, len(doc('ul.questions > li')))
        eq_(4, len(doc('ul.army-of-awesome > li')))
Exemplo n.º 8
0
    def test_correct_fields(self):
        follower = profile()
        followed = profile()
        q = question(creator=followed.user, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()
        follow(follower.user, followed.user)

        # Make a new action for the above. This should trigger notifications
        action.send(followed.user, verb='asked', action_object=q)
        act = Action.objects.order_by('-id')[0]
        notification = Notification.objects.get(action=act)

        serializer = api.NotificationSerializer(instance=notification)

        eq_(serializer.data['is_read'], False)
        eq_(
            serializer.data['actor'], {
                'type': 'user',
                'username': followed.user.username,
                'display_name': followed.name
            })
        eq_(serializer.data['verb'], 'asked')
        eq_(serializer.data['action_object'], {
            'type': 'question',
            'id': q.id,
        })
        eq_(serializer.data['target'], None)
        eq_(type(serializer.data['timestamp']), datetime)
Exemplo n.º 9
0
    def test_it_works(self):
        u1 = profile().user
        u2 = profile().user

        a1 = answer(creator=u1, save=True)  # noqa
        a2 = answer(creator=u1, save=True)
        a3 = answer(creator=u2, save=True)

        a1.question.solution = a1
        a1.question.save()
        answervote(answer=a3, helpful=True, save=True)

        self.refresh()

        req = self.factory.get('/')
        data = self.api.get_data(req)

        eq_(data['count'], 2)

        eq_(data['results'][0]['user']['username'], u1.username)
        eq_(data['results'][0]['rank'], 1)
        eq_(data['results'][0]['answer_count'], 2)
        eq_(data['results'][0]['solution_count'], 1)
        eq_(data['results'][0]['helpful_vote_count'], 0)
        eq_(data['results'][0]['last_contribution_date'],
            a2.created.replace(microsecond=0))

        eq_(data['results'][1]['user']['username'], u2.username)
        eq_(data['results'][1]['rank'], 2)
        eq_(data['results'][1]['answer_count'], 1)
        eq_(data['results'][1]['solution_count'], 0)
        eq_(data['results'][1]['helpful_vote_count'], 1)
        eq_(data['results'][1]['last_contribution_date'],
            a3.created.replace(microsecond=0))
Exemplo n.º 10
0
    def test_top_contributors_questions(self):
        firefox = product(slug='firefox', save=True)
        fxos = product(slug='firefox-os', save=True)
        a1 = answer(save=True)
        a1.question.products.add(firefox)
        a1.question.products.add(fxos)
        a2 = answer(creator=a1.creator, save=True)
        a3 = answer(save=True)
        a3.question.products.add(fxos)
        a4 = answer(created=datetime.now()-timedelta(days=91),
                    save=True)
        answer(creator=a4.question.creator, question=a4.question, save=True)

        for u in User.objects.all():
            profile(user=u)

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top = top_contributors_questions()
        eq_(2, len(top))
        assert a4.creator_id not in [u['term'] for u in top]
        eq_(a1.creator_id, top[0]['term'])

        # Verify, filtering of Firefox questions only.
        top = top_contributors_questions(product=firefox.slug)
        eq_(1, len(top))
        eq_(a1.creator_id, top[0]['term'])
        top = top_contributors_questions(product=fxos.slug)
        eq_(2, len(top))
Exemplo n.º 11
0
    def test_it_works(self):
        u1 = profile().user
        u2 = profile().user

        r1 = revision(creator=u1, save=True)  # noqa
        r2 = revision(creator=u1, save=True)
        r3 = revision(creator=u2, save=True)

        r2.reviewer = u2
        r2.save()

        self.refresh()

        req = self.factory.get('/')
        data = self.api.get_data(req)

        eq_(data['count'], 2)

        eq_(data['results'][0]['user']['username'], u1.username)
        eq_(data['results'][0]['rank'], 1)
        eq_(data['results'][0]['revision_count'], 2)
        eq_(data['results'][0]['review_count'], 0)
        eq_(data['results'][0]['last_contribution_date'],
            r2.created.replace(microsecond=0))

        eq_(data['results'][1]['user']['username'], u2.username)
        eq_(data['results'][1]['rank'], 2)
        eq_(data['results'][1]['revision_count'], 1)
        eq_(data['results'][1]['review_count'], 1)
        eq_(data['results'][1]['last_contribution_date'],
            r3.created.replace(microsecond=0))
Exemplo n.º 12
0
    def test_filter_by_product(self):
        u1 = profile().user
        u2 = profile().user

        p1 = product(save=True)
        p2 = product(save=True)

        d1 = document(save=True)
        d1.products.add(p1)
        revision(document=d1, creator=u1, save=True)

        d2 = document(save=True)
        d2.products.add(p2)
        revision(document=d2, creator=u1, save=True)

        d3 = document(save=True)
        d3.products.add(p2)
        revision(document=d3, creator=u2, save=True)

        self.refresh()

        req = self.factory.get('/', {'product': p1.slug})
        data = self.api.get_data(req)

        eq_(data['count'], 1)
        eq_(data['results'][0]['user']['username'], u1.username)
        eq_(data['results'][0]['revision_count'], 1)
Exemplo n.º 13
0
    def test_top_contributors_questions(self):
        firefox = product(slug='firefox', save=True)
        fxos = product(slug='firefox-os', save=True)
        a1 = answer(save=True)
        a1.question.product = firefox
        a1.question.save()
        a2 = answer(creator=a1.creator, save=True)
        a3 = answer(save=True)
        a3.question.product = fxos
        a3.question.save()
        a4 = answer(created=datetime.now() - timedelta(days=91), save=True)
        a5 = answer(creator=a1.creator, save=True)
        a5.question.product = fxos
        a5.question.save()
        answer(creator=a4.question.creator, question=a4.question, save=True)

        for u in User.objects.all():
            profile(user=u)

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top, _ = top_contributors_questions()
        eq_(2, len(top))
        assert a4.creator_id not in [u['term'] for u in top]
        eq_(a1.creator_id, top[0]['term'])

        # Verify, filtering of Firefox questions only.
        top, _ = top_contributors_questions(product=firefox.slug)
        eq_(1, len(top))
        eq_(a1.creator_id, top[0]['term'])
        top, _ = top_contributors_questions(product=fxos.slug)
        eq_(2, len(top))
Exemplo n.º 14
0
    def test_l10n_welcome_email(self, get_current):
        get_current.return_value.domain = 'testserver'

        u1 = profile().user
        u2 = profile(first_l10n_email_sent=True).user

        two_days = datetime.now() - timedelta(hours=48)

        d = document(locale='ru', save=True)
        revision(document=d, creator=u1, created=two_days, save=True)
        revision(document=d, creator=u2, created=two_days, save=True)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u1 only.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u1.email])

        # Links should be locale-neutral
        assert 'en-US' not in mail.outbox[0].body

        # Check that no links used the wrong host.
        assert 'support.mozilla.org' not in mail.outbox[0].body
        # Check that one link used the right host.
        assert 'https://testserver/kb/locales' in mail.outbox[0].body
        # Assumption: links will be done consistently, and so this is enough testing.

        # u3's flag should now be set.
        u1 = User.objects.get(id=u1.id)
        eq_(u1.profile.first_l10n_email_sent, True)
Exemplo n.º 15
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='******')
Exemplo n.º 16
0
    def test_correct_fields(self):
        follower = profile()
        followed = profile()
        q = question(creator=followed.user, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()
        follow(follower.user, followed.user)

        # Make a new action for the above. This should trigger notifications
        action.send(followed.user, verb='asked', action_object=q)
        act = Action.objects.order_by('-id')[0]
        notification = Notification.objects.get(action=act)

        serializer = api.NotificationSerializer(instance=notification)

        eq_(serializer.data['is_read'], False)
        eq_(serializer.data['actor'], {
            'type': 'user',
            'username': followed.user.username,
            'display_name': followed.name,
            'avatar': profile_avatar(followed.user),
        })
        eq_(serializer.data['verb'], 'asked')
        eq_(serializer.data['action_object']['type'], 'question')
        eq_(serializer.data['action_object']['id'], q.id)
        eq_(serializer.data['target'], None)
        # Check that the serialized data is in the correct format. If it is
        # not, this will throw an exception.
        datetime.strptime(serializer.data['timestamp'], '%Y-%m-%dT%H:%M:%SZ')
Exemplo n.º 17
0
    def test_filter_last_contribution(self):
        u1 = profile().user
        u2 = profile().user

        today = datetime.now()
        yesterday = today - timedelta(days=1)
        day_before_yesterday = yesterday - timedelta(days=1)

        revision(creator=u1, created=today, save=True)
        revision(creator=u1, created=day_before_yesterday, save=True)
        revision(creator=u2, created=day_before_yesterday, save=True)

        self.refresh()

        # Test 1

        req = self.factory.get('/', {'last_contribution_date__gt': yesterday.strftime('%Y-%m-%d')})
        data = self.api.get_data(req)

        eq_(data['count'], 1)
        eq_(data['results'][0]['user']['username'], u1.username)
        # Even though only 1 contribution was made in the time range, this filter
        # is only checking the last contribution time, so both are included.
        eq_(data['results'][0]['revision_count'], 2)

        # Test 2

        req = self.factory.get('/', {'last_contribution_date__lt': yesterday.strftime('%Y-%m-%d')})
        data = self.api.get_data(req)

        eq_(data['count'], 1)
        eq_(data['results'][0]['user']['username'], u2.username)
        eq_(data['results'][0]['revision_count'], 1)
Exemplo n.º 18
0
    def test_top_contributors(self):
        # There should be no top contributors since there are no answers.
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(0, len(doc('#top-contributors ol li')))

        # Add an answer, we now have a top conributor.
        a = answer(save=True)
        profile(user=a.creator)
        self.refresh()
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        lis = doc('#top-contributors ol li')
        eq_(1, len(lis))
        eq_(Profile.objects.get(user=a.creator).display_name, lis[0].text)

        # Make answer 91 days old. There should no be top contributors.
        a.created = datetime.now() - timedelta(days=91)
        a.save()
        self.refresh()
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(0, len(doc('#top-contributors ol li')))
Exemplo n.º 19
0
    def test_correct_fields(self):
        follower = profile()
        followed = profile()
        q = question(creator=followed.user, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()
        follow(follower.user, followed.user)

        # Make a new action for the above. This should trigger notifications
        action.send(followed.user, verb='asked', action_object=q)
        act = Action.objects.order_by('-id')[0]
        notification = Notification.objects.get(action=act)

        serializer = api.NotificationSerializer(instance=notification)

        eq_(serializer.data['is_read'], False)
        eq_(
            serializer.data['actor'], {
                'type': 'user',
                'username': followed.user.username,
                'display_name': followed.name,
                'avatar': profile_avatar(followed.user),
            })
        eq_(serializer.data['verb'], 'asked')
        eq_(serializer.data['action_object']['type'], 'question')
        eq_(serializer.data['action_object']['id'], q.id)
        eq_(serializer.data['target'], None)
        # Check that the serialized data is in the correct format. If it is
        # not, this will throw an exception.
        datetime.strptime(serializer.data['timestamp'], '%Y-%m-%dT%H:%M:%SZ')
Exemplo n.º 20
0
    def test_top_contributors_kb(self):
        d = document(locale='en-US', save=True)
        r1 = revision(document=d, save=True)
        r2 = revision(document=d, creator=r1.creator, save=True)
        r3 = revision(document=d, save=True)
        r4 = revision(document=d, created=date.today()-timedelta(days=91),
                      save=True)

        for u in User.objects.all():
            profile(user=u)

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top = top_contributors_kb()
        eq_(2, len(top))
        assert r4.creator_id not in [u['term'] for u in top]
        eq_(r1.creator_id, top[0]['term'])

        # If we specify an older start, then we get all 3.
        top = top_contributors_kb(start=date.today() - timedelta(days=92))
        eq_(3, len(top))

        # If we also specify an older end date, we only get the creator for
        # the older revision.
        top = top_contributors_kb(
            start=date.today() - timedelta(days=92),
            end=date.today() - timedelta(days=1))
        eq_(1, len(top))
        eq_(r4.creator_id, top[0]['term'])
Exemplo n.º 21
0
    def test_l10n_welcome_email(self, get_current):
        get_current.return_value.domain = 'testserver'

        u1 = profile().user
        u2 = profile(first_l10n_email_sent=True).user

        two_days = datetime.now() - timedelta(hours=48)

        d = document(locale='ru', save=True)
        revision(document=d, creator=u1, created=two_days, save=True)
        revision(document=d, creator=u2, created=two_days, save=True)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u1 only.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u1.email])

        # Links should be locale-neutral
        assert 'en-US' not in mail.outbox[0].body

        # Check that no links used the wrong host.
        assert 'support.mozilla.org' not in mail.outbox[0].body
        # Check that one link used the right host.
        assert 'https://testserver/kb/locales' in mail.outbox[0].body
        # Assumption: links will be done consistently, and so this is enough testing.

        # u3's flag should now be set.
        u1 = User.objects.get(id=u1.id)
        eq_(u1.profile.first_l10n_email_sent, True)
Exemplo n.º 22
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='******')
Exemplo n.º 23
0
    def test_top_contributors(self):
        """Verify the top contributors appear."""
        d = document(locale='en-US', save=True)
        revision(document=d, save=True)
        d = document(locale='es', save=True)
        revision(document=d, save=True)
        revision(document=d, save=True)
        answer(save=True)
        answer(save=True)
        answer(save=True)
        reply(user=user(save=True), save=True)
        reply(user=user(save=True), save=True)
        reply(user=user(save=True), save=True)
        reply(user=user(save=True), save=True)

        for u in User.objects.all():
            profile(user=u)

        self.refresh()

        response = self.client.get(urlparams(reverse('community.home')))
        eq_(response.status_code, 200)
        doc = pq(response.content)
        eq_(1, len(doc('ul.kb > li')))
        eq_(2, len(doc('ul.l10n > li')))
        eq_(3, len(doc('ul.questions > li')))
        eq_(4, len(doc('ul.army-of-awesome > li')))
Exemplo n.º 24
0
    def test_filter_by_product(self):
        u1 = profile().user
        u2 = profile().user

        p1 = product(save=True)
        p2 = product(save=True)

        d1 = document(save=True)
        d1.products.add(p1)
        revision(document=d1, creator=u1, save=True)

        d2 = document(save=True)
        d2.products.add(p2)
        revision(document=d2, creator=u1, save=True)

        d3 = document(save=True)
        d3.products.add(p2)
        revision(document=d3, creator=u2, save=True)

        self.refresh()

        req = self.factory.get('/', {'product': p1.slug})
        data = self.api.get_data(req)

        eq_(data['count'], 1)
        eq_(data['results'][0]['user']['username'], u1.username)
        eq_(data['results'][0]['revision_count'], 1)
Exemplo n.º 25
0
    def test_top_contributors_l10n(self):
        d = document(locale='es', save=True)
        es1 = revision(document=d, save=True)
        es1 = revision(document=d, creator=es1.creator, save=True)
        es3 = revision(document=d, save=True)
        es4 = revision(document=d, created=date.today()-timedelta(days=91),
                      save=True)

        d = document(locale='de', save=True)
        de1 = revision(document=d, save=True)
        de2 = revision(document=d, creator=de1.creator, save=True)

        d = document(locale='en-US', save=True)
        revision(document=d, save=True)
        revision(document=d, save=True)

        for u in User.objects.all():
            profile(user=u)

        self.refresh()

        # By default, we should only get 2 top contributors back for 'es'.
        top = top_contributors_l10n(locale='es')
        eq_(2, len(top))
        assert es4.creator_id not in [u['term'] for u in top]
        eq_(es1.creator_id, top[0]['term'])

         # By default, we should only get 1 top contributors back for 'de'.
        top = top_contributors_l10n(locale='de')
        eq_(1, len(top))
        eq_(de1.creator_id, top[0]['term'])

        # If no locale is passed, it includes all locales except en-US.
        top = top_contributors_l10n()
        eq_(3, len(top))
Exemplo n.º 26
0
    def test_reindex_users_that_contributed_yesterday(self):
        yesterday = datetime.now() - timedelta(days=1)

        # Verify for answers.
        u = user(username='******', save=True)
        p = profile(user=u)
        answer(creator=u, created=yesterday, save=True)

        reindex_users_that_contributed_yesterday()
        self.refresh()

        data = UserMappingType.search().query(username__match='answerer')[0]
        eq_(data['last_contribution_date'].date(), yesterday.date())

        # Verify for edits.
        u = user(username='******', save=True)
        p = profile(user=u)
        revision(creator=u, created=yesterday, save=True)

        reindex_users_that_contributed_yesterday()
        self.refresh()

        data = UserMappingType.search().query(username__match='editor')[0]
        eq_(data['last_contribution_date'].date(), yesterday.date())

        # Verify for reviews.
        u = user(username='******', save=True)
        p = profile(user=u)
        revision(reviewer=u, reviewed=yesterday, save=True)

        reindex_users_that_contributed_yesterday()
        self.refresh()

        data = UserMappingType.search().query(username__match='reviewer')[0]
        eq_(data['last_contribution_date'].date(), yesterday.date())
Exemplo n.º 27
0
    def test_top_contributors(self):
        # There should be no top contributors since there are no answers.
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(0, len(doc('#top-contributors ol li')))

        # Add an answer, we now have a top conributor.
        a = answer(save=True)
        profile(user=a.creator)
        self.refresh()
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        lis = doc('#top-contributors ol li')
        eq_(1, len(lis))
        eq_(Profile.objects.get(user=a.creator).display_name, lis[0].text)

        # Make answer 91 days old. There should no be top contributors.
        a.created = datetime.now() - timedelta(days=91)
        a.save()
        self.refresh()
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(0, len(doc('#top-contributors ol li')))
Exemplo n.º 28
0
 def test_only_self_edits(self):
     p1 = profile()
     p2 = profile()
     self.client.force_authenticate(user=p2.user)
     url = reverse('user-detail', args=[p1.user.username])
     res = self.client.patch(url, {})
     # u2 should not have permission to edit u1's user.
     eq_(res.status_code, 403)
Exemplo n.º 29
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar="images/foo.png")
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48&d=%s" % (
         email_hash,
         settings.MEDIA_URL + "images/foo.png",
     )
     eq_(gravatar_url, profile_avatar(self.u))
Exemplo n.º 30
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48&d=%s" % (
         email_hash,
         settings.STATIC_URL + settings.DEFAULT_AVATAR,
     )
     eq_(gravatar_url, profile_avatar(self.u))
Exemplo n.º 31
0
 def test_only_self_edits(self):
     p1 = profile()
     p2 = profile()
     self.client.force_authenticate(user=p2.user)
     url = reverse('user-detail', args=[p1.user.username])
     res = self.client.patch(url, {})
     # u2 should not have permission to edit u1's user.
     eq_(res.status_code, 403)
Exemplo n.º 32
0
    def setUp(self):
        self.client = APIClient()

        self.follower = profile().user
        self.followed = profile().user
        self.question = question(creator=self.followed, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()
        follow(self.follower, self.followed)
Exemplo n.º 33
0
    def setUp(self):
        self.client = APIClient()

        self.follower = profile().user
        self.followed = profile().user
        self.question = question(creator=self.followed, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()
        follow(self.follower, self.followed)
Exemplo n.º 34
0
    def test_no_results(self):
        profile(name='Foo Bar', user=user(username='******', save=True))

        self.refresh()

        response = self.client.get(
            urlparams(reverse('community.search'), q='baz'))

        eq_(response.status_code, 200)
        assert 'No users were found' in response.content
Exemplo n.º 35
0
    def test_loggedin_preferred_language(self):
        u = user(save=True)
        profile(user=u, locale='zh-CN')
        self.client.login(username=u.username, password='******')
        response = self.client.get('/', follow=True)
        self.assertRedirects(response, '/zh-CN/home')

        self.client.logout()
        response = self.client.get('/', follow=True, HTTP_ACCEPT_LANGUAGE='xx')
        self.assertRedirects(response, '/xx/home')
Exemplo n.º 36
0
    def test_loggedin_preferred_language(self):
        u = user(save=True)
        profile(user=u, locale='zh-CN')
        self.client.login(username=u.username, password='******')
        response = self.client.get('/', follow=True)
        self.assertRedirects(response, '/zh-CN/home')

        self.client.logout()
        response = self.client.get('/', follow=True, HTTP_ACCEPT_LANGUAGE='xx')
        self.assertRedirects(response, '/xx/home')
Exemplo n.º 37
0
    def test_query_display_name_with_whitespace(self):
        u1 = user(username="******", save=True)
        p = profile(user=u1, name=u"Elite Mike")
        u2 = user(username="******", save=True)
        profile(user=u2, name=u"NotElite Mike")

        self.refresh()

        eq_(UserMappingType.search().count(), 2)
        eq_(UserMappingType.search().query(idisplay_name__match_whitespace="elite").count(), 1)
Exemplo n.º 38
0
    def test_no_results(self):
        profile(name='Foo Bar', user=user(username='******', save=True))

        self.refresh()

        response = self.client.get(
            urlparams(reverse('community.search'), q='baz'))

        eq_(response.status_code, 200)
        assert 'No users were found' in response.content
Exemplo n.º 39
0
    def test_query_display_name_with_whitespace(self):
        u1 = user(username='******', save=True)
        profile(user=u1, name=u'Elite Mike')
        u2 = user(username='******', save=True)
        profile(user=u2, name=u'NotElite Mike')

        self.refresh()

        eq_(UserMappingType.search().count(), 2)
        eq_(UserMappingType.search().query(
            idisplay_name__match_whitespace='elite').count(), 1)
Exemplo n.º 40
0
    def test_query_username_with_numbers(self):
        u1 = user(username="******", save=True)
        p = profile(user=u1, name=u"Elite Mike")
        u2 = user(username="******", save=True)
        profile(user=u2, name=u"NotElite Mike")

        self.refresh()

        eq_(UserMappingType.search().query(iusername__match="1337mike").count(), 1)
        data = UserMappingType.search().query(iusername__match="1337mike").values_dict()[0]
        eq_(data["username"], p.user.username)
        eq_(data["display_name"], p.name)
Exemplo n.º 41
0
    def test_query_display_name_with_whitespace(self):
        u1 = user(username='******', save=True)
        p = profile(user=u1, name=u'Elite Mike')
        u2 = user(username='******', save=True)
        profile(user=u2, name=u'NotElite Mike')

        self.refresh()

        eq_(UserMappingType.search().count(), 2)
        eq_(
            UserMappingType.search().query(
                idisplay_name__match_whitespace='elite').count(), 1)
Exemplo n.º 42
0
    def test_suggest_completions_numbers(self):
        u1 = user(username='******', save=True)
        profile(user=u1, name=u'Elite Mike')
        u2 = user(username='******', save=True)
        profile(user=u2, name=u'Crazy Pants')

        self.refresh()
        eq_(UserMappingType.search().count(), 2)

        results = UserMappingType.suggest_completions('13')
        eq_(1, len(results))
        eq_('Elite Mike (1337mike)', results[0]['text'])
        eq_(u1.id, results[0]['payload']['user_id'])
Exemplo n.º 43
0
    def test_suggest_completions_numbers(self):
        u1 = user(username="******", save=True)
        profile(user=u1, name=u"Elite Mike")
        u2 = user(username="******", save=True)
        profile(user=u2, name=u"Crazy Pants")

        self.refresh()
        eq_(UserMappingType.search().count(), 2)

        results = UserMappingType.suggest_completions("13")
        eq_(1, len(results))
        eq_("Elite Mike (1337mike)", results[0]["text"])
        eq_(u1.id, results[0]["payload"]["user_id"])
Exemplo n.º 44
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)
Exemplo n.º 45
0
    def test_query_username_with_numbers(self):
        u1 = user(username='******', save=True)
        p = profile(user=u1, name=u'Elite Mike')
        u2 = user(username='******', save=True)
        profile(user=u2, name=u'NotElite Mike')

        self.refresh()

        eq_(UserMappingType.search().query(
            iusername__match='1337mike').count(), 1)
        data = UserMappingType.search().query(iusername__match='1337mike')[0]
        eq_(data['username'], p.user.username)
        eq_(data['display_name'], p.name)
Exemplo n.º 46
0
def notification(**kwargs):
    """Create and return a notification."""
    defaults = {
        'read_at': None,
    }
    defaults.update(kwargs)

    if 'owner' not in defaults:
        defaults['owner'] = profile().user
    if 'action' not in defaults:
        defaults['action'] = Action.objects.create(actor=profile().user, verb='looked at')

    return Notification(**defaults)
Exemplo n.º 47
0
    def test_suggest_completions_numbers(self):
        u1 = user(username='******', save=True)
        profile(user=u1, name=u'Elite Mike')
        u2 = user(username='******', save=True)
        profile(user=u2, name=u'Crazy Pants')

        self.refresh()
        eq_(UserMappingType.search().count(), 2)

        results = UserMappingType.suggest_completions('13')
        eq_(1, len(results))
        eq_('Elite Mike (1337mike)', results[0]['text'])
        eq_(u1.id, results[0]['payload']['user_id'])
Exemplo n.º 48
0
    def test_POST(self, get_current):
        get_current.return_value.domain = 'testserver.com'
        u = user(save=True, email='*****@*****.**', is_active=True)
        profile(user=u)  # save=True is forced.

        r = self.client.post(reverse('users.forgot_username'),
                             {'email': u.email})
        eq_(302, r.status_code)
        eq_('http://testserver/en-US/users/login', r['location'])

        # Verify email
        eq_(1, len(mail.outbox))
        assert mail.outbox[0].subject.find('Your username on') == 0
        assert mail.outbox[0].body.find(u.username) > 0
Exemplo n.º 49
0
    def test_POST(self, get_current):
        get_current.return_value.domain = 'testserver.com'
        u = user(save=True, email='*****@*****.**', is_active=True)
        profile(user=u)  # save=True is forced.

        r = self.client.post(reverse('users.forgot_username'),
                             {'email': u.email})
        eq_(302, r.status_code)
        eq_('http://testserver/en-US/users/login', r['location'])

        # Verify email
        eq_(1, len(mail.outbox))
        assert mail.outbox[0].subject.find('Your username on') == 0
        assert mail.outbox[0].body.find(u.username) > 0
Exemplo n.º 50
0
    def test_query_username_with_numbers(self):
        u1 = user(username='******', save=True)
        p = profile(user=u1, name=u'Elite Mike')
        u2 = user(username='******', save=True)
        profile(user=u2, name=u'NotElite Mike')

        self.refresh()

        eq_(
            UserMappingType.search().query(
                iusername__match='1337mike').count(), 1)
        data = UserMappingType.search().query(iusername__match='1337mike')[0]
        eq_(data['username'], p.user.username)
        eq_(data['display_name'], p.name)
Exemplo n.º 51
0
def notification(**kwargs):
    """Create and return a notification."""
    defaults = {
        'read_at': None,
    }
    defaults.update(kwargs)

    if 'owner' not in defaults:
        defaults['owner'] = profile().user
    if 'action' not in defaults:
        defaults['action'] = Action.objects.create(actor=profile().user,
                                                   verb='looked at')

    return Notification(**defaults)
Exemplo n.º 52
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)
Exemplo n.º 53
0
    def test_top_army_of_awesome(self):
        r1 = reply(user=user(save=True), save=True)
        r2 = reply(user=user(save=True), save=True)
        profile(user=r1.user)
        profile(user=r2.user)

        self.refresh()

        response = self.client.get(urlparams(
            reverse('community.top_contributors', args=['army-of-awesome'])))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(2, len(doc('li.results-user')))
        assert r1.user.username in response.content
        assert r2.user.username in response.content
Exemplo n.º 54
0
    def test_top_questions(self):
        a1 = answer(save=True)
        a2 = answer(save=True)
        profile(user=a1.creator)
        profile(user=a2.creator)

        self.refresh()

        response = self.client.get(urlparams(
            reverse('community.top_contributors', args=['questions'])))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(2, len(doc('li.results-user')))
        assert a1.creator.username in response.content
        assert a2.creator.username in response.content
Exemplo n.º 55
0
 def test_from_action_to_simple_push(self, requests):
     """Test that when an action is created, it results in a push notification being sent."""
     # Create a user.
     u = profile().user
     # Register them to receive push notifications.
     url = 'http://example.com/simple_push/asdf'
     PushNotificationRegistration.objects.create(creator=u, push_url=url)
     # Make them follow an object.
     q = question(save=True)
     follow(u, q, actor_only=False)
     # Create an action involving that object
     action.send(profile().user, verb='looked at funny', action_object=q)
     n = Notification.objects.get(owner=u)
     # Assert that they got notified.
     requests.put.assert_called_once_with(url, 'version={}'.format(n.id))
Exemplo n.º 56
0
    def test_following_actor(self):
        follower = profile().user
        followed = profile().user
        q = question(creator=followed, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()
        follow(follower, followed)

        # Make a new action for the above. This should trigger notifications
        action.send(followed, verb='asked', action_object=q)
        act = Action.objects.order_by('-id')[0]
        notification = Notification.objects.get(action=act)

        eq_(notification.owner, follower)
        eq_(notification.action, act)
Exemplo n.º 57
0
    def setUp(self):
        self.client = APIClient()

        follower = profile()
        followed = profile()
        q = question(creator=followed.user, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()

        follow(follower.user, followed.user)

        # Make a new action for the above. This should trigger notifications
        action.send(followed.user, verb='asked', action_object=q)
        act = Action.objects.order_by('-id')[0]
        self.notification = Notification.objects.get(action=act)
Exemplo n.º 58
0
    def test_updates_subview(self, requests):
        requests.put.return_value.status_code = 200

        u = profile().user
        q = question(content='asdf', save=True)
        ct = ContentType.objects.get_for_model(q)
        rt = RealtimeRegistration.objects.create(
            creator=u,
            content_type=ct,
            object_id=q.id,
            endpoint='http://example.com/')
        # Some of the above may have created actions, which we don't care about.
        Action.objects.all().delete()
        # This should create an action that will trigger the above.
        a = answer(question=q, content='asdf', save=True)

        self.client.force_authenticate(user=u)
        url = reverse('realtimeregistration-updates', args=[rt.id])
        res = self.client.get(url)
        eq_(res.status_code, 200)

        eq_(len(res.data), 1)
        act = res.data[0]
        eq_(act['actor']['username'], a.creator.username)
        eq_(act['target']['content'], q.content_parsed)
        eq_(act['action_object']['content'], a.content_parsed)
Exemplo n.º 59
0
 def setUp(self):
     self.u = user(save=True)
     self.profile = profile(user=self.u)
     self.url = reverse('users.profile',
                        args=[self.u.username],
                        locale='en-US')
     super(UserProfileTests, self).setUp()
Exemplo n.º 60
0
 def test_request_password_reset(self, get_current):
     get_current.return_value.domain = 'testserver'
     p = profile()
     url = reverse('user-request-password-reset', args=[p.user.username])
     res = self.client.get(url)
     eq_(res.status_code, 204)
     eq_(1, len(mail.outbox))