当前位置: 首页>>代码示例>>Python>>正文


Python test_views.TestClient类代码示例

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


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

示例1: RemoteAccessRequestModelTests

class RemoteAccessRequestModelTests(MyJobsBase):
    def setUp(self):
        super(RemoteAccessRequestModelTests, self).setUp()
        self.password = '[email protected]'
        self.client = TestClient()
        self.client.login(email=self.user.email, password=self.password)

        self.account_owner = UserFactory(email='[email protected]',
                                         password=self.password)
        self.impersonate_url = reverse('impersonate-start', kwargs={
            'uid': self.account_owner.pk})
        self.site = SeoSite.objects.first()

    def test_create_request_sends_messages(self):
        """
        The requesting of remote access should send both a My.jobs message
        and an email to the account owner.
        """
        msg = "User had %s messages, expected %s"
        mail.outbox = []
        spar = SecondPartyAccessRequest.objects.create(
            account_owner=self.account_owner, second_party=self.user,
            site=self.site, reason='just cuz')
        self.assertEqual(len(mail.outbox), 1)

        # We're logged in as the requesting user at this point and should
        # not have any messages.
        response = self.client.get(reverse('home'))
        self.assertEqual(len(response.context['new_messages']), 0,
                         msg=msg % (len(response.context['new_messages']), 0))

        response = self.client.get(reverse('impersonate-approve',
                                           kwargs={'access_id': spar.id}))
        self.assertEqual(response.status_code, 403,
                         msg=("Unauthorized approval of a request should not "
                              "happen but did"))

        # Log out then log in as the account owner.
        self.client.get(reverse('auth_logout'))
        self.client.login(email=self.account_owner.email,
                          password=self.password)
        response = self.client.get(reverse('home'))

        # We should now have one My.jobs message.
        messages = response.context['new_messages']
        self.assertEqual(len(messages), 1,
                         msg=msg % (len(response.context['new_messages']), 1))
        message = messages[0]
        email = mail.outbox[0]
        self.assertEqual(message.message.body, email.body,
                         msg="Message and email bodies were not identical")
        for text in ['>Allow<', '>Deny<', spar.reason,
                     self.user.get_full_name(default=self.user.email)]:
            self.assertTrue(text in email.body,
                            msg="%s not in email body" % text)
        response = self.client.get(reverse('impersonate-approve',
                                           kwargs={'access_id': spar.id}))
        spar = SecondPartyAccessRequest.objects.get(pk=spar.pk)
        self.assertEqual(spar.accepted, True,
                         msg="Acceptance status was not updated")
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:60,代码来源:test_models.py

示例2: TestDownloads

class TestDownloads(MyReportsTestCase):
    """Tests the reports view."""

    def setUp(self):
        super(TestDownloads, self).setUp()
        self.client = TestClient(path=reverse('downloads'),
                                 HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.client.login_user(self.user)

        ContactRecordFactory.create_batch(10, partner__owner=self.company)

    def test_column_order(self):
        """Tests that column order is preserved"""

        # create a report whose results is for all contact records in the
        # company
        response = self.client.post(
            path=reverse('reports', kwargs={
                'app': 'mypartners', 'model': 'contactrecord'}),
            data={'values': ['partner', 'contact__name', 'contact_type']})

        report_name = response.content
        report = Report.objects.get(name=report_name)

        response = self.client.get(data={'id': report.id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['columns'], {
            'Partner': True, 'Contact Name': True, 'Contact Type': True})
开发者ID:zeus911,项目名称:MyJobs,代码行数:28,代码来源:test_views.py

示例3: TestDownloadReport

class TestDownloadReport(MyReportsTestCase):
    """Tests that reports can be downloaded."""

    def setUp(self):
        super(TestDownloadReport, self).setUp()
        self.client = TestClient(path=reverse('download_report'))
        self.client.login_user(self.user)

        ContactRecordFactory.create_batch(5, partner__owner=self.company)
        ContactRecordFactory.create_batch(
            5, contact_type='job', job_applications=1,
            partner__owner=self.company)
        ContactRecordFactory.create_batch(
            5, contact_type='job',
            job_hires=1, partner__owner=self.company)

    def test_download_csv(self):
        """Test that a report can be downloaded in CSV format."""

        # create a report whose results is for all contact records in the
        # company
        response = self.client.post(path=reverse('reports', kwargs={
            'app': 'mypartners', 'model': 'contactrecord'}))
        report_name = response.content
        report = Report.objects.get(name=report_name)

        # download the report
        response = self.client.get(data={'id': report.pk})

        self.assertEqual(response['Content-Type'], 'text/csv')
开发者ID:zeus911,项目名称:MyJobs,代码行数:30,代码来源:test_views.py

示例4: TestDownloadReport

class TestDownloadReport(MyReportsTestCase):
    """Tests that reports can be downloaded."""

    def setUp(self):
        super(TestDownloadReport, self).setUp()
        self.client = TestClient(path=reverse("download_report"))
        self.client.login_user(self.user)

        ContactRecordFactory.create_batch(5, partner__owner=self.company)
        ContactRecordFactory.create_batch(5, contact_type="job", job_applications=1, partner__owner=self.company)
        ContactRecordFactory.create_batch(5, contact_type="job", job_hires=1, partner__owner=self.company)

    def test_download_csv(self):
        """Test that a report can be downloaded in CSV format."""

        # create a report whose results is for all contact records in the
        # company
        response = self.client.post(path=reverse("reports", kwargs={"app": "mypartners", "model": "contactrecord"}))
        report_name = response.content
        report = Report.objects.get(name=report_name)
        python = report.python

        # download the report
        response = self.client.get(data={"id": report.pk, "values": ["contact", "contact_email", "contact_phone"]})

        self.assertEqual(response["Content-Type"], "text/csv")

        # specifying export values shouldn't modify the underlying report
        self.assertEqual(len(python[0].keys()), len(report.python[0].keys()))
开发者ID:vfulco,项目名称:MyJobs,代码行数:29,代码来源:test_views.py

示例5: TestReportView

class TestReportView(MyReportsTestCase):
    """
    Tests the ReportView class, which is used to create and retrieve
    reports.
    """
    def setUp(self):
        super(TestReportView, self).setUp()
        self.client = TestClient(path=reverse('reports', kwargs={
            'app': 'mypartners', 'model': 'contactrecord'}))
        self.client.login_user(self.user)

        ContactRecordFactory.create_batch(5, partner__owner=self.company)
        ContactRecordFactory.create_batch(
            5, contact_type='job', job_applications=1,
            partner__owner=self.company)
        ContactRecordFactory.create_batch(
            5, contact_type='job',
            job_hires=1, partner__owner=self.company)

    def test_create_report(self):
        """Test that a report model instance is properly created."""

        # create a report whose results is for all contact records in the
        # company
        response = self.client.post()
        report_name = response.content
        report = Report.objects.get(name=report_name)

        self.assertEqual(len(report.python), 15)

        # we use this in other tests

        return report_name

    def test_get_report(self):
        """Test that chart data is retreived from record results."""

        report_name = self.test_create_report()
        report = Report.objects.get(name=report_name)

        response = self.client.get(data={'id': report.pk})
        data = json.loads(response.content)

        # check contact record stats
        for key in ['applications', 'hires', 'communications', 'emails']:
            self.assertEqual(data[key], 5)

        # check contact stats
        self.assertEqual(data['contacts'][0]['records'], 1)
        self.assertEqual(data['contacts'][0]['referrals'], 10)
开发者ID:abdulfiroz007,项目名称:MyJobs,代码行数:50,代码来源:test_views.py

示例6: MyReportsTestCase

class MyReportsTestCase(TestCase):
    """
    Base class for all MyReports Tests. Identical to `django.test.TestCase`
    except that it provides a MyJobs TestClient instance and a logged in user.
    """
    def setUp(self):
        self.client = TestClient()
        self.user = UserFactory(email='[email protected]')
        self.company = CompanyFactory(name='Test Company')
        self.partner = PartnerFactory(name='Test Partner', owner=self.company)

        # associate company to user
        CompanyUserFactory(user=self.user, company=self.company)

        self.client.login_user(self.user)
开发者ID:kepinae,项目名称:MyJobs,代码行数:15,代码来源:test_views.py

示例7: MyJobsHelpersTests

class MyJobsHelpersTests(MyJobsBase):
    def setUp(self):
        super(MyJobsHelpersTests, self).setUp()
        self.user = UserFactory()
        self.client = TestClient()

        self.login_params = {'username': '[email protected]',
                             'password': '[email protected]',
                             'action': 'login'}

    def test_login_dont_remember_me(self):
        self.assertEqual(Session.objects.count(), 0)
        response = self.client.post(reverse('home'),
                                    data=self.login_params)
        self.assertEqual(Session.objects.count(), 1)

        session = Session.objects.all()[0]

        session_dict = session.get_decoded()
        user_id = session_dict['_auth_user_id']
        self.assertEqual(user_id, self.user.id)

        # session.expire_date is tz aware; datetime.datetime.now is naive
        # It probably isn't worth it to bring in pytz just for tests
        now = datetime.datetime.now(session.expire_date.tzinfo)
        diff = session.expire_date - now

        # Due to the delay between the post at the top of this test
        # and reaching this line, this can't be an assertEquals;
        self.assertTrue(880 <= diff.total_seconds() <= 900)

    def test_login_remember_me(self):
        self.assertEqual(Session.objects.count(), 0)
        self.login_params['remember_me'] = True
        response = self.client.post(reverse('home'),
                                    data=self.login_params)
        self.assertEqual(Session.objects.count(), 1)

        session = Session.objects.all()[0]

        session_dict = session.get_decoded()
        user_id = session_dict['_auth_user_id']
        self.assertEqual(user_id, self.user.id)

        weeks = (datetime.datetime.now() + datetime.timedelta(days=14))
        # Session expiration should be two weeks from now - comparing number
        # of days should be good enough
        self.assertEqual(session.expire_date.toordinal(), weeks.toordinal())
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:48,代码来源:test_helpers.py

示例8: 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

示例9: setUp

 def setUp(self):
     super(TestSecureBlocks, self).setUp()
     self.staff_user = UserFactory(is_staff=True)
     self.client = TestClient()
     self.client.login_user(self.staff_user)
     self.sb_url = reverse('secure_blocks')
     SeoSiteFactory(domain='jobs.example.com')
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:7,代码来源:test_secure_blocks.py

示例10: setUp

    def setUp(self):
        super(MyJobsHelpersTests, self).setUp()
        self.client = TestClient()

        self.login_params = {'username': '[email protected]',
                             'password': '[email protected]',
                             'action': 'login'}
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:7,代码来源:test_helpers.py

示例11: setUp

 def setUp(self):
     super(UserResourceTestCase, self).setUp()
     create_api_key(User, instance=self.user, created=True)
     self.client = TestClient(
         path="/api/v1/user/",
         data={"email": "[email protected]", "username": self.user.email, "api_key": self.user.api_key.key},
     )
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:7,代码来源:test_api.py

示例12: setUp

    def setUp(self):
        super(TestDownloads, self).setUp()
        self.client = TestClient(path=reverse('downloads'),
                                 HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.client.login_user(self.user)

        ContactRecordFactory.create_batch(10, partner__owner=self.company)
开发者ID:kepinae,项目名称:MyJobs,代码行数:7,代码来源:test_views.py

示例13: setUp

    def setUp(self):
        super(MyDashboardViewsTests, self).setUp()
        self.staff_user = UserFactory()
        group = Group.objects.get(name=CompanyUser.GROUP_NAME)
        self.staff_user.groups.add(group)

        self.business_unit = BusinessUnitFactory()

        self.company = CompanyFactory(id=1)
        self.company.job_source_ids.add(self.business_unit)
        self.admin = CompanyUserFactory(user=self.staff_user,
                                        company=self.company)
        self.microsite = SeoSiteFactory()
        self.microsite.business_units.add(self.business_unit)

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

        self.candidate_user = UserFactory(email="[email protected]")
        SavedSearchFactory(user=self.candidate_user,
                           feed='http://test.jobs/jobs/feed/rss?',
                           url='http://test.jobs/search?q=django',
                           label='test Jobs')

        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,
                                   feed='http://test.jobs/jobs/feed/rss?',
                                   label='%s Jobs' % search)
        update_solr_task(settings.TEST_SOLR_INSTANCE)
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:34,代码来源:test_views.py

示例14: setUp

    def setUp(self):
        super(TestReportView, self).setUp()
        self.client = TestClient(path=reverse("reports", kwargs={"app": "mypartners", "model": "contactrecord"}))
        self.client.login_user(self.user)

        ContactRecordFactory.create_batch(5, partner__owner=self.company)
        ContactRecordFactory.create_batch(5, contact_type="job", job_applications=1, partner__owner=self.company)
        ContactRecordFactory.create_batch(5, contact_type="job", job_hires=1, partner__owner=self.company)
开发者ID:vfulco,项目名称:MyJobs,代码行数:8,代码来源:test_views.py

示例15: setUp

 def setUp(self):
     super(UserResourceTests, self).setUp()
     create_api_key(User, instance=self.user, created=True)
     self.client = TestClient(
         path='/api/v1/user/',
         data={'email': '[email protected]',
               'username': self.user.email,
               'api_key': self.user.api_key.key})
开发者ID:kepinq,项目名称:MyJobs,代码行数:8,代码来源:test_api.py


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