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 #2
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 #3
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)
Example #4
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 #5
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 #6
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 #7
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")
Example #8
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 #9
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
Example #10
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
Example #11
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
Example #12
0
def questionvote(**kwargs):
    defaults = dict(created=datetime.now())
    defaults.update(kwargs)
    if "question" not in kwargs and "queation_id" not in kwargs:
        defaults["question"] = question(save=True)
    if "creator" not in kwargs and "creator_id" not in kwargs:
        defaults["creator"] = profile().user
    return QuestionVote(**defaults)
Example #13
0
    def test_anonymous_change_to_login(self):
        u = user(save=True)
        profile(user=u, locale="zh-CN")

        # anonymous is fr
        self.client.get("/?lang=fr", follow=True)
        response = self.client.get("/", follow=True)
        self.assertRedirects(response, "/fr/home")

        # logged in is zh-CN
        self.client.login(username=u.username, password="******")
        response = self.client.get("/", follow=True)
        self.assertRedirects(response, "/zh-CN/home")

        # anonymous again, session is now destroyed
        self.client.logout()
        response = self.client.get("/", follow=True, HTTP_ACCEPT_LANGUAGE="xx")
        self.assertRedirects(response, "/xx/home")
Example #14
0
    def test_num_documents(self):
        """Verify the number of documents contributed by user."""
        u = profile().user
        revision(creator=u, save=True)
        revision(creator=u, save=True)

        r = self.client.get(reverse('users.profile', args=[u.id]))
        eq_(200, r.status_code)
        assert '2 documents' in r.content
Example #15
0
    def test_num_documents(self):
        """Verify the number of documents contributed by user."""
        u = profile().user
        revision(creator=u, save=True)
        revision(creator=u, save=True)

        r = self.client.get(reverse('users.profile', args=[u.id]))
        eq_(200, r.status_code)
        assert '2 documents' in r.content
Example #16
0
 def setUp(self):
     self.timezone = timezone('US/Pacific')
     self.locale = 'en_US'
     url_ = reverse('forums.threads', args=['testslug'])
     self.context = {'request': test_utils.RequestFactory().get(url_)}
     self.context['request'].locale = self.locale
     user_profile = profile(timezone=self.timezone, locale=self.locale)
     self.context['request'].user = user_profile
     self.context['request'].user.is_authenticated = Mock(return_value=True)
     self.context['request'].session = {'timezone': self.timezone}
Example #17
0
 def setUp(self):
     self.timezone = timezone('US/Pacific')
     self.locale = 'en_US'
     url_ = reverse('forums.threads', args=['testslug'])
     self.context = {'request': test_utils.RequestFactory().get(url_)}
     self.context['request'].LANGUAGE_CODE = self.locale
     user_profile = profile(timezone=self.timezone, locale=self.locale)
     self.context['request'].user = user_profile
     self.context['request'].user.is_authenticated = Mock(return_value=True)
     self.context['request'].session = {'timezone': self.timezone}
Example #18
0
    def test_ga_custom_variable_on_registered_login(self):
        """After logging in, there should be a ga-push data attr on body."""
        user_ = profile().user

        # User should be "Registered":
        response = self.client.post(
            reverse("users.login"), {"username": user_.username, "password": "******"}, follow=True
        )
        eq_(200, response.status_code)
        doc = pq(response.content)
        assert '"Registered"' in doc("body").attr("data-ga-push")
Example #19
0
    def test_ga_custom_variable_on_registered_login(self):
        """After logging in, there should be a ga-push data attr on body."""
        user_ = profile().user

        # User should be "Registered":
        response = self.client.post(reverse('users.login'),
                                    {'username': user_.username,
                                     'password': '******'},
                                    follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        assert '"Registered"' in doc('body').attr('data-ga-push')
Example #20
0
    def test_ga_custom_variable_on_admin_login(self):
        """After logging in, there should be a ga-push data attr on body."""
        user_ = profile().user

        # Add user to Administrators and so should be "Contributor - Admin":
        user_.groups.add(group(name="Administrators", save=True))
        response = self.client.post(
            reverse("users.login"), {"username": user_.username, "password": "******"}, follow=True
        )
        eq_(200, response.status_code)
        doc = pq(response.content)
        assert '"Contributor - Admin"' in doc("body").attr("data-ga-push")
Example #21
0
    def test_ga_custom_variable_on_registered_login(self):
        """After logging in, there should be a ga-push data attr on body."""
        user_ = profile().user

        # User should be "Registered":
        response = self.client.post(reverse('users.login'),
                                    {'username': user_.username,
                                     'password': '******'},
                                    follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        assert '"Registered"' in doc('body').attr('data-ga-push')
Example #22
0
    def test_ga_custom_variable_on_admin_login(self):
        """After logging in, there should be a ga-push data attr on body."""
        user_ = profile().user

        # Add user to Administrators and so should be "Contributor - Admin":
        user_.groups.add(group(name='Administrators', save=True))
        response = self.client.post(reverse('users.login'),
                                    {'username': user_.username,
                                     'password': '******'},
                                    follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        assert '"Contributor - Admin"' in doc('body').attr('data-ga-push')
Example #23
0
    def test_ga_custom_variable_on_contributor_login(self):
        """After logging in, there should be a ga-push data attr on body."""
        user_ = profile().user

        # Add user to Contributors and so should be "Contributor":
        user_.groups.add(group(name='Contributors', save=True))
        response = self.client.post(reverse('users.login'),
                                    {'username': user_.username,
                                     'password': '******'},
                                    follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        assert '"Contributor"' in doc('body').attr('data-ga-push')
Example #24
0
    def test_flagged_and_deleted_profile(self):
        u = user(save=True)
        p = profile(user=u)
        flag_user = user(save=True)
        # Flag a profile and delete it
        f = FlaggedObject(content_object=p, reason="spam", creator_id=flag_user.id)
        f.save()
        p.delete()

        # Verify flagit queue
        u = user(save=True)
        add_permission(u, FlaggedObject, "can_moderate")
        self.client.login(username=u.username, password="******")
        response = get(self.client, "flagit.queue")
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(1, len(doc("#flagged-queue form.update")))
Example #25
0
    def test_deactivate_button(self):
        """Check that the deactivate button is shown appropriately"""
        p = profile()
        r = self.client.get(reverse('users.profile', args=[p.user.id]))
        assert 'Deactivate this user' not in r.content

        add_permission(self.u, Profile, 'deactivate_users')
        self.client.login(username=self.u.username, password='******')
        r = self.client.get(reverse('users.profile', args=[p.user.id]))
        assert 'Deactivate this user' in r.content

        p.user.is_active = False
        p.user.save()
        r = self.client.get(reverse('users.profile', args=[p.user.id]))
        assert 'This user has been deactivated.' in r.content

        r = self.client.get(reverse('users.profile', args=[self.u.id]))
        assert 'Deactivate this user' not in r.content
Example #26
0
    def test_profile_deactivate(self):
        """Test user deactivation"""
        p = profile()

        self.client.login(username=self.u.username, password='******')
        res = self.client.post(reverse('users.deactivate', locale='en-US'),
                               {'user_id': p.user.id})

        eq_(403, res.status_code)

        add_permission(self.u, Profile, 'deactivate_users')
        res = self.client.post(reverse('users.deactivate', locale='en-US'),
                               {'user_id': p.user.id})

        eq_(302, res.status_code)

        p = Profile.objects.get(user_id=p.user_id)
        assert not p.user.is_active
Example #27
0
    def test_flagged_and_deleted_profile(self):
        u = user(save=True)
        p = profile(user=u)
        flag_user = user(save=True)
        # Flag a profile and delete it
        f = FlaggedObject(content_object=p,
                          reason='spam', creator_id=flag_user.id)
        f.save()
        p.delete()

        # Verify flagit queue
        u = user(save=True)
        add_permission(u, FlaggedObject, 'can_moderate')
        self.client.login(username=u.username, password='******')
        response = get(self.client, 'flagit.queue')
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(1, len(doc('#flagged-queue form.update')))
Example #28
0
    def test_deactivate_button(self):
        """Check that the deactivate button is shown appropriately"""
        p = profile()
        r = self.client.get(reverse('users.profile', args=[p.user.id]))
        assert 'Deactivate this user' not in r.content

        add_permission(self.u, Profile, 'deactivate_users')
        self.client.login(username=self.u.username, password='******')
        r = self.client.get(reverse('users.profile', args=[p.user.id]))
        assert 'Deactivate this user' in r.content

        p.user.is_active = False
        p.user.save()
        r = self.client.get(reverse('users.profile', args=[p.user.id]))
        assert 'This user has been deactivated.' in r.content

        r = self.client.get(reverse('users.profile', args=[self.u.id]))
        assert 'Deactivate this user' not in r.content
Example #29
0
    def test_profile_deactivate(self):
        """Test user deactivation"""
        p = profile()

        self.client.login(username=self.u.username, password='******')
        res = self.client.post(reverse('users.deactivate', locale='en-US'),
                               {'user_id': p.user.id})

        eq_(403, res.status_code)

        add_permission(self.u, Profile, 'deactivate_users')
        res = self.client.post(reverse('users.deactivate', locale='en-US'),
                               {'user_id': p.user.id})

        eq_(302, res.status_code)

        p = Profile.objects.get(user_id=p.user_id)
        assert not p.user.is_active
Example #30
0
 def setUp(self):
     self.u = user(save=True)
     self.profile = profile(user=self.u)
     self.url = reverse('users.profile', args=[self.u.pk], locale='en-US')
     super(UserProfileTests, self).setUp()
Example #31
0
 def setUp(self):
     self.u = user(save=True)
     self.p = profile(user=self.u)
     self.client.login(username=self.u.username, password='******')
     super(UserSettingsTests, self).setUp()
Example #32
0
 def setUp(self):
     self.u = user(save=True)
     profile(user=self.u)
     self.client.login(username=self.u.username, password='******')
     super(ChangeEmailTestCase, self).setUp()
Example #33
0
 def setUp(self):
     self.u = user()
     self.u.save()
     self.p = profile(self.u)
     self.client.login(username=self.u.username, password='******')
Example #34
0
    def test_user_get_profile(self):
        """user.get_profile() returns what you'd expect."""
        user = User.objects.all()[0]
        p = profile(user)

        eq_(p, user.get_profile())
Example #35
0
 def setUp(self):
     self.u = user(save=True)
     self.profile = profile(name='', website='', user=self.u)
Example #36
0
    def test_user_get_profile(self):
        """user.get_profile() returns what you'd expect."""
        u = user(save=True)
        p = profile(user=u)

        eq_(p, u.get_profile())
Example #37
0
 def setUp(self):
     self.user = user()
     self.user.save()
     self.profile = profile(user=self.user)
     self.url = reverse('users.profile', args=[self.user.pk],
                        locale='en-US')
Example #38
0
 def test_display_name(self):
     eq_(u'testuser', display_name(self.u))
     p = profile(user=self.u, name=u'Test User')
     eq_(u'Test User', display_name(self.u))
Example #39
0
 def setUp(self):
     self.user = user()
     self.user.save()
     self.profile = profile(user=self.user)
     self.url = reverse('users.profile', args=[self.user.pk],
                        locale='en-US')
Example #40
0
 def setUp(self):
     self.u = user(save=True)
     self.profile = profile(name='', website='', user=self.u)
Example #41
0
 def setUp(self):
     self.u = user()
     self.u.save()
     self.p = profile(self.u)
     self.client.login(username=self.u.username, password='******')
Example #42
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     eq_(settings.DEFAULT_AVATAR, profile_avatar(self.u))
Example #43
0
 def setUp(self):
     self.u = user(save=True)
     self.profile = profile(user=self.u)
     self.url = reverse('users.profile', args=[self.u.pk],
                        locale='en-US')
     super(UserProfileTests, self).setUp()
Example #44
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar='images/foo.png')
     eq_('%simages/foo.png' % settings.MEDIA_URL, profile_avatar(self.u))
Example #45
0
 def setUp(self):
     super(EditAvatarTests, self).setUp()
     self.old_settings = copy(settings._wrapped.__dict__)
     self.u = user(save=True)
     profile(user=self.u)
Example #46
0
 def test_display_name(self):
     eq_(u'testuser', display_name(self.u))
     p = profile(user=self.u, name=u'Test User')
     eq_(u'Test User', display_name(self.u))
Example #47
0
 def setUp(self):
     super(EditAvatarTests, self).setUp()
     self.old_settings = copy(settings._wrapped.__dict__)
     self.u = user(save=True)
     profile(user=self.u)
Example #48
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar='images/foo.png')
     eq_('%simages/foo.png' % settings.MEDIA_URL, profile_avatar(self.u))
Example #49
0
 def setUp(self):
     super(AnnouncementModelTests, self).setUp()
     self.creator = user(save=True)
     profile(self.creator).save()
     self.group = group(save=True)
     self.creator.groups.add(self.group)
Example #50
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     eq_(settings.DEFAULT_AVATAR, profile_avatar(self.u))
Example #51
0
 def setUp(self):
     super(AnnouncementModelTests, self).setUp()
     self.creator = user(save=True)
     profile(self.creator).save()
     self.group = group(save=True)
     self.creator.groups.add(self.group)
Example #52
0
def question(**kwargs):
    defaults = dict(title=str(datetime.now()), content="", created=datetime.now(), num_answers=0, is_locked=0)
    defaults.update(kwargs)
    if "creator" not in kwargs and "creator_id" not in kwargs:
        defaults["creator"] = profile().user
    return Question(**defaults)