• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python factories.UserFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中myjobs.tests.factories.UserFactory的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了UserFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_search_updates_facet_counts

    def test_search_updates_facet_counts(self):
        # Add ProfileData to the candidate_user
        EducationFactory(user=self.candidate_user)
        AddressFactory(user=self.candidate_user)
        LicenseFactory(user=self.candidate_user)
        self.candidate_user.save()

        # Create a new user with ProfileData
        user = UserFactory(email="[email protected]")
        SavedSearchFactory(user=user,
                           url='http://test.jobs/search?q=python',
                           feed='http://test.jobs/jobs/feed/rss?',
                           label='Python Jobs')
        EducationFactory(user=user)
        AddressFactory(user=user)
        LicenseFactory(user=user)
        user.save()

        update_solr_task(settings.TEST_SOLR_INSTANCE)

        # Assert there are two users with country codes
        country_tag = '#Country-details-table .facet-count'
        q = '?company={company}'
        q = q.format(company=str(self.company.id))
        response = self.client.post(reverse('dashboard') + q)
        soup = BeautifulSoup(response.content)
        self.assertEqual(int(soup.select(country_tag)[0].text), 2)

        # When we search, the facet count updates.
        q = '?company={company}&search={search}'
        q = q.format(company=str(self.company.id), search='find')
        response = self.client.post(reverse('dashboard') + q)
        soup = BeautifulSoup(response.content)
        self.assertEqual(int(soup.select(country_tag)[0].text), 1)
开发者ID:kepinq,项目名称:MyJobs,代码行数:34,代码来源:test_views.py


示例2: test_bad_events_deactivate_user

    def test_bad_events_deactivate_user(self):
        now = datetime.datetime.now()
        for event in STOP_SENDING + BAD_EMAIL:
            u = UserFactory(email="[email protected]",
                            is_verified=True, opt_in_myjobs=True)
            self.make_email_logs(u.email, event, now, False, 3)
            process_batch_events()

            u = User.objects.get(pk=u.pk)
            self.assertEqual(u.deactivate_type, event)
            # Users start this test case with is_verified=True
            # is_verified should only change if the modifying event
            # is a block or drop
            self.assertEqual(u.is_verified, event in STOP_SENDING)
            self.assertFalse(u.opt_in_myjobs)

            infos = u.messageinfo_set.all()
            self.assertEqual(len(infos), 1)
            message = infos[0].message

            if u.deactivate_type in STOP_SENDING:
                text = 'stop communications'
            else:
                text = 'Attempts to send messages to'
            self.assertTrue(text in message.body)

            EmailLog.objects.all().delete()
            u.delete()
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:28,代码来源:test_tasks.py


示例3: test_not_disabled

    def test_not_disabled(self):
        """
        An anonymous user who provides the :verify: 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=%s' % user.user_guid
        next_qs = '?next=' + urlquote('/profile/view/%s' % qs)

        # Anonymous user navigates to url with :verify: 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/")
开发者ID:wejhink,项目名称:MyJobs,代码行数:35,代码来源:test_models.py


示例4: test_non_staff_user

 def test_non_staff_user(self):
     self.client.logout()
     user = UserFactory(email='[email protected]')
     user.set_password('secret')
     self.client.login(username=user.email, password='secret')
     response = self.client.get(reverse('source_code_upload'))
     self.assertTrue('Log in' in response.content)
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:7,代码来源:test_source_codes.py


示例5: setUp

    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="[email protected]")
        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='example%[email protected]' % 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)
开发者ID:jpaezsa,项目名称:MyJobs,代码行数:31,代码来源:views.py


示例6: SavedSearchTemplateTagTests

class SavedSearchTemplateTagTests(MyJobsBase):
    def setUp(self):
        super(SavedSearchTemplateTagTests, self).setUp()
        self.user = UserFactory(is_active=True)
        self.search = SavedSearchFactory(user=self.user)

    def test_confirm_creation_active_user(self):
        expected = reverse('view_full_feed') + '?id={id}&verify={guid}'.format(
            id=self.search.pk, guid=self.user.user_guid)
        actual = get_created_url(self.search)

        self.assertEqual(actual, expected)

    def test_confirm_creation_inactive_user(self):
        self.user.is_active = False
        self.user.save()

        user_with_profile = UserFactory(email='[email protected]',
                                        is_active=False)
        profile_search = SavedSearchFactory(user=user_with_profile)
        ActivationProfile.objects.create(user=user_with_profile,
                                         email=user_with_profile.email)

        for saved_search in [self.search, profile_search]:
            actual = get_created_url(saved_search)

            profile = ActivationProfile.objects.get(user=saved_search.user)
            expected = reverse('registration_activate',
                               args=[profile.activation_key]) + \
                '?verify={guid}'.format(guid=saved_search.user.user_guid)
            self.assertEqual(actual, expected)
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:31,代码来源:test_templatetags.py


示例7: SavedSearchDeletionTests

class SavedSearchDeletionTests(MyJobsBase):
    # Creating an entire test class for this is kind of overkill but it doesn't
    # fit with any of the others.
    def setUp(self):
        super(SavedSearchDeletionTests, self).setUp()
        self.user = UserFactory()
        self.creator = UserFactory(email='[email protected]')
        self.search = SavedSearchFactory(user=self.user)
        self.partner_search = PartnerSavedSearchFactory(user=self.user,
                                                        created_by=self.creator)

    def test_deletion_and_preservation(self):
        """
        When a user is deleted, that user's saved searches should be deleted.
        Partner saved searches should be left alone with the exception of
        nullifying the recipient.
        """
        mail.outbox = []
        self.assertEqual(MessageInfo.objects.count(), 0)
        self.user.delete()
        with self.assertRaises(SavedSearch.DoesNotExist):
            SavedSearch.objects.get(pk=self.search.pk)
        SavedSearch.objects.get(pk=self.partner_search.pk)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(MessageInfo.objects.count(), 1)
开发者ID:zeus911,项目名称:MyJobs,代码行数:25,代码来源:test_models.py


示例8: test_message_made_sent_to_multiple

 def test_message_made_sent_to_multiple(self):
     """
     Test that one message can be received by multiple users.
     """
     user = UserFactory(email="[email protected]")
     user.groups.add(Group.objects.get(id=1))
     user.claim_messages()
     self.assertEqual(Message.objects.count(), 1)
     self.assertEqual(MessageInfo.objects.count(), 2)
     self.assertEqual(self.message,
                      self.user.messageinfo_set.get().message)
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:11,代码来源:test_models.py


示例9: NewUserTests

class NewUserTests(SeleniumTestCase):

    """Tests Account creation"""

    def setUp(self):
        self.user = UserFactory(first_name="John", last_name="Doe")

    def test_home_page_works(self):
        """
        As John, navigating to https://secure.my.jobs should send me to a page
        titled "My.jobs".
        """
        self.browser.get(self.live_server_url)
        self.assertIn(self.browser.title, 'My.jobs')

    def test_cant_log_in_without_account(self):
        """
        As John, I shouldn't be able to log into My.jobs without registering
        first.
        """
        self.browser.get('/'.join([self.live_server_url, 'prm', 'view']))

        # attempt to log in
        username = self.find('id_username')
        username.send_keys(self.user.email)
        self.find('id_password').send_keys(self.user.password)
        self.find('login').click()

        self.assertEqual(username.get_attribute('placeholder'),
                         'Please enter a correct email.')

    def test_user_registration(self):
        """
        As John, I should be able to register on My.jobs and log in.
        """
        user = UserFactory.build(email='[email protected]')
        self.browser.get('/'.join([self.live_server_url, 'prm', 'view']))

        # register
        self.find('id_email').send_keys(user.email)
        self.find('id_password1').send_keys(user.password)
        self.find('id_password2').send_keys(user.password)
        self.find('register').click()

        self.assertEqual(self.find('profile').get_attribute(
            'innerHTML'),
            'Skip: Take me to my profile')

    def test_user_login(self):
        self.user.set_password("test")
        self.user.save()
        self.find('id_username').send_keys(self.user.email)
        self.find('id_password').send_keys("test")
        self.find('login').click()
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:54,代码来源:test_mypartners.py


示例10: MessageManagerTests

class MessageManagerTests(MyJobsBase):
    def setUp(self):
        super(MessageManagerTests, self).setUp()
        self.user = UserFactory()
        self.user.groups.add(Group.objects.get(pk=1))

    def test_create_message_by_group(self):
        message = Message.objects.create_message(
            subject='subject', body='message body',
            groups=Group.objects.all())

        self.user.claim_messages()

        infos = self.user.messageinfo_set.all()
        self.assertEqual(len(infos), 1)
        self.assertEqual(infos[0].message, message)

    def test_create_message_creates_messageinfo(self):
        message = Message.objects.create_message(
            users=self.user, subject='subject', body='message body')

        infos = MessageInfo.objects.all()
        self.assertEqual(infos.count(), 1)
        self.assertEqual(infos[0].user, self.user)
        self.assertEqual(infos[0].message, message)

    def test_create_message_with_users_and_groups(self):
        new_user = UserFactory(email='[email protected]')
        message = Message.objects.create_message(
            users=new_user, subject='subject', body='message body',
            groups=Group.objects.get(pk=1))

        [user.claim_messages() for user in [new_user, self.user]]
        get_messages = lambda u: list(u.message_set.all())

        group_user_messages = get_messages(self.user)
        new_user_messages = get_messages(new_user)

        self.assertEqual(group_user_messages, new_user_messages)
        self.assertEqual(len(group_user_messages), 1)
        self.assertEqual(group_user_messages[0], message)

    def test_create_message_sets_expiration(self):
        message = Message.objects.create_message(
            subject='subject', body='message body',
            groups=Group.objects.get(pk=1), expires=False)

        self.assertTrue(message.expire_at is None)
        self.user.claim_messages()
        info = self.user.messageinfo_set.first()
        self.assertFalse(info.expired_time())
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:51,代码来源:test_models.py


示例11: test_activities

    def test_activities(self):
        """
        `User.get_activities(company)` should return a list of activities
        associated with this user and company.

        """
        user = UserFactory(email="[email protected]")

        self.assertItemsEqual(user.get_activities(self.company), [])

        user.roles.add(self.role)
        activities = self.role.activities.values_list('name', flat=True)

        self.assertItemsEqual(user.get_activities(self.company), activities)
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:14,代码来源:test_models.py


示例12: test_deleting_user_does_not_cascade

    def test_deleting_user_does_not_cascade(self):
        """
        Deleting a user shouldn't delete related objects such as partner saved
        searches and reports.
        """

        user = UserFactory(email="[email protected]")
        company = CompanyFactory()
        pss = PartnerSavedSearchFactory(created_by=user)
        report = Report.objects.create(created_by=user, owner=company)

        user.delete()
        self.assertIn(pss, PartnerSavedSearch.objects.all())
        self.assertIn(report, Report.objects.all())
开发者ID:wejhink,项目名称:MyJobs,代码行数:14,代码来源:test_models.py


示例13: test_gravatar_url

 def test_gravatar_url(self):
     """
     Test that email is hashed correctly and returns a 200 response
     """
     user = UserFactory()
     gravatar_url = "http://www.gravatar.com/avatar/c160f8cc69a4f0b" \
                           "f2b0362752353d060?s=20&d=mm"
     no_gravatar_url = ("<div class='gravatar-blank gravatar-danger' "
                            "style='height: 20px; width: 20px'>"
                            "<span class='gravatar-text' "
                            "style='font-size:13.0px;'>A</span></div>")
     generated_gravatar_url = user.get_gravatar_url()
     self.assertEqual(no_gravatar_url, generated_gravatar_url)
     status_code = urllib.urlopen(gravatar_url).getcode()
     self.assertEqual(status_code, 200)
开发者ID:wejhink,项目名称:MyJobs,代码行数:15,代码来源:test_models.py


示例14: RedirectMiddlewareTests

class RedirectMiddlewareTests(MyJobsBase):
    def setUp(self):
        super(RedirectMiddlewareTests, self).setUp()
        self.user = UserFactory()
        self.redirect_middleware = PasswordChangeRedirectMiddleware()
        self.request_factory = RequestFactory()

    def test_logged_in_no_redirect(self):
        """
        A logged in user whose password_change flag is not set
        should proceed to their original destination
        """
        request = self.request_factory.get(reverse('edit_account'))
        request.user = self.user
        response = self.redirect_middleware.process_request(request)
        self.assertEqual(response, None)

    def test_logged_in_autocreated_user_redirects(self):
        """
        A logged in user whose password_change flag is set should
        be redirected to the password change form
        """
        self.user.password_change = True
        self.user.save()

        request = self.request_factory.get(reverse('saved_search_main'))
        request.user = self.user

        response = self.redirect_middleware.process_request(request)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.get('location'),
                         reverse('edit_account')+"#as-password")

    def test_not_logged_in_returns_forbidden(self):
        """
        An anonymous user that tries to post to a private url should
        receive a 403 Forbidden status
        """
        request = self.request_factory.get(reverse('saved_search_main'),
                                           HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        new_request = request.GET.copy()
        new_request['next'] = reverse('home')
        request.GET = new_request
        request.REQUEST.dicts = (new_request, request.POST)
        request.user = AnonymousUser()
        response = self.redirect_middleware.process_request(request)
        self.assertEqual(response.status_code, 403)
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:48,代码来源:test_middleware.py


示例15: setUp

    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',
            'jobs_per_email': 5,
            '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.patcher = patch('urllib2.urlopen', return_file())
        self.patcher.start()
开发者ID:wejhink,项目名称:MyJobs,代码行数:27,代码来源:test_views.py


示例16: setUp

 def setUp(self):
     super(AdminTests, self).setUp()
     self.site = AdminSite()
     settings.SITE = SeoSite.objects.first()
     self.request = RequestFactory().get("/")
     self.user = UserFactory(is_superuser=True)
     self.request.user = self.user
开发者ID:abdulfiroz007,项目名称:MyJobs,代码行数:7,代码来源:test_admin.py


示例17: AccountFormTests

class AccountFormTests(MyJobsBase):
    def setUp(self):
        super(AccountFormTests, self).setUp()
        self.user = UserFactory()
        self.name = PrimaryNameFactory(user=self.user)
        
    def test_password_form(self):
        invalid_data = [
            { 'data': {'password': 'cats',
                       'new_password1': '7dY=Ybtk',
                       'new_password2': '7dY=Ybtk'},
              u'errors': [['password', [u"Wrong password."]]]},
            { 'data': {'password': '[email protected]',
                       'new_password1': '7dY=Ybtk',
                       'new_password2': 'notnewpassword'},
                u'errors':
                    [[u'new_password2', [u'The new password fields did not match.']],
                    [u'new_password1', [u'The new password fields did not match.']]],
            
            },
        ]

        for item in invalid_data:
            form = ChangePasswordForm(user=self.user, data=item['data'])
            self.failIf(form.is_valid())
            self.assertEqual(form.errors[item[u'errors'][0][0]],
                             item[u'errors'][0][1])

        form = ChangePasswordForm(user=self.user,data={'password': '[email protected]',
                                                       'new_password1': '7dY=Ybtk',
                                                       'new_password2': '7dY=Ybtk'})
        
        self.failUnless(form.is_valid())
        form.save()
        self.failUnless(self.user.check_password('7dY=Ybtk'))
开发者ID:kepinae,项目名称:MyJobs,代码行数:35,代码来源:test_forms.py


示例18: setUp

 def setUp(self):
     super(SavedSearchDeletionTests, self).setUp()
     self.user = UserFactory()
     self.creator = UserFactory(email='[email protected]')
     self.search = SavedSearchFactory(user=self.user)
     self.partner_search = PartnerSavedSearchFactory(user=self.user,
                                                     created_by=self.creator)
开发者ID:zeus911,项目名称:MyJobs,代码行数:7,代码来源:test_models.py


示例19: setUp

    def setUp(self):
        super(EmailForwardTests, self).setUp()
        self.redirect_guid = JOB['guid']
        self.redirect = RedirectFactory(buid=JOB['buid'],
                                        guid='{%s}' %
                                             uuid.UUID(self.redirect_guid))

        self.password = 'secret'
        self.user = UserFactory(email='[email protected]')
        self.user.set_password(self.password)
        self.user.save()

        self.contact = CompanyEmail.objects.create(
            buid=self.redirect.buid,
            email=self.user.email)

        self.email = self.user.email.replace('@', '%40')
        self.auth = {
            'bad': [
                '',
                'Basic %s' % base64.b64encode('bad%40email:wrong_pass')],
            'good':
                'Basic %s' % base64.b64encode('%s:%s' % (self.user.email.\
                                                         replace('@', '%40'),
                                                         self.password))}
        self.post_dict = {'to': '[email protected]',
                          'from': '[email protected]',
                          'text': 'Questions about stuff',
                          'html': '<b>Questions about stuff</b>',
                          'subject': 'Bad Email',
                          'attachments': 0}

        self.r = Replacer()
        self.r.replace('pysolr.Solr.search', mock_search)
开发者ID:vfulco,项目名称:MyJobs,代码行数:34,代码来源:test_views.py


示例20: setUp

    def setUp(self):
        super(SavedSearchHelperTests, self).setUp()
        self.user = UserFactory()
        self.valid_url = 'http://www.my.jobs/jobs?location=chicago&q=nurse'

        self.patcher = patch('urllib2.urlopen', return_file())
        self.patcher.start()
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:7,代码来源:test_helpers.py



注:本文中的myjobs.tests.factories.UserFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_views.TestClient类代码示例发布时间:2022-05-27
下一篇:
Python _misc._Label函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap