def test_unpublished_sessions_for_entitlement_when_enrolled( self, mock_get_edx_api_data): """ Test unpublished course runs are part of visible session entitlements when the user is enrolled. """ catalog_course_run = CourseRunFactory.create(status=COURSE_UNPUBLISHED) catalog_course = CourseFactory(course_runs=[catalog_course_run]) mock_get_edx_api_data.return_value = catalog_course course_key = CourseKey.from_string(catalog_course_run.get('key')) course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id, expiration_datetime=now() - timedelta(days=1)) course_enrollment = CourseEnrollmentFactory(user=self.user, course=course_overview, mode=CourseMode.VERIFIED) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED) session_entitlements = get_visible_sessions_for_entitlement( entitlement) self.assertEqual(session_entitlements, [catalog_course_run])
def test_unpublished_sessions_for_entitlement_when_enrolled(self, mock_get_edx_api_data): """ Test unpublished course runs are part of visible session entitlements when the user is enrolled. """ catalog_course_run = CourseRunFactory.create(status=COURSE_UNPUBLISHED) catalog_course = CourseFactory(course_runs=[catalog_course_run]) mock_get_edx_api_data.return_value = catalog_course course_key = CourseKey.from_string(catalog_course_run.get('key')) course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) CourseModeFactory.create( mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id, expiration_datetime=now() - timedelta(days=1) ) course_enrollment = CourseEnrollmentFactory( user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED ) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED ) session_entitlements = get_visible_sessions_for_entitlement(entitlement) self.assertEqual(session_entitlements, [catalog_course_run])
def test_get_visible_sessions_for_entitlement_expired_mode( self, mock_get_edx_api_data): """ Test retrieval of visible session entitlements. """ catalog_course_run = CourseRunFactory.create() catalog_course = CourseFactory(course_runs=[catalog_course_run]) mock_get_edx_api_data.return_value = catalog_course course_key = CourseKey.from_string(catalog_course_run.get('key')) course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id, expiration_datetime=now() - timedelta(days=1)) course_enrollment = CourseEnrollmentFactory(user=self.user, course_id=six.text_type( course_overview.id), mode=CourseMode.VERIFIED) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED) session_entitlements = get_visible_sessions_for_entitlement( entitlement) self.assertEqual(session_entitlements, [catalog_course_run])
def test_unpublished_sessions_for_entitlement(self, mock_get_edx_api_data): """ Test unpublished course runs are not part of visible session entitlements. """ catalog_course_runs = CourseRunFactory.create( status=COURSE_UNPUBLISHED) catalog_course = CourseFactory(course_runs=[catalog_course_runs]) mock_get_edx_api_data.return_value = catalog_course course_key = CourseKey.from_string(catalog_course_runs.get('key')) course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id) course_enrollment = CourseEnrollmentFactory(user=self.user, course_id=unicode( course_overview.id), mode=CourseMode.VERIFIED) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED) session_entitlements = get_visible_sessions_for_entitlement( entitlement) self.assertEqual(session_entitlements, [])
def setUp(self): super(TeamsServiceTests, self).setUp() self.course_run = CourseRunFactory.create() self.course_key = self.course_run['key'] self.team = CourseTeamFactory.create(course_id=self.course_key) self.service = TeamsService() self.user = UserFactory.create() CourseEnrollmentFactory.create(user=self.user, course_id=self.course_key) self.team.add_user(self.user)
def setUp(self): super(TeamsServiceTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_run = CourseRunFactory.create() self.course_key = self.course_run['key'] self.team = CourseTeamFactory.create(course_id=self.course_key) self.service = TeamsService() self.user = UserFactory.create() CourseEnrollmentFactory.create(user=self.user, course_id=self.course_key) self.team.add_user(self.user)
def test_get_visible_sessions_for_entitlement(self, mock_get_edx_api_data): """ Test retrieval of visible session entitlements. """ catalog_course_run = CourseRunFactory.create() catalog_course = CourseFactory(course_runs=[catalog_course_run]) mock_get_edx_api_data.return_value = catalog_course course_key = CourseKey.from_string(catalog_course_run.get('key')) course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id) course_enrollment = CourseEnrollmentFactory( user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED ) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED ) session_entitlements = get_visible_sessions_for_entitlement(entitlement) self.assertEqual(session_entitlements, [catalog_course_run])
def test_get_visible_sessions_for_entitlement(self, mock_get_edx_api_data): """ Test retrieval of visible session entitlements. """ catalog_course_run = CourseRunFactory.create() catalog_course = CourseFactory(course_runs=[catalog_course_run]) mock_get_edx_api_data.return_value = catalog_course course_key = CourseKey.from_string(catalog_course_run.get('key')) course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id) course_enrollment = CourseEnrollmentFactory( user=self.user, course=course_overview, mode=CourseMode.VERIFIED ) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED ) session_entitlements = get_visible_sessions_for_entitlement(entitlement) assert session_entitlements == [catalog_course_run]
def setUp(self): super(TeamsServiceTests, self).setUp() self.course_run = CourseRunFactory.create() self.team = CourseTeamFactory.create(course_id=self.course_run['key']) self.service = TeamsService()
def test_get_team_names__none(self): """ If there are no teams in the teamset, the function will return an empty list""" course_run = CourseRunFactory.create() course_key = course_run['key'] result = self.service.get_team_names(course_key, "some-topic-id") assert result == {}