當前位置: 首頁>>代碼示例>>Python>>正文


Python factory.Iterator方法代碼示例

本文整理匯總了Python中factory.Iterator方法的典型用法代碼示例。如果您正苦於以下問題:Python factory.Iterator方法的具體用法?Python factory.Iterator怎麽用?Python factory.Iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在factory的用法示例。


在下文中一共展示了factory.Iterator方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_program_page

# 需要導入模塊: import factory [as 別名]
# 或者: from factory import Iterator [as 別名]
def test_program_page(browser, base_test_data, logged_in_student):
    """
    Test viewing the program page
    """
    courses = list(base_test_data.program.course_set.all()) + \
        CourseFactory.create_batch(2, program=base_test_data.program)
    page = ProgramPageFactory.create(program=base_test_data.program, title="A Program Title")
    faculty = FacultyFactory.create_batch(3, program_page=page)
    info_links = InfoLinksFactory.create_batch(3, program_page=page)
    semester_dates = SemesterDateFactory.create_batch(3, program_page=page)
    program_courses = ProgramCourseFactory.create_batch(
        len(courses),
        program_page=page,
        course=Iterator(courses)
    )

    browser.get("/a-program-title/")
    faculty_elements = browser.driver.find_elements_by_css_selector(".faculty-tile")
    assert len(faculty) == len(faculty_elements)
    info_elements = browser.driver.find_elements_by_css_selector(".program-contact-link")
    assert len(info_links) == len(info_elements)
    semester_elements = browser.driver.find_elements_by_css_selector(".semester-date")
    assert len(semester_dates) == len(semester_elements)
    program_course_elements = browser.driver.find_elements_by_css_selector(".program-course .course-row")
    assert len(program_courses) == len(program_course_elements) 
開發者ID:mitodl,項目名稱:micromasters,代碼行數:27,代碼來源:basic_test.py

示例2: test_index

# 需要導入模塊: import factory [as 別名]
# 或者: from factory import Iterator [as 別名]
def test_index(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        QuestionFactory.create_batch(len(models.Question.STATUS_CHOICES),
                                     status=factory.Iterator([i[0] for i in models.Question.STATUS_CHOICES]))

        response = views.question_admin_index(request)
        self.assertEqual(response.status_code, 200)

        expected_questions = models.Question.objects.all()
        self.assertEqual(list(response.context_data["questions"]), list(expected_questions)) 
開發者ID:Inboxen,項目名稱:Inboxen,代碼行數:12,代碼來源:tests.py

示例3: test_index

# 需要導入模塊: import factory [as 別名]
# 或者: from factory import Iterator [as 別名]
def test_index(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        BlogPostFactory.create_batch(2, draft=factory.Iterator([True, False]), author=self.user)

        response = views.blog_admin_index(request)
        self.assertEqual(response.status_code, 200)

        expected_posts = models.BlogPost.objects.all()
        self.assertEqual(list(response.context_data["posts"]), list(expected_posts)) 
開發者ID:Inboxen,項目名稱:Inboxen,代碼行數:11,代碼來源:tests.py

示例4: test_index

# 需要導入模塊: import factory [as 別名]
# 或者: from factory import Iterator [as 別名]
def test_index(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        factories.DomainFactory.create_batch(2, enabled=factory.Iterator([True, False]))

        response = admin.domain_admin_index(request)
        self.assertEqual(response.status_code, 200)

        expected_domains = models.Domain.objects.all()
        self.assertEqual(list(response.context_data["domains"]), list(expected_domains)) 
開發者ID:Inboxen,項目名稱:Inboxen,代碼行數:11,代碼來源:test_admin.py

示例5: test_filter_and_sorting

# 需要導入模塊: import factory [as 別名]
# 或者: from factory import Iterator [as 別名]
def test_filter_and_sorting(self, staff_client, program_data, fin_aid_status, sort_param):
        """
        Tests ReviewFinancialAidView correctly applies sort and filter parameters, or
        uses defaults for those parameters
        """
        FinancialAidFactory.create_batch(
            10,
            tier_program=program_data.tier_programs["0k"],
            status=factory.Iterator([
                ReviewFinancialAidView.default_status,
                FinancialAidStatus.AUTO_APPROVED
            ])
        )
        url = self.review_url(program_data.program.id, status=fin_aid_status, sort_param=sort_param)
        resp = staff_client.get(url)
        assert resp.status_code == status.HTTP_200_OK
        financial_aid_objects = resp.context_data["financial_aid_objects"]

        # View should filter FinancialAid objects by the provided status or a default status
        expected_status = fin_aid_status or ReviewFinancialAidView.default_status
        assert all(fin_aid.status == expected_status for fin_aid in financial_aid_objects)
        # View should sort by the given parameter, or sort by ascending last name by default
        should_reverse_sort = sort_param == '-last_name'
        assert (
            list(financial_aid_objects) ==
            sorted(financial_aid_objects, key=lambda f: f.user.last_name, reverse=should_reverse_sort)
        ) 
開發者ID:mitodl,項目名稱:micromasters,代碼行數:29,代碼來源:views_pytest_test.py

示例6: test_view_with_search

# 需要導入模塊: import factory [as 別名]
# 或者: from factory import Iterator [as 別名]
def test_view_with_search(self, staff_client, program_data):
        """
        Tests that ReviewFinancialAidView returns the expected results with search
        """
        fin_aid_status = FinancialAidStatus.AUTO_APPROVED
        profiles = ProfileFactory.create_batch(
            4,
            first_name=factory.Iterator(['match_name', 'x', 'y', 'z']),
            last_name=factory.Iterator(['x', 'y', 'z', 'match_name']),
        )
        FinancialAidFactory.create_batch(
            4,
            tier_program=program_data.tier_programs["0k"],
            status=fin_aid_status,
            user=factory.Iterator([p.user for p in profiles])
        )
        name_query = 'match_name'
        url = self.review_url(program_data.program.id, status=fin_aid_status, search_param=name_query)
        resp = staff_client.get(url)
        assert resp.status_code == status.HTTP_200_OK
        financial_aid_objects = resp.context_data["financial_aid_objects"]

        # Two users should match the search term - one for first_name, one for last_name
        assert len(financial_aid_objects) == 2
        assert all(
            name_query in (fin_aid.user.profile.first_name, fin_aid.user.profile.last_name)
            for fin_aid in financial_aid_objects
        ) 
開發者ID:mitodl,項目名稱:micromasters,代碼行數:30,代碼來源:views_pytest_test.py

示例7: test_context

# 需要導入模塊: import factory [as 別名]
# 或者: from factory import Iterator [as 別名]
def test_context(self):
        """
        Assert context values for logged in user
        """
        with mute_signals(post_save):
            profile = ProfileFactory.create()
        self.client.force_login(profile.user)

        # ProgramFaculty and ProgramCourse are asserted via ProgramPageSerializer below
        FacultyFactory.create_batch(3, program_page=self.program_page)
        courses = self.program_page.program.course_set.all()
        ProgramCourseFactory.create_batch(
            len(courses), program_page=self.program_page, course=Iterator(courses)
        )

        ga_tracking_id = FuzzyText().fuzz()
        with self.settings(
            GA_TRACKING_ID=ga_tracking_id,
            ENVIRONMENT='environment',
            VERSION='version',
        ):
            response = self.client.get(self.program_page.url)
            assert response.context['authenticated'] is True
            assert response.context['username'] is None
            assert response.context['title'] == self.program_page.title
            assert response.context['is_public'] is True
            assert response.context['has_zendesk_widget'] is True
            assert response.context['is_staff'] is False
            self.assertContains(response, 'Share this page')
            js_settings = json.loads(response.context['js_settings_json'])
            assert js_settings == {
                'gaTrackingID': ga_tracking_id,
                'environment': 'environment',
                'sentry_dsn': "",
                'host': 'testserver',
                'release_version': 'version',
                'user': serialize_maybe_user(profile.user),
                'program': ProgramPageSerializer(self.program_page).data,
            } 
開發者ID:mitodl,項目名稱:micromasters,代碼行數:41,代碼來源:views_test.py


注:本文中的factory.Iterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。