Exemplo n.º 1
0
    def test_not_disabled(self):
        """
        An anonymous user who provides the :verify-email: query string or
        user with is_disabled set to True should be redirected to the home
        page. An anonymous user who does not should see a 404. A user with
        is_active set to False should proceed to their destination.
        """
        client = TestClient()
        user = UserFactory()

        #Anonymous user
        resp = client.get(reverse('view_profile'))
        path = resp.request.get('PATH_INFO')
        self.assertRedirects(resp, reverse('home') + '?next=' + path)

        # This is ugly, but it is an artifact of the way Django redirects
        # users who fail the `user_passes_test` decorator.
        qs = '?verify-email=%s' % user.email
        next_qs = '?next=' + urlquote('/profile/view/%s' % qs)

        # Anonymous user navigates to url with :verify-email: in query string
        resp = client.get(reverse('view_profile') + qs)
        # Old path + qs is urlquoted and added to the url as the :next: param
        self.assertRedirects(resp, "http://testserver/" + next_qs)

        # Active user
        client.login_user(user)
        resp = client.get(reverse('view_profile'))
        self.assertTrue(resp.status_code, 200)

        #Disabled user
        user.is_disabled = True
        user.save()
        resp = client.get(reverse('view_profile'))
        self.assertRedirects(resp, "http://testserver/?next=/profile/view/")
Exemplo n.º 2
0
    def setUp(self):
        super(MySearchViewTests, self).setUp()
        self.client = TestClient()
        self.user = UserFactory()
        self.client.login_user(self.user)
        self.new_form_data = {
            'url': 'www.my.jobs/jobs',
            'feed': 'http://www.my.jobs/jobsfeed/rss?',
            'label': 'Jobs Label',
            'email': self.user.email,
            'frequency': 'D',
            'is_active': 'True',
            'sort_by': 'Relevance',
        }
        self.new_digest_data = {
            'is_active': 'True',
            'user': self.user,
            'email': self.user.email,
            'frequency': 'M',
            'day_of_month': 1,
        }
        self.new_form = forms.SavedSearchForm(user=self.user,
                                              data=self.new_form_data)

        self.r = Replacer()
        self.r.replace('urllib2.urlopen', return_file)
Exemplo n.º 3
0
    def setUp(self):
        self.staff_user = UserFactory()
        group = Group.objects.get(name=CompanyUser.GROUP_NAME)
        self.staff_user.groups.add(group)
        self.staff_user.save()

        self.company = CompanyFactory()
        self.company.save()
        self.admin = CompanyUserFactory(user=self.staff_user,
                                        company=self.company)
        self.admin.save()
        self.microsite = MicrositeFactory(company=self.company)
        self.microsite.save()

        self.client = TestClient()
        self.client.login_user(self.staff_user)

        self.candidate_user = UserFactory(email="*****@*****.**")
        SavedSearchFactory(user=self.candidate_user,
                           url='http://test.jobs/search?q=django',
                           label='test Jobs')
        self.candidate_user.save()

        for i in range(5):
            # Create 5 new users
            user = UserFactory(email='*****@*****.**' % i)
            for search in SEARCH_OPTS:
                # Create 15 new searches and assign three per user
                SavedSearchFactory(user=user,
                                   url='http://test.jobs/search?q=%s' % search,
                                   label='%s Jobs' % search)
Exemplo n.º 4
0
 def setUp(self):
     self.user = UserFactory()
     self.client = TestClient()
     create_api_key(User, instance=self.user, created=True)
     self.data = {'email': '*****@*****.**',
                  'username': self.user.email,
                  'api_key': self.user.api_key.key
     }
Exemplo n.º 5
0
    def setUp(self):
        self.user = UserFactory()
        self.auth_callback_url = 'https://secure.my.jobs/account'
        self.auth_callback = '?auth_callback=%s' % self.auth_callback_url
        self.key_qs = '%s&key=%s'

        self.client = TestClient()
        self.client.login_user(self.user)
Exemplo n.º 6
0
    def setUp(self):
        super(MyJobsHelpersTests, self).setUp()
        self.user = UserFactory()
        self.client = TestClient()

        self.login_params = {
            'username': '******',
            'password': '******',
            'action': 'login'
        }
Exemplo n.º 7
0
    def setUp(self):
        super(SavedSearchResourceTests, self).setUp()
        self.user = UserFactory()
        self.client = TestClient()
        self.data = {'email':'*****@*****.**', 'url':'www.my.jobs/jobs'}
        create_api_key(User, instance=self.user, created=True)

        self.credentials = (self.user.email, self.user.api_key.key)

        self.r = Replacer()
        self.r.replace('urllib2.urlopen', return_file)
Exemplo n.º 8
0
 def setUp(self):
     self.user = UserFactory()
     self.message = Message(subject='subject',
                            body='body',
                            message_type='success')
     self.message.save()
     for group in Group.objects.all():
         self.message.group.add(group.pk)
     self.message.save()
     self.messageInfo = MessageInfo(user=User.objects.get(id=1),
                                    message=self.message)
     self.messageInfo.save()
     self.client = TestClient()
     self.client.login_user(self.user)
Exemplo n.º 9
0
    def test_is_active(self):
        """
        A user with is_active set to False should be redirected to the home
        page, while a user with is_active set to True should proceed to their
        destination.
        """
        client = TestClient()
        user = UserFactory()
        quoted_email = urllib.quote(user.email)

        # Active user
        client.login_user(user)
        resp = client.get(reverse('saved_search_main'))
        self.assertTrue(resp.status_code, 200)

        # Inactive user
        user.is_active = False
        user.save()
        resp = client.get(reverse('saved_search_main'))
        self.assertRedirects(resp,
                             "http://testserver/?next=/saved-search/view/")
Exemplo n.º 10
0
    def setUp(self):
        """
        These tests use the default backend, since we know it's
        available; that needs to have ``ACCOUNT_ACTIVATION_DAYS`` set.

        """
        super(RegistrationViewTests, self).setUp()
        self.client = TestClient()
        self.old_activation = getattr(settings, 'ACCOUNT_ACTIVATION_DAYS',
                                      None)
        if self.old_activation is None:
            settings.ACCOUNT_ACTIVATION_DAYS = 7  # pragma: no cover

        self.data = {
            'email': '*****@*****.**',
            'password1': 'swordfish',
            'password2': 'swordfish',
            'action': 'register'
        }
        self.client.post(reverse('home'), data=self.data)
        self.user = User.objects.get(email=self.data['email'])
Exemplo n.º 11
0
    def test_group_status(self):
        """
        Should return True if user.groups contains the group specified and
        False if it does not.
        """
        client = TestClient()
        user = UserFactory()

        user.groups.all().delete()

        for group in Group.objects.all():
            # Makes a list of all group names, excluding the one that the
            # user will be a member of
            names = map(lambda group: group.name,
                        Group.objects.filter(~Q(name=group.name)))

            user.groups.add(group.pk)
            user.save()

            for name in names:
                self.assertFalse(User.objects.is_group_member(user, name))
            self.assertTrue(User.objects.is_group_member(user, group.name))

            user.groups.all().delete()
Exemplo n.º 12
0
 def setUp(self):
     super(MyProfileViewsTests, self).setUp()
     self.user = UserFactory()
     self.client = TestClient()
     self.client.login_user(self.user)
     self.name = PrimaryNameFactory(user=self.user)
Exemplo n.º 13
0
 def setUp(self):
     self.user = UserFactory()
     self.name = PrimaryNameFactory(user=self.user)
     self.client = TestClient()