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


Python testing.Client类代码示例

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


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

示例1: test_pages

    def test_pages(self):
        offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        student = Member.objects.get(offering=offering, person__userid='0aaa0')
        instr = Member.objects.get(offering=offering, person__userid='ggbaker')
        c = Client()
        c.login_user('ggbaker')

        test_views(self, c, 'offering:discipline:', ['index', 'new', 'newgroup', 'new_nonstudent'],
                   {'course_slug': offering.slug})

        cluster = DisciplineGroup(name='TheCluster', offering=offering)
        cluster.save()
        case = DisciplineCaseInstrStudent(student=student.person, owner=instr.person, offering=offering, group=cluster)
        case.save()

        test_views(self, c, 'offering:discipline:', ['showgroup'],
                   {'course_slug': offering.slug, 'group_slug': cluster.slug})
        test_views(self, c, 'offering:discipline:', ['show', 'edit_related', 'edit_attach', 'new_file'],
                   {'course_slug': offering.slug, 'case_slug': case.slug})

        # have a look at each form
        for step in STEP_FORM:
            test_views(self, c, 'offering:discipline:', ['edit_case_info'],
                       {'course_slug': offering.slug, 'case_slug': case.slug, 'field': step})

        # minimally-finish the case so we can check the letter
        case.letter_sent = 'MAIL'
        case.letter_text = 'foo'
        case.save()
        test_views(self, c, 'offering:discipline:', ['view_letter'],
                   {'course_slug': offering.slug, 'case_slug': case.slug})
开发者ID:sfu-fas,项目名称:coursys,代码行数:31,代码来源:tests.py

示例2: test_pages

    def test_pages(self):
        """
        Basic page rendering
        """
        crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        memb = Member.objects.get(offering=crs, person__userid="ggbaker")
        person = Person.objects.get(userid='ggbaker')

        p = Page(offering=crs, label="Index")
        p.save()
        v = PageVersion(page=p, title="Index Page", wikitext="Original Contents", editor=memb)
        v.save()
        p = Page(offering=crs, label="OtherPage")
        p.save()
        v = PageVersion(page=p, title="Other Page", wikitext="Original Contents", editor=memb)
        v.save()
        
        c = Client()
        c.login_user('ggbaker')
        
        # test the basic rendering of the core pages
        test_views(self, c, 'pages.views.', ['index_page', 'all_pages', 'new_page', 'new_file', 'import_site'],
                {'course_slug': crs.slug})

        test_views(self, c, 'pages.views.', ['view_page', 'page_history', 'edit_page', 'import_page'],
                {'course_slug': crs.slug, 'page_label': 'OtherPage'})
开发者ID:avacariu,项目名称:coursys,代码行数:26,代码来源:tests.py

示例3: test_grad_letters

    def test_grad_letters(self):
        """
        Check handling of letters for grad students
        """
        client = Client()
        test_auth(client, 'ggbaker')
        gs = GradStudent.objects.get(person__userid=self.gs_userid)

        # get template text and make sure substitutions are made
        lt = LetterTemplate.objects.get(label="Funding")
        url = reverse('grad.views.get_letter_text', kwargs={'grad_slug': gs.slug, 'letter_template_id': lt.id})
        response = client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'M Grad is making satisfactory progress')
        content = unicode(response.content)
        
        # create a letter with that content
        l = Letter(student=gs, date=datetime.date.today(), to_lines="The Student\nSFU", template=lt, created_by='ggbaker', content=content)
        l.save()
        url = reverse('grad.views.view_letter', kwargs={'grad_slug': gs.slug, 'letter_slug': l.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('grad.views.copy_letter', kwargs={'grad_slug': gs.slug, 'letter_slug': l.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
开发者ID:avacariu,项目名称:coursys,代码行数:26,代码来源:tests.py

示例4: test_course_credits_admin_200_ok

    def test_course_credits_admin_200_ok(self):
        raise SkipTest()
        client = Client()
        client.login_user("teachadm")

        url = reverse('planning.views.view_insts_in_unit')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.view_teaching_credits_admin', kwargs={'userid': 'ggbaker'})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.view_teaching_equivalent_admin', kwargs={'userid': 'ggbaker', 'equivalent_id': 1})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.new_teaching_equivalent_admin', kwargs={'userid': 'ggbaker'})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.edit_teaching_equivalent_admin', kwargs={'userid': 'ggbaker', 'equivalent_id': 1})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.edit_course_offering_credits', kwargs={'userid': 'ggbaker', 'course_slug': TEST_COURSE_SLUG})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
开发者ID:avacariu,项目名称:coursys,代码行数:28,代码来源:disabled-tests.py

示例5: test_workflow

    def test_workflow(self):
        """
        Test the privacy policy workflow and page exclusions
        """
        # clear privacy agreement from test data
        p = Person.objects.get(userid='dzhao')
        p.config = {}
        p.save()

        client = Client()
        client.login_user(p.userid)
        privacy_url = reverse('privacy.views.privacy')

        # non-role page should still render
        url = reverse('dashboard.views.index')
        basic_page_tests(self, client, url)

        # but role page should redirect to agreement
        url = reverse('advisornotes.views.advising')
        response = client.get(url)
        self.assertRedirects(response, privacy_url + '?next=' + url)

        # check privacy page
        basic_page_tests(self, client, privacy_url)

        # submit and expect recorded agreement
        response = client.post(privacy_url + '?next=' + url, {'agree': 'on'})
        self.assertRedirects(response, url)
        p = Person.objects.get(userid='dzhao')
        self.assertTrue(p.config['privacy_signed'])

        # now we should be able to access
        basic_page_tests(self, client, url)
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:33,代码来源:tests.py

示例6: test_redirect

    def test_redirect(self):
        """
        Redirecting with redirect stub
        """
        crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        memb = Member.objects.get(offering=crs, person__userid="ggbaker")

        p = Page(offering=crs, label="Test")
        p.save()
        v = PageVersion(page=p, title="Test Page", wikitext="one +two+ three +four+", editor=memb)
        v.save()

        c = Client()
        # normal pages still viewable
        url = reverse('offering:pages:view_page', kwargs={'course_slug': crs.slug, 'page_label': 'Test'})
        response = c.get(url)
        self.assertEqual(response.status_code, 200)

        v = PageVersion(page=p, redirect='NewLocation', editor=memb)
        v.save()

        response = c.get(url)
        self.assertEqual(response.status_code, 301)
        redir_url = reverse('offering:pages:view_page', kwargs={'course_slug': crs.slug, 'page_label': 'NewLocation'})
        self.assertTrue(response['location'].endswith(redir_url))
开发者ID:sfu-fas,项目名称:coursys,代码行数:25,代码来源:tests.py

示例7: test_api

 def test_api(self):
     crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
     memb = Member.objects.get(offering=crs, person__userid="ggbaker")
     person = Person.objects.get(userid='ggbaker')
     p = Page(offering=crs, label="PageExists")
     p.save()
     v = PageVersion(page=p, title="Page Exists", wikitext="Original Contents", editor=memb, comment="original page")
     v.save()
     
     from dashboard.models import new_feed_token
     token = new_feed_token()
     
     updata = u"""{
         "userid": "ggbaker",
         "token": "%s",
         "pages": [
             {
                 "label": "Index",
                 "title": "The Coursé Page",
                 "can_read": "ALL",
                 "can_write": "INST",
                 "wikitext-base64": "VGhpcyBwYWdlIGlzIHNwZWNpYWwgaW4gKipzb21lKiogd2F5LiBcKHh+XjIrMSA9IFxmcmFjezF9ezJ9XCkuCgpHb29kYnllIHdvcmxkIQ==",
                 "comment": "page creation comment",
                 "use_math": true
             },
             {
                 "label": "PageExists",
                 "new_label": "PageChanged",
                 "title": "Another Page",
                 "can_read": "STUD",
                 "wikitext": "This is some **new** page\\n\\ncontent."
             }
         ]
     }""" % (token)
     
     # make a request with no auth token in place
     c = Client()
     url = reverse('pages.views.api_import', kwargs={'course_slug': crs.slug})
     response = c.post(url, data=updata.encode('utf8'), content_type="application/json")
     self.assertEquals(response.status_code, 403)
     
     # create token and try again
     person.config['pages-token'] = token
     person.save()
     response = c.post(url, data=updata.encode('utf8'), content_type="application/json")
     self.assertEquals(response.status_code, 200)
     
     # make sure the data arrived
     self.assertEquals(Page.objects.filter(offering=crs, label="PageExists").count(), 0)
     p = Page.objects.get(offering=crs, label="PageChanged")
     v = p.current_version()
     self.assertEqual(v.title, "Another Page")
     self.assertEqual(v.get_wikitext(), "This is some **new** page\n\ncontent.")
     
     p = Page.objects.get(offering=crs, label="Index")
     v = p.current_version()
     self.assertEqual(v.title, u"The Cours\u00e9 Page")
     self.assertEqual(v.get_wikitext(), 'This page is special in **some** way. \\(x~^2+1 = \\frac{1}{2}\\).\n\nGoodbye world!')
     self.assert_('math' in v.config)
     self.assertEqual(v.config['math'], True)
开发者ID:avacariu,项目名称:coursys,代码行数:60,代码来源:tests.py

示例8: test_new_nonstudent_post_failure

 def test_new_nonstudent_post_failure(self):
     client = Client()
     client.login_user("dzhao")
     response = client.post(reverse('advisornotes.views.new_nonstudent'), {'first_name': 'test123'})
     self.assertEqual(response.status_code, 200, "Should be brought back to form")
     q = NonStudent.objects.filter(first_name='test123')
     self.assertEqual(len(q), 0, "Nonstudent should not have been created")
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:7,代码来源:tests.py

示例9: test_rest_notes_emplid_doesnt_exist

 def test_rest_notes_emplid_doesnt_exist(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_doesnt_exist.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Emplid '321' doesn't exist")
开发者ID:avacariu,项目名称:coursys,代码行数:8,代码来源:tests.py

示例10: test_rest_notes_invalid_UTF8

 def test_rest_notes_invalid_UTF8(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_bad_utf8.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.content, 'Bad UTF-8 encoded text')
开发者ID:avacariu,项目名称:coursys,代码行数:8,代码来源:tests.py

示例11: test_rest_notes_bad_base64

 def test_rest_notes_bad_base64(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_bad_base64.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Invalid base64 data for note file attachment")
开发者ID:avacariu,项目名称:coursys,代码行数:8,代码来源:tests.py

示例12: test_rest_notes_emplid_not_int

 def test_rest_notes_emplid_not_int(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_not_int.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Note emplid must be an integer")
开发者ID:avacariu,项目名称:coursys,代码行数:8,代码来源:tests.py

示例13: test_rest_notes_emplid_text_missing

 def test_rest_notes_emplid_text_missing(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_missing.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Emplid or text not present in note")
开发者ID:avacariu,项目名称:coursys,代码行数:8,代码来源:tests.py

示例14: test_rest_notes_empty_list

 def test_rest_notes_empty_list(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_empty.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "No advising notes present")
开发者ID:avacariu,项目名称:coursys,代码行数:8,代码来源:tests.py

示例15: test_rest_notes_missing_credential

 def test_rest_notes_missing_credential(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_missing_credential.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "The key 'secret' is not present. ")
开发者ID:avacariu,项目名称:coursys,代码行数:8,代码来源:tests.py


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