def test_serialize_entitlement_for_ecommerce_api(self): entitlement = CourseEntitlementFactory() actual = serialize_entitlement_for_ecommerce_api(entitlement) expected = { 'price': str(entitlement.price), 'product_class': 'Course Entitlement', 'attribute_values': [ { 'name': 'certificate_type', 'value': entitlement.mode, }, ] } assert actual == expected
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_entitlement_kwargs = { 'course': publisher_course_run.course, 'currency': currency, } professional_entitlement = CourseEntitlementFactory( mode=CourseEntitlement.PROFESSIONAL, **common_entitlement_kwargs) verified_entitlement = CourseEntitlementFactory( mode=CourseEntitlement.VERIFIED, **common_entitlement_kwargs) 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) with LogCapture(LOGGER_NAME) as log: url = reverse('publisher:api:v1:course_run-publish', kwargs={'pk': publisher_course_run.pk}) response = self.client.post(url, {}) assert response.status_code == 200 log.check(( LOGGER_NAME, 'INFO', 'Published course run with id: [{}] lms_course_id: [{}], user: [{}], date: [{}]' .format(publisher_course_run.id, publisher_course_run.lms_course_id, self.user, date.today()))) 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), serialize_entitlement_for_ecommerce_api(professional_entitlement), serialize_entitlement_for_ecommerce_api(verified_entitlement), ] assert ecommerce_body['products'] == expected assert ecommerce_body['verification_deadline'] == serialize_datetime( publisher_course_run.end_date_temporary) 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 assert ecommerce_body['id'] == publisher_course_run.lms_course_id assert ecommerce_body['uuid'] == str(discovery_course.uuid) # 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_date_temporary assert discovery_course_run.end == publisher_course_run.end_date_temporary assert discovery_course_run.pacing_type == publisher_course_run.pacing_type_temporary 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.has_ofac_restrictions == publisher_course_run.has_ofac_restrictions 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 assert discovery_course.learner_testimonials == publisher_course.learner_testimonial assert discovery_course.faq == publisher_course.faq assert discovery_course.additional_information == publisher_course.additional_information 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_entitlement_kwargs = { 'course': discovery_course, 'currency': currency, } self.assertEqual(2, DiscoveryCourseEntitlement.objects.all().count()) DiscoveryCourseEntitlement.objects.get( mode=SeatType.objects.get(slug=DiscoverySeat.PROFESSIONAL), price=professional_entitlement.price, **common_entitlement_kwargs) DiscoveryCourseEntitlement.objects.get( mode=SeatType.objects.get(slug=DiscoverySeat.VERIFIED), price=verified_entitlement.price, **common_entitlement_kwargs) 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)