Python factory.Iterator() Examples
The following are 7
code examples of factory.Iterator().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
factory
, or try the search function
.
Example #1
Source File: basic_test.py From micromasters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #2
Source File: tests.py From Inboxen with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #3
Source File: tests.py From Inboxen with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #4
Source File: test_admin.py From Inboxen with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #5
Source File: views_pytest_test.py From micromasters with BSD 3-Clause "New" or "Revised" License | 5 votes |
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) )
Example #6
Source File: views_pytest_test.py From micromasters with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 )
Example #7
Source File: views_test.py From micromasters with BSD 3-Clause "New" or "Revised" License | 5 votes |
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, }