Exemplo n.º 1
0
    def test_inactive_user(self):
        """
        An inactive user cannot access the AAQ flow
        """
        user = UserFactory(is_superuser=False)
        self.client.login(username=user.username, password="******")

        # After log in, set user to inactive
        user.is_active = False
        user.save()

        url = reverse("questions.aaq_step1")
        response = self.client.get(url, follow=True)
        assert not template_used(response, "questions/new_question.html")
Exemplo n.º 2
0
    def test_deactivate_button(self):
        """Check that the deactivate button is shown appropriately"""
        u = UserFactory()
        r = self.client.get(reverse('users.profile', args=[u.username]))
        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=[u.username]))
        assert 'Deactivate this user' in r.content

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

        r = self.client.get(reverse('users.profile', args=[self.u.username]))
        assert 'Deactivate this user' not in r.content
Exemplo n.º 3
0
    def test_deactivate_button(self):
        """Check that the deactivate button is shown appropriately"""
        u = UserFactory()
        r = self.client.get(reverse('users.profile', args=[u.username]))
        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=[u.username]))
        assert 'Deactivate this user' in r.content

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

        r = self.client.get(reverse('users.profile', args=[self.u.username]))
        assert 'Deactivate this user' not in r.content
Exemplo n.º 4
0
    def test_questions_inactive_user(self):
        """Verify questions from inactive users aren't counted."""
        # Two questions for an inactive user.
        # They shouldn't show up in the count.
        u = UserFactory(is_active=False)
        QuestionFactory(creator=u)
        QuestionFactory(creator=u)

        r = self._get_api_result('api.kpi.questions')
        eq_(len(r['objects']), 0)

        # Activate the user, now the questions should count.
        u.is_active = True
        u.save()
        cache.clear()  # We need to clear the cache for new results.

        url = reverse('api.kpi.questions')
        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['questions'], 2)
Exemplo n.º 5
0
    def test_aaq_new_question_inactive(self, get_current):
        """New question is posted through mobile."""
        get_current.return_value.domain = 'testserver'

        # Log in first.
        u = UserFactory()
        self.client.login(username=u.username, password='******')

        # Then become inactive.
        u.is_active = False
        u.save()

        # Set 'in-aaq' for the session. It isn't already set because this
        # test doesn't do a GET of the form first.
        s = self.client.session
        s['in-aaq'] = True
        s.save()

        response = self._new_question(post_it=True)
        eq_(200, response.status_code)
        assert template_used(response, 'questions/mobile/confirm_email.html')
Exemplo n.º 6
0
    def test_questions_inactive_user(self):
        """Verify questions from inactive users aren't counted."""
        # Two questions for an inactive user.
        # They shouldn't show up in the count.
        u = UserFactory(is_active=False)
        QuestionFactory(creator=u)
        QuestionFactory(creator=u)

        r = self._get_api_result('api.kpi.questions')
        eq_(len(r['objects']), 0)

        # Activate the user, now the questions should count.
        u.is_active = True
        u.save()
        cache.clear()  # We need to clear the cache for new results.

        url = reverse('api.kpi.questions')
        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['questions'], 2)
Exemplo n.º 7
0
    def test_aaq_new_question_inactive(self, get_current):
        """New question is posted through mobile."""
        get_current.return_value.domain = 'testserver'

        # Log in first.
        u = UserFactory()
        self.client.login(username=u.username, password='******')

        # Then become inactive.
        u.is_active = False
        u.save()

        # Set 'in-aaq' for the session. It isn't already set because this
        # test doesn't do a GET of the form first.
        s = self.client.session
        s['in-aaq'] = True
        s.save()

        response = self._new_question(post_it=True)
        eq_(200, response.status_code)
        assert template_used(response, 'questions/mobile/confirm_email.html')