本文整理汇总了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)
示例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))
示例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))
示例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))
示例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)
)
示例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
)
示例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,
}