def test_set_last_seen_courseware_timezone_no_integrity_error(self): # Previously this function was trying to create duplicate records # that would bump into a uniqueness constraint causing an integrity error self.client.get(self.url, {'browser_timezone': 'America/New_York'}) TieredCache.dangerous_clear_all_tiers() self.client.get(self.url, {'browser_timezone': 'Asia/Tokyo'}) assert len(LastSeenCoursewareTimezone.objects.filter()) == 1
def test_ingest_verified_deadline(self, mock_push_to_ecomm): """ Verify the method ingests data from the Courses API. """ TieredCache.dangerous_clear_all_tiers() api_data = self.mock_api() assert Course.objects.count() == 0 assert CourseRun.objects.count() == 0 # Assume that while we are relying on ORGS_ON_OLD_PUBLISHER it will never be empty with self.settings(ORGS_ON_OLD_PUBLISHER='OTHER'): self.loader.ingest() # Verify the API was called with the correct authorization header self.assert_api_called(4) runs = CourseRun.objects.all() # Run with a verified entitlement, but no change in end date run1 = runs[0] run1.seats.add( SeatFactory(course_run=run1, type=SeatTypeFactory.verified())) run1.save() # Run with a verified entitlement, and the end date has changed run2 = runs[1] run2.seats.add( SeatFactory( course_run=run2, type=SeatTypeFactory.verified(), upgrade_deadline=datetime.datetime.now(pytz.UTC), )) original_run2_deadline = run2.seats.first().upgrade_deadline run2.end = datetime.datetime.now(pytz.UTC) run2.save() # Run with a credit entitlement, and the end date has changed should not run3 = runs[2] run3.seats.add( SeatFactory( course_run=run3, type=SeatTypeFactory.credit(), upgrade_deadline=None, )) run3.end = datetime.datetime.now(pytz.UTC) run3.save() # Verify the CourseRuns were created correctly expected_num_course_runs = len(api_data) assert CourseRun.objects.count() == expected_num_course_runs # Verify multiple calls to ingest data do NOT result in data integrity errors. self.loader.ingest() calls = [ mock.call(run2), mock.call(run3), ] mock_push_to_ecomm.assert_has_calls(calls) # Make sure the verified seat with a course run end date is changed assert original_run2_deadline != run2.seats.first().upgrade_deadline # Make sure the credit seat with a course run end date is unchanged assert run3.seats.first().upgrade_deadline is None
def setUp(self): super(PaymentProcessorListViewTests, self).setUp() self.token = self.generate_jwt_token_header(self.create_user()) toggle_switch( settings.PAYMENT_PROCESSOR_SWITCH_PREFIX + DummyProcessor.NAME, True) toggle_switch( settings.PAYMENT_PROCESSOR_SWITCH_PREFIX + AnotherDummyProcessor.NAME, True) site_config, __ = SiteConfiguration.objects.get_or_create(site__id=1) old_payment_processors = site_config.payment_processors site_config.payment_processors = ",".join( [DummyProcessor.NAME, AnotherDummyProcessor.NAME]) site_config.save() def reset_site_config(): """ Reset method - resets site_config to pre-test state """ site_config.payment_processors = old_payment_processors site_config.save() self.addCleanup(reset_site_config) # Clear the view cache TieredCache.dangerous_clear_all_tiers()
def setUp(self): """ Create a course and user to test with. """ super().setUp() # Need key to be deterministic to test slugs. self.course = CourseFactory.create(org='edX', course='course_test', run='test_run', display_name='Badged', start=datetime.datetime(year=2015, month=5, day=19), end=datetime.datetime(year=2015, month=5, day=20)) self.user = UserFactory.create(email='*****@*****.**') CourseEnrollmentFactory.create( user=self.user, course_id=self.course.location.course_key, mode='honor') # Need to empty this on each run. BadgrBackend.badges = [] self.badge_class = BadgeClassFactory.create( course_id=self.course.location.course_key) self.legacy_badge_class = BadgeClassFactory.create( course_id=self.course.location.course_key, issuing_component='') self.no_course_badge_class = BadgeClassFactory.create() TieredCache.dangerous_clear_all_tiers() httpretty.httpretty.reset()
def test_ingest(self, partner_uses_publisher, on_new_publisher): """ Verify the method ingests data from the Courses API. """ TieredCache.dangerous_clear_all_tiers() api_data = self.mock_api() if not partner_uses_publisher: self.partner.publisher_url = None self.partner.save() self.assertEqual(Course.objects.count(), 0) self.assertEqual(CourseRun.objects.count(), 0) # Assume that while we are relying on ORGS_ON_OLD_PUBLISHER it will never be empty with self.settings(ORGS_ON_OLD_PUBLISHER='MITx' if not on_new_publisher else 'OTHER'): self.loader.ingest() # Verify the API was called with the correct authorization header self.assert_api_called(4) # Verify the CourseRuns were created correctly expected_num_course_runs = len(api_data) self.assertEqual(CourseRun.objects.count(), expected_num_course_runs) for datum in api_data: self.assert_course_run_loaded(datum, partner_uses_publisher, new_pub=on_new_publisher) # Verify multiple calls to ingest data do NOT result in data integrity errors. self.loader.ingest()
def test_ingest(self): """ Verify the method ingests data from the E-Commerce API. """ TieredCache.dangerous_clear_all_tiers() courses_api_data = self.mock_courses_api() loaded_course_run_data = courses_api_data[:-1] loaded_seat_data = courses_api_data[:-2] self.assertEqual(CourseRun.objects.count(), len(loaded_course_run_data)) products_api_data = self.mock_products_api() # Verify a seat exists on all courses already for course_run in CourseRun.objects.all(): self.assertEqual(course_run.seats.count(), 1) self.loader.ingest() # Verify the API was called with the correct authorization header self.assert_api_called(4) for datum in loaded_seat_data: self.assert_seats_loaded(datum, products_api_data) self.assert_entitlements_loaded(products_api_data) self.assert_enrollment_codes_loaded(products_api_data) # Verify multiple calls to ingest data do NOT result in data integrity errors. self.loader.ingest()
def setUp(self): super().setUp() cache.clear() # Set the domain used for all test requests domain = "testserver.fake" self.client = self.client_class(SERVER_NAME=domain) Site.objects.all().delete() self.site_configuration = SiteConfigurationFactory(site__domain=domain, site__id=settings.SITE_ID) self.site = self.site_configuration.site # Clear edx rest api client cache TieredCache.dangerous_clear_all_tiers()
def test_ingest(self): """ Verify the method ingests data from the Organizations API. """ TieredCache.dangerous_clear_all_tiers() api_data = self.mock_api() self.assertEqual(Program.objects.count(), 0) self.loader.ingest() # Verify the API was called with the correct authorization header self.assert_api_called(6) # Verify the Programs were created correctly self.assertEqual(Program.objects.count(), len(api_data)) for datum in api_data: self.assert_program_loaded(datum) self.loader.ingest()
def test_ingest_with_existing_banner_image(self): TieredCache.dangerous_clear_all_tiers() programs = self.mock_api() for program_data in programs: banner_image_url = program_data.get('banner_image_urls', {}).get('w1440h480') if banner_image_url: responses.add_callback(responses.GET, banner_image_url, callback=mock_jpeg_callback(), content_type=JPEG) self.loader.ingest() # Verify the API was called with the correct authorization header self.assert_api_called(6) for program in programs: self.assert_program_loaded(program) self.assert_program_banner_image_loaded(program)
def setUp(self): TieredCache.dangerous_clear_all_tiers() super(TieredCacheMixin, self).setUp()
def setUp(self): super().setUp() TieredCache.dangerous_clear_all_tiers()
def setUp(self): super(OAuthAPIClientTests, self).setUp() TieredCache.dangerous_clear_all_tiers()
def setUp(self): super(CachedClientCredentialTests, self).setUp() TieredCache.dangerous_clear_all_tiers()
def tearDown(self): super(PermissionsTests, self).tearDown() TieredCache.dangerous_clear_all_tiers() cache.clear()
def setUpClass(cls): super(PermissionsTests, cls).setUpClass() TieredCache.dangerous_clear_all_tiers() cache.clear()
def tearDown(self): super().tearDown() TieredCache.dangerous_clear_all_tiers() cache.clear()
def tearDown(self): TieredCache.dangerous_clear_all_tiers() super(TieredCacheMixin, self).tearDown()
def setUp(self): super(DiscoveryMockMixin, self).setUp() TieredCache.dangerous_clear_all_tiers()
def setUpClass(cls): super().setUpClass() TieredCache.dangerous_clear_all_tiers() cache.clear()