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')))
def test_reindex_users_that_contributed_yesterday(self): yesterday = datetime.now() - timedelta(days=1) # Verify for answers. u = user(username='******', save=True) 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) 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) 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())
def setUp(self): super(ActiveContributorsTestCase, self).setUp() start_date = date.today() - timedelta(days=10) self.start_date = start_date before_start = start_date - timedelta(days=1) # Create some revisions to test with. # 3 'en-US' contributors: d = document(locale='en-US', save=True) u = user(save=True) self.user = u revision(document=d, is_approved=True, reviewer=u, save=True) revision(document=d, creator=u, save=True) self.product = product(save=True) r = revision(created=start_date, save=True) r.document.products.add(self.product) # Add one that shouldn't count: self.en_us_old = revision(document=d, created=before_start, save=True) # 4 'es' contributors: d = document(locale='es', save=True) revision(document=d, is_approved=True, reviewer=u, save=True) revision(document=d, creator=u, reviewer=user(save=True), save=True) revision(document=d, created=start_date, save=True) revision(document=d, save=True) # Add one that shouldn't count: self.es_old = revision(document=d, created=before_start, save=True)
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')
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='******')
def setUp(self): super(AddRemoveMemberTests, self).setUp() self.user = user(save=True) self.member = user(save=True) add_permission(self.user, GroupProfile, "change_groupprofile") self.group_profile = group_profile(group=group(save=True), save=True) self.client.login(username=self.user.username, password="******")
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='******')
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()
def test_user_can_edit_others_profile_with_permission(self): u1 = user(save=True) url = reverse('users.edit_profile', args=[u1.username]) u2 = user(save=True) add_permission(u2, Profile, 'change_profile') self.client.login(username=u2.username, password='******') # Try GET r = self.client.get(url) eq_(200, r.status_code) # Try POST data = {'name': 'John Doe', 'public_email': True, 'bio': 'my bio', 'website': 'http://google.com/', 'twitter': '', 'facebook': '', 'mozillians': '', 'irc_handle': 'johndoe', 'timezone': 'America/New_York', 'country': 'US', 'city': 'Disney World', 'locale': 'en-US'} r = self.client.post(url, data) eq_(302, r.status_code) profile = Profile.objects.get(user=u1) for key in data: if key != 'timezone': eq_(data[key], getattr(profile, key)) eq_(data['timezone'], profile.timezone.zone)
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)
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) # Create metric kinds and update metrics for tomorrow (today's # activity shows up tomorrow). self._make_contributor_metric_kinds() update_contributor_metrics(day=date.today() + timedelta(days=1)) 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)
def test_product_specific_ready(self): """Verify product-specific ready for l10n notifications.""" # Add a Firefox OS watcher. ReadyRevisionEvent.notify(user(save=True), product='firefox-os') # Create a document for Firefox doc = document(save=True) doc.products.add(product(slug='firefox', save=True)) # Mark a revision a ready for L10n. There should be only one email # to the watcher created in setUp. self._mark_as_ready_revision(doc=doc) eq_(1, len(mail.outbox)) _assert_ready_mail(mail.outbox[0]) # Add firefox-os to the document's products. Mark as ready for l10n, # and there should be two new emails. doc.products.add(product(slug='firefox-os', save=True)) self._mark_as_ready_revision(doc=doc) eq_(3, len(mail.outbox)) _assert_ready_mail(mail.outbox[1]) _assert_ready_mail(mail.outbox[2]) # Add a Firefox watcher, mark as ready for l10n, and there should # be three new emails. ReadyRevisionEvent.notify(user(save=True), product='firefox') self._mark_as_ready_revision(doc=doc) eq_(6, len(mail.outbox))
def test_no_duplicate_emails(self): user(email=self.data['email'], save=True) serializer = api.ProfileShortSerializer(data=self.data) eq_(serializer.errors, { 'email': ['A user with that email address already exists.'], }) ok_(not serializer.is_valid())
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)
def test_take_twice_forced(self): u1 = user(save=True) u2 = user(save=True) q = question(save=True) q.take(u1) q.take(u2, force=True) eq_(q.taken_by, u2)
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 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="******")
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="******")
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
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)
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)
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='******')
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)
def test_take_conflict(self): u1 = user(save=True) u2 = user(save=True) taken_until = datetime.now() + timedelta(seconds=30) q = question(save=True, taken_until=taken_until, taken_by=u1) self.client.force_authenticate(user=u2) res = self.client.post(reverse('question-take', args=[q.id])) eq_(res.status_code, 409) q = Question.objects.get(id=q.id) eq_(q.taken_by, u1)
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. """ def _login(user): self.client.login(username=user.username, password="******") def assert_is_locked(r): self.assertContains(r, 'id="unlock-button"') def assert_not_locked(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)
def test_user_list(self): u = user(username='******', save=True) user(username='******', save=True) users = User.objects.all() list = user_list(users) assert isinstance(list, Markup) fragment = pq(list) eq_(3, len(fragment('a'))) a = fragment('a')[1] assert a.attrib['href'].endswith(str(u.username)) eq_(u.username, a.text)
def test_user_list(self): u = user(username="******", save=True) user(username="******", save=True) users = User.objects.all() list = user_list(users) assert isinstance(list, Markup) fragment = pq(list) eq_(3, len(fragment("a"))) a = fragment("a")[1] assert a.attrib["href"].endswith(str(u.id)) eq_(u.username, a.text)
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)
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
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='******')
def test_links_nofollow(self): """Links posted should have rel=nofollow.""" u = user(save=True) t = thread(save=True) t.new_post(creator=u, content='linking http://test.org') response = get(self.client, 'wiki.discuss.posts', args=[t.document.slug, t.pk]) doc = pq(response.content) eq_('nofollow', doc('ol.posts div.content a')[0].attrib['rel'])
def test_fire_on_reply(self, fire): """The event fires when there is a reply.""" u = user(save=True) t = thread(save=True) self.client.login(username=u.username, password='******') post(self.client, 'forums.reply', {'content': 'a post'}, args=[t.forum.slug, t.id]) # NewPostEvent.fire() is called. assert fire.called
def test_fire_on_new_thread(self, fire): """The event fires when there is a new thread.""" u = user(save=True) f = forum(save=True) self.client.login(username=u.username, password='******') post(self.client, 'forums.new_thread', {'title': 'a title', 'content': 'a post'}, args=[f.slug]) # NewThreadEvent.fire() is called. assert fire.called
def test_has_perm_thread_delete(self): """User in group can delete thread in forum_1, but not in forum_2.""" u = user(save=True) self.group.user_set.add(u) self.context['request'].user = u assert 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)
def test_has_perm_post_edit(self): """User in group can edit any post in forum_1, but not in forum_2.""" u = user(save=True) self.group.user_set.add(u) self.context['request'].user = u assert has_perm(self.context, 'forums_forum.post_edit_forum', self.forum_1) assert not has_perm(self.context, 'forums_forum.post_edit_forum', self.forum_2)
def test_report_employee_answers(self): # Note: This depends on two groups that are created in migrations. # If we fix the tests to not run migrations, we'll need to create the # two groups here: 'Support Forum Tracked', 'Support Forum Metrics' tracked_group = Group.objects.get(name='Support Forum Tracked') tracked_user = user(save=True) tracked_user.groups.add(tracked_group) report_group = Group.objects.get(name='Support Forum Metrics') report_user = user(save=True) report_user.groups.add(report_group) # An unanswered question that should get reported question(created=datetime.now() - timedelta(days=2), save=True) # An answered question that should get reported q = question(created=datetime.now() - timedelta(days=2), save=True) answer(question=q, save=True) # A question answered by a tracked user that should get reported q = question(created=datetime.now() - timedelta(days=2), save=True) answer(creator=tracked_user, question=q, save=True) # More questions that shouldn't get reported q = question(created=datetime.now() - timedelta(days=3), save=True) answer(creator=tracked_user, question=q, save=True) q = question(created=datetime.now() - timedelta(days=1), save=True) answer(question=q, save=True) question(save=True) report_employee_answers() # Get the last email and verify contents email = mail.outbox[len(mail.outbox) - 1] assert 'Number of questions asked: 3' in email.body assert 'Number of questions answered: 2' in email.body assert '{username}: 1'.format( username=tracked_user.username) in email.body eq_([report_user.email], email.to)
def test_delete_post_removes_flag(self): """Deleting a post also removes the flags on that post.""" p = post(save=True) u = user(save=True) FlaggedObject.objects.create( status=0, content_object=p, reason='language', creator_id=u.id) eq_(1, FlaggedObject.objects.count()) p.delete() eq_(0, FlaggedObject.objects.count())
def setUp(self): # This has to be done before the db goes into read only mode. self.user = user(save=True, password='******') models.signals.pre_save.connect(self.db_error) models.signals.pre_delete.connect(self.db_error) self.old_settings = copy.copy(settings._wrapped.__dict__) settings.SLAVE_DATABASES = ['default'] settings_module = importlib.import_module(settings.SETTINGS_MODULE) settings_module.read_only_mode(settings._wrapped.__dict__) self.client.handler.load_middleware()
def test_util_has_perm_or_owns_sanity(self): """Sanity check for access.has_perm_or_owns.""" from kitsune.forums.tests import thread me = user(save=True) my_t = thread(creator=me, save=True) other_t = thread(save=True) perm = 'forums_forum.thread_edit_forum' allowed = access.has_perm_or_owns(me, perm, my_t, my_t.forum) eq_(allowed, True) allowed = access.has_perm_or_owns(me, perm, other_t, other_t.forum) eq_(allowed, False)
def setUp(self): self.locale = locale(save=True, locale='es') self.u = user(save=True) self.locale.leaders.add(self.u) self.locale.save() self.announcement = announcement( creator=self.u, locale=self.locale, content="Look at me!", show_after=datetime(2012, 01, 01, 0, 0, 0), save=True)
def test_has_perm_thread_sticky(self): # User in group can change sticky status of thread in forum_1, # but not in forum_2. u = user(save=True) self.group.user_set.add(u) self.context['request'].user = u assert has_perm(self.context, 'forums_forum.thread_sticky_forum', self.forum_1) assert not has_perm(self.context, 'forums_forum.thread_sticky_forum', self.forum_2)
def test_edit_own_image(self): """Can edit an image I created.""" u = user(save=True) img = image(creator=u) self.client.login(username=u.username, password='******') r = post(self.client, 'gallery.edit_media', {'description': 'arrr'}, args=['image', img.id]) eq_(200, r.status_code) eq_('arrr', Image.objects.get().description)
def test_reply_without_view_permission(self): """Posting without view_in_forum permission should 404.""" rforum = restricted_forum() t = thread(forum=rforum, save=True) u = user(save=True) self.client.login(username=u.username, password='******') response = post(self.client, 'forums.reply', {'content': 'Blahs'}, args=[t.forum.slug, t.id]) eq_(404, response.status_code)
def setUp(self): super(TestQuestionUpdates, self).setUp() self.u = user(is_superuser=True, save=True) self.client.login(username=self.u.username, password='******') self.q = question(updated=datetime(2012, 7, 9, 9, 0, 0), save=True) self.a = answer(question=self.q, save=True) # Get the question from the database so we have a consistent level of # precision during the test. self.q = Question.objects.get(pk=self.q.id)
def test_schedule_rebuild_kb_on_delete(self, schedule_rebuild_kb): """KB rebuild scheduled on delete""" im = image() u = user(save=True) add_permission(u, Image, 'delete_image') self.client.login(username=u.username, password='******') r = post(self.client, 'gallery.delete_media', args=['image', im.id]) eq_(200, r.status_code) eq_(0, Image.objects.count()) assert schedule_rebuild_kb.called
def test_no_match_passwords(self): u = user(save=True) response = self.client.post(reverse('users.registercontributor', locale='en-US'), { 'username': u.username, 'email': u.email, 'password': '******', 'password2': 'testbus' }, follow=True) self.assertContains(response, 'must match')
def test_logged_in_get(self, get_current): """New question is posted through mobile.""" get_current.return_value.domain = 'testserver' u = user(save=True) self.client.login(username=u.username, password='******') response = self._new_question() eq_(200, response.status_code) self.assertTemplateUsed(response, 'questions/mobile/new_question.html')
def test_duplicate_username(self): u = user(save=True) response = self.client.post(reverse('users.registercontributor', locale='en-US'), { 'username': u.username, 'email': '*****@*****.**', 'password': '******', 'password2': 'foo' }, follow=True) self.assertContains(response, 'already exists')
def test_data_in_index(self): """Verify the data we are indexing.""" u = user(username='******', email='*****@*****.**', save=True) p = profile(user=u, name=u'Rick Róss') r1 = reply(user=u, twitter_username='******', save=True) r2 = reply(user=u, twitter_username='******', save=True) self.refresh() eq_(UserMappingType.search().count(), 1) data = UserMappingType.search().values_dict()[0] eq_(data['username'], p.user.username) eq_(data['display_name'], p.name) assert r1.twitter_username in data['twitter_usernames'] assert r2.twitter_username in data['twitter_usernames'] u = user(username='******', email='*****@*****.**', save=True) p = profile(user=u, name=u'Will Cage') self.refresh() eq_(UserMappingType.search().count(), 2)
def test_post_delete_403(self): """Deleting a post without permissions returns 403.""" p = forum_post(save=True) t = p.thread u = user(save=True) self.client.login(username=u.username, password='******') response = get(self.client, 'forums.delete_post', args=[t.forum.slug, t.id, p.id]) eq_(403, response.status_code)
def test_move_thread_403(self): """Moving a thread without permissions returns 403.""" t = forum_post(save=True).thread f = forum(save=True) u = user(save=True) self.client.login(username=u.username, password='******') response = post(self.client, 'forums.move_thread', {'forum': f.id}, args=[t.forum.slug, t.id]) eq_(403, response.status_code)
def test_edit_image_with_permissions(self): """Editing image sets the updated_by field.""" img = image() u = user(save=True) add_permission(u, Image, 'change_image') self.client.login(username=u.username, password='******') r = post(self.client, 'gallery.edit_media', {'description': 'arrr'}, args=['image', img.id]) eq_(200, r.status_code) eq_(u.username, Image.objects.get().updated_by.username)
def test_data_in_index(self): """Verify the data we are indexing.""" u = user(save=True) r = reply(user=u, locale='de', save=True) self.refresh() eq_(ReplyMetricsMappingType.search().count(), 1) data = ReplyMetricsMappingType.search()[0] eq_(data['locale'], r.locale) eq_(data['creator_id'], r.user_id)
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) # 1 mail for each watcher, 1 for creator, and one for reviewer. eq_(4, 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 'Your revision has been approved' in mail.outbox[2].subject assert 'A revision you contributed to has' in mail.outbox[3].subject
def test_results(self): profile(name='Foo Bar', user=user(username='******', save=True)) profile(name='Bar Bam', user=user(username='******', save=True)) self.refresh() # Searching for "bam" should return 1 user. response = self.client.get( urlparams(reverse('community.search'), q='bam')) eq_(response.status_code, 200) doc = pq(response.content) eq_(len(doc('.results-user')), 1) # Searching for "bar" should return both users. response = self.client.get( urlparams(reverse('community.search'), q='bar')) eq_(response.status_code, 200) doc = pq(response.content) eq_(len(doc('.results-user')), 2)
def test_watch_forum_without_permission(self): """Watching forums without the view_in_forum permission should 404. """ rforum = restricted_forum() u = user(save=True) self.client.login(username=u.username, password='******') response = self.client.post(reverse('forums.watch_forum', args=[rforum.slug]), {'watch': 'yes'}, follow=False) eq_(404, response.status_code)
def test_edit_thread_template(self): """The edit-thread template should render.""" u = user(save=True) self.client.login(username=u.username, password='******') t = thread(creator=u, is_locked=False, save=True) res = get(self.client, 'wiki.discuss.edit_thread', args=[t.document.slug, t.id]) doc = pq(res.content) eq_(len(doc('form.edit-thread')), 1)
def test_reply_without_post_permission(self): """Posting without post_in_forum permission should 403.""" rforum = restricted_forum(permission_code='forums_forum.post_in_forum') t = thread(forum=rforum, save=True) u = user(save=True) self.client.login(username=u.username, password='******') with patch.object(Forum, 'allows_viewing_by', Mock(return_value=True)): response = post(self.client, 'forums.reply', {'content': 'Blahs'}, args=[t.forum.slug, t.id]) eq_(403, response.status_code)
def test_duplicate_email(self): u = user(email='*****@*****.**', save=True) User.objects.create(username='******', email='*****@*****.**').save() response = self.client.post(reverse('users.registercontributor', locale='en-US'), { 'username': '******', 'email': u.email, 'password': '******', 'password2': 'foo' }, follow=True) self.assertContains(response, 'already exists')
def test_new_thread_redirect(self): """Posting a new thread should redirect.""" f = forum(save=True) u = user(save=True) self.client.login(username=u.username, password='******') url = reverse('forums.new_thread', args=[f.slug]) data = {'title': 'some title', 'content': 'some content'} r = self.client.post(url, data, follow=False) eq_(302, r.status_code) assert f.slug in r['location'] assert 'last=' in r['location']