def test_remove_audit_seat_for_professional_course_runs(self, seat_type): seat = SeatFactory(type=seat_type) audit_seat = SeatFactory(type=Seat.AUDIT, course_run=seat.course_run) form = SeatForm(instance=seat) form.save() assert list(seat.course_run.seats.all()) == [seat] assert not Seat.objects.filter(pk=audit_seat.pk).exists()
def test_commit(self, seat_type): SeatFactory(type=Seat.AUDIT) SeatFactory(type=Seat.NO_ID_PROFESSIONAL) SeatFactory(type=Seat.PROFESSIONAL) seat = SeatFactory(type=seat_type) call_command('add_audit_seats_to_verified_course_runs', '--commit') assert seat.course_run.seats.count() == 2 assert seat.course_run.seats.filter(type=Seat.AUDIT, price=0).exists()
def test_create_audit_seat_for_credit_and_verified_course_runs( self, seat_type): seat = SeatFactory(type=seat_type) form = SeatForm(instance=seat) form.save() assert seat.course_run.seats.count() == 2 assert seat.course_run.seats.filter(type=Seat.AUDIT, price=0).exists()
def setUp(self): super(CourseRunStateSerializerTests, self).setUp() self.run_state = CourseRunStateFactory( name=CourseRunStateChoices.Draft) self.course_run = self.run_state.course_run self.request = RequestFactory() self.user = UserFactory() self.request.user = self.user CourseStateFactory(name=CourseStateChoices.Approved, course=self.course_run.course) SeatFactory(course_run=self.course_run, type=Seat.AUDIT) language_tag = LanguageTag(code='te-st', name='Test Language') language_tag.save() self.course_run.transcript_languages.add(language_tag) self.course_run.language = language_tag organization = OrganizationFactory() self.course_run.course.organizations.add(organization) self.course_run.save() self.course_run.staff.add(PersonFactory()) toggle_switch('enable_publisher_email_notifications', True) CourseUserRoleFactory(course=self.course_run.course, role=PublisherUserRole.CourseTeam, user=self.user) CourseUserRoleFactory(course=self.course_run.course, role=PublisherUserRole.ProjectCoordinator, user=UserFactory())
def test_serialize_seat_for_ecommerce_api_with_id_verification( self, seat_type): seat = SeatFactory(type=seat_type) actual = serialize_seat_for_ecommerce_api(seat) expected_attribute_values = [{ 'name': 'certificate_type', 'value': seat_type, }, { 'name': 'id_verification_required', 'value': True, }] assert actual['attribute_values'] == expected_attribute_values
def test_serialize_seat_for_ecommerce_api_with_audit_seat(self): seat = SeatFactory(type=Seat.AUDIT) actual = serialize_seat_for_ecommerce_api(seat) expected = { 'expires': serialize_datetime(seat.calculated_upgrade_deadline), 'price': str(seat.price), 'product_class': 'Seat', 'attribute_values': [{ 'name': 'certificate_type', 'value': '', }, { 'name': 'id_verification_required', 'value': False, }] } assert actual == expected
def test_publish_seat_without_upgrade_deadline(self, mock_access_token): publisher_course_run = self._create_course_run_for_publication() verified_seat = SeatFactory(type=Seat.VERIFIED, course_run=publisher_course_run, upgrade_deadline=None) partner = publisher_course_run.course.organizations.first().partner self._set_test_client_domain_and_login(partner) self._mock_studio_api_success(publisher_course_run) self._mock_ecommerce_api(publisher_course_run) url = reverse('publisher:api:v1:course_run-publish', kwargs={'pk': publisher_course_run.pk}) response = self.client.post(url, {}) assert response.status_code == 200 discovery_course_run = CourseRun.objects.get(key=publisher_course_run.lms_course_id) DiscoverySeat.objects.get( type=DiscoverySeat.VERIFIED, upgrade_deadline=verified_seat.calculated_upgrade_deadline, price=verified_seat.price, course_run=discovery_course_run )
def test_publish_masters_track_seat(self, mock_access_token): """ Test that publishing a seat with masters_track creates a masters seat and masters track """ publisher_course_run = self._create_course_run_for_publication() audit_seat_with_masters_track = SeatFactory( type="Audit", course_run=publisher_course_run, masters_track=True) publisher_course_run.seats.add(audit_seat_with_masters_track) partner = publisher_course_run.course.organizations.first().partner self._set_test_client_domain_and_login(partner) self._mock_studio_api_success(publisher_course_run) self._mock_ecommerce_api(publisher_course_run) publish_url = reverse('publisher:api:v1:course_run-publish', kwargs={'pk': publisher_course_run.pk}) response = self.client.post(publish_url, {}) assert response.status_code == 200 discovery_course_run = CourseRun.objects.get( key=publisher_course_run.lms_course_id) assert discovery_course_run.seats.all().count() == 2 assert discovery_course_run.seats.filter( type=DiscoverySeat.MASTERS).count() == 1
def test_serialize_seat_for_ecommerce_api(self): seat = SeatFactory() actual = serialize_seat_for_ecommerce_api(seat) assert actual['price'] == str(seat.price) assert actual['product_class'] == 'Seat'
def test_publish(self, mock_access_token): # pylint: disable=unused-argument,too-many-statements publisher_course_run = self._create_course_run_for_publication() currency = Currency.objects.get(code='USD') common_seat_kwargs = { 'course_run': publisher_course_run, 'currency': currency, } audit_seat = SeatFactory(type=Seat.AUDIT, upgrade_deadline=None, **common_seat_kwargs) # The credit seat should NOT be published. SeatFactory(type=Seat.CREDIT, **common_seat_kwargs) professional_seat = SeatFactory(type=Seat.PROFESSIONAL, **common_seat_kwargs) verified_seat = SeatFactory(type=Seat.VERIFIED, **common_seat_kwargs) partner = publisher_course_run.course.organizations.first().partner self._set_test_client_domain_and_login(partner) self._mock_studio_api_success(publisher_course_run) self._mock_ecommerce_api(publisher_course_run) url = reverse('publisher:api:v1:course_run-publish', kwargs={'pk': publisher_course_run.pk}) response = self.client.post(url, {}) assert response.status_code == 200 assert len(responses.calls) == 3 expected = { 'discovery': CourseRunViewSet.PUBLICATION_SUCCESS_STATUS, 'ecommerce': CourseRunViewSet.PUBLICATION_SUCCESS_STATUS, 'studio': CourseRunViewSet.PUBLICATION_SUCCESS_STATUS, } assert response.data == expected # Verify the correct deadlines were sent to the E-Commerce API ecommerce_body = json.loads(responses.calls[2].request.body) expected = [ serialize_seat_for_ecommerce_api(audit_seat), serialize_seat_for_ecommerce_api(professional_seat), serialize_seat_for_ecommerce_api(verified_seat), ] assert ecommerce_body['products'] == expected assert ecommerce_body['verification_deadline'] == serialize_datetime( publisher_course_run.end) discovery_course_run = CourseRun.objects.get( key=publisher_course_run.lms_course_id) publisher_course = publisher_course_run.course discovery_course = discovery_course_run.course # pylint: disable=no-member assert discovery_course_run.title_override == publisher_course_run.title_override assert discovery_course_run.short_description_override is None assert discovery_course_run.full_description_override is None assert discovery_course_run.start == publisher_course_run.start assert discovery_course_run.end == publisher_course_run.end assert discovery_course_run.enrollment_start == publisher_course_run.enrollment_start assert discovery_course_run.enrollment_end == publisher_course_run.enrollment_end assert discovery_course_run.pacing_type == publisher_course_run.pacing_type assert discovery_course_run.min_effort == publisher_course_run.min_effort assert discovery_course_run.max_effort == publisher_course_run.max_effort assert discovery_course_run.language == publisher_course_run.language assert discovery_course_run.weeks_to_complete == publisher_course_run.length assert discovery_course_run.learner_testimonials == publisher_course.learner_testimonial expected = set(publisher_course_run.transcript_languages.all()) assert set(discovery_course_run.transcript_languages.all()) == expected assert set(discovery_course_run.staff.all()) == set( publisher_course_run.staff.all()) assert discovery_course.canonical_course_run == discovery_course_run assert discovery_course.partner == partner assert discovery_course.title == publisher_course.title assert discovery_course.short_description == publisher_course.short_description assert discovery_course.full_description == publisher_course.full_description assert discovery_course.level_type == publisher_course.level_type assert discovery_course.video == Video.objects.get( src=publisher_course.video_link) assert discovery_course.image.name is not None assert discovery_course.image.url is not None assert discovery_course.image.file is not None assert discovery_course.image.small.url is not None assert discovery_course.image.small.file is not None assert discovery_course.outcome == publisher_course.expected_learnings assert discovery_course.prerequisites_raw == publisher_course.prerequisites assert discovery_course.syllabus_raw == publisher_course.syllabus expected = list(publisher_course_run.course.organizations.all()) assert list(discovery_course.authoring_organizations.all()) == expected expected = { publisher_course.primary_subject, publisher_course.secondary_subject } assert set(discovery_course.subjects.all()) == expected common_seat_kwargs = { 'course_run': discovery_course_run, 'currency': currency, } DiscoverySeat.objects.get(type=DiscoverySeat.AUDIT, upgrade_deadline__isnull=True, **common_seat_kwargs) DiscoverySeat.objects.get(type=DiscoverySeat.PROFESSIONAL, upgrade_deadline__isnull=True, price=professional_seat.price, **common_seat_kwargs) DiscoverySeat.objects.get( type=DiscoverySeat.VERIFIED, upgrade_deadline=verified_seat.upgrade_deadline, price=verified_seat.price, **common_seat_kwargs)
def test_audit_only_seat_not_modified(self): seat = SeatFactory(type=Seat.AUDIT) form = SeatForm(instance=seat) form.save() assert list(seat.course_run.seats.all()) == [seat]
def test_no_commit(self): seats = SeatFactory.create_batch(3, type=Seat.VERIFIED) call_command('add_audit_seats_to_verified_course_runs') assert Seat.objects.count() == len(seats)