def test_has_valid_seats(self): """ Verify that property returns True if seats are valid. """ factories.SeatFactory(course_run=self.course_run, type=Seat.AUDIT, price=0) invalid_seat = factories.SeatFactory(course_run=self.course_run, type=Seat.VERIFIED, price=0) self.assertFalse(self.course_run.has_valid_seats) invalid_seat.price = 200 invalid_seat.save() self.assertTrue(self.course_run.has_valid_seats) credit_seat = factories.SeatFactory(course_run=self.course_run, type=Seat.CREDIT, price=0, credit_price=0) self.assertFalse(self.course_run.has_valid_seats) credit_seat.price = 200 credit_seat.credit_price = 200 credit_seat.save() self.assertTrue(self.course_run.has_valid_seats)
def test_calculated_upgrade_deadline_with_verified_seat(self, settings): settings.PUBLISHER_UPGRADE_DEADLINE_DAYS = random.randint(1, 21) now = datetime.datetime.utcnow() seat = factories.SeatFactory(type=Seat.VERIFIED, upgrade_deadline=None, course_run__end=now) expected = subtract_deadline_delta(now, settings.PUBLISHER_UPGRADE_DEADLINE_DAYS) assert seat.calculated_upgrade_deadline == expected seat = factories.SeatFactory(type=Seat.VERIFIED) assert seat.calculated_upgrade_deadline is not None assert seat.calculated_upgrade_deadline == seat.upgrade_deadline
def test_calculated_upgrade_deadline_with_verified_seat(self, settings): settings.PUBLISHER_UPGRADE_DEADLINE_DAYS = random.randint(1, 21) now = datetime.datetime.utcnow() seat = factories.SeatFactory(type=Seat.VERIFIED, upgrade_deadline=None, course_run__end=now) expected = now - datetime.timedelta(days=settings.PUBLISHER_UPGRADE_DEADLINE_DAYS) expected = expected.replace(hour=23, minute=59, second=59, microsecond=99999) assert seat.calculated_upgrade_deadline == expected seat = factories.SeatFactory(type=Seat.VERIFIED) assert seat.calculated_upgrade_deadline is not None assert seat.calculated_upgrade_deadline == seat.upgrade_deadline
def test_verified_seat_price(self): """ Verify that the wrapper return the verified seat price. """ self.assertEqual(self.wrapped_course_run.verified_seat_price, None) seat = factories.SeatFactory(type=Seat.VERIFIED, course_run=self.course_run) wrapped_course_run = CourseRunWrapper(self.course_run) self.assertEqual(wrapped_course_run.verified_seat_price, seat.price)
def test_credit_seat_price(self): """ Verify that the wrapper return the credit seat price. """ self.assertEqual(self.wrapped_course_run.credit_seat_price, None) seat = factories.SeatFactory(type=Seat.CREDIT, course_run=self.course_run) wrapped_course_run = CourseRunWrapper(self.course_run) self.assertEqual(wrapped_course_run.credit_seat_price, seat.credit_price)
def setUpClass(cls): super(StateChangeEmailTests, cls).setUpClass() cls.user = UserFactory() cls.user_2 = UserFactory() cls.user_3 = UserFactory() cls.site = Site.objects.get(pk=settings.SITE_ID) cls.group = factories.GroupFactory() cls.user.groups.add(cls.group) cls.user_2.groups.add(cls.group) cls.user_3.groups.add(cls.group) cls.seat = factories.SeatFactory() cls.course_run = cls.seat.course_run cls.course = cls.course_run.course assign_perm(Course.VIEW_PERMISSION, cls.group, cls.course) # NOTE: We intentionally do NOT create an attribute for user_2. # By default this user WILL receive email notifications. UserAttributeFactory(user=cls.user, enable_email_notification=True) UserAttributeFactory(user=cls.user_3, enable_email_notification=False) toggle_switch('enable_publisher_email_notifications', True)
def setUp(self): super(CommentsEmailTests, self).setUp() self.user = UserFactory() self.user_2 = UserFactory() self.user_3 = UserFactory() self.site = Site.objects.get(pk=settings.SITE_ID) self.group = factories.GroupFactory(name='abc') self.user.groups.add(self.group) self.user_2.groups.add(self.group) self.user_3.groups.add(self.group) self.seat = factories.SeatFactory() self.course_run = self.seat.course_run self.course = self.course_run.course assign_perm(Course.VIEW_PERMISSION, self.group, self.course) # NOTE: We intentionally do NOT create an attribute for user_2. # By default this user WILL receive email notifications. UserAttributeFactory(user=self.user, enable_email_notification=True) UserAttributeFactory(user=self.user_3, enable_email_notification=False) toggle_switch('enable_publisher_email_notifications', True)
def setUp(self): super(CourseRunMarkAsReviewedEmailTests, self).setUp() self.user = UserFactory() self.user_2 = UserFactory() self.user_3 = UserFactory() self.seat = factories.SeatFactory() self.course_run = self.seat.course_run self.course = self.course_run.course self.course.organizations.add(OrganizationFactory()) # add user in course-user-role table factories.CourseUserRoleFactory(course=self.course, role=PublisherUserRole.CourseTeam, user=self.user_2) factories.CourseUserRoleFactory(course=self.course, role=PublisherUserRole.Publisher, user=self.user_3) self.course_run_state = factories.CourseRunStateFactory( course_run=self.course_run) self.course_run.lms_course_id = 'course-v1:edX+DemoX+Demo_Course' self.course_run.save() toggle_switch('enable_publisher_email_notifications', True)
def setUp(self): super(ChangeCourseRunStateViewTests, self).setUp() self.seat = factories.SeatFactory(type=Seat.VERIFIED, price=2) self.course_run = self.seat.course_run self.run_state = factories.CourseRunStateFactory(name=CourseRunStateChoices.Draft, course_run=self.course_run) self.course_state = factories.CourseStateFactory( name=CourseStateChoices.Approved, course=self.course_run.course ) self.user = UserFactory() self.user.groups.add(Group.objects.get(name=INTERNAL_USER_GROUP_NAME)) self.change_state_url = reverse('publisher:api:change_course_run_state', kwargs={'pk': self.run_state.id}) self.client.login(username=self.user.username, password=USER_PASSWORD) 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 self.course_run.lms_course_id = 'course-v1:edX+DemoX+Demo_Course' self.course_run.course.organizations.add(OrganizationFactory()) self.course_run.save() self.course_run.staff.add(PersonFactory()) toggle_switch('enable_publisher_email_notifications', True)
def test_credit_seat(self): """ Verify that the wrapper return the credit seat. """ self.assertEqual(self.wrapped_course_run.credit_seat, None) seat = factories.SeatFactory( type=Seat.CREDIT, course_run=self.course_run, credit_provider='ASU', credit_hours=9 ) wrapped_course_run = CourseRunWrapper(self.course_run) self.assertEqual(wrapped_course_run.credit_seat, seat)
def setUpClass(cls): super(CourseRunStateTests, cls).setUpClass() cls.seat = factories.SeatFactory(type=Seat.VERIFIED, price=100) cls.course_run_state = factories.CourseRunStateFactory( course_run=cls.seat.course_run, name=CourseRunStateChoices.Draft) cls.course_run = cls.course_run_state.course_run cls.course = cls.course_run.course cls.user = UserFactory() factories.CourseStateFactory(name=CourseStateChoices.Approved, course=cls.course) factories.CourseUserRoleFactory(course=cls.course_run.course, role=PublisherUserRole.CourseTeam, user=cls.user) factories.CourseUserRoleFactory( course=cls.course_run.course, role=PublisherUserRole.MarketingReviewer, user=UserFactory())
def setUp(self): super(CommentsTests, self).setUp() self.user = UserFactory(is_staff=True, is_superuser=True) self.group = factories.GroupFactory() self.user.groups.add(self.group) self.client.login(username=self.user.username, password=USER_PASSWORD) self.site = Site.objects.get(pk=settings.SITE_ID) self.course_edit_page = 'publisher:publisher_courses_edit' self.course_run_edit_page = 'publisher:publisher_course_runs_edit' self.seat_edit_page = 'publisher:publisher_seats_edit' self.edit_comment_page = 'publisher_comments:comment_edit' self.seat = factories.SeatFactory(type=Seat.PROFESSIONAL, credit_hours=0) self.course_run = self.seat.course_run self.course = self.course_run.course self.course.assign_permission_by_group(self.group) toggle_switch('enable_publisher_email_notifications', True)
def setUp(self): super(CourseRunMarkAsReviewedEmailTests, self).setUp() self.user = UserFactory() self.user_2 = UserFactory() self.user_3 = UserFactory() self.seat = factories.SeatFactory() self.course_run = self.seat.course_run self.course = self.course_run.course # add user in course-user-role table factories.CourseUserRoleFactory( course=self.course, role=PublisherUserRole.CourseTeam, user=self.user_2 ) factories.CourseUserRoleFactory( course=self.course, role=PublisherUserRole.Publisher, user=self.user_3 ) self.course_run_state = factories.CourseRunStateFactory(course_run=self.course_run) toggle_switch('enable_publisher_email_notifications', True)
def setUp(self): super(CommentsEmailTests, self).setUp() self.user = UserFactory() self.user_2 = UserFactory() self.user_3 = UserFactory() self.site = Site.objects.get(pk=settings.SITE_ID) self.organization_extension = factories.OrganizationExtensionFactory() self.seat = factories.SeatFactory() self.course_run = self.seat.course_run self.course = self.course_run.course self.course.organizations.add(self.organization_extension.organization) # NOTE: We intentionally do NOT create an attribute for user_2. # By default this user WILL receive email notifications. # add user in course-user-role table factories.CourseUserRoleFactory( course=self.course, role=PublisherUserRole.ProjectCoordinator, user=self.user) factories.CourseUserRoleFactory( course=self.course, role=PublisherUserRole.ProjectCoordinator, user=self.user_2) factories.CourseUserRoleFactory( course=self.course, role=PublisherUserRole.ProjectCoordinator, user=self.user_3) UserAttributeFactory(user=self.user, enable_email_notification=True) UserAttributeFactory(user=self.user_3, enable_email_notification=False) toggle_switch('enable_publisher_email_notifications', True) self.url = 'http://www.test.com'
def setUp(self): super(CourseRunSendForReviewEmailTests, self).setUp() self.user = UserFactory() self.user_2 = UserFactory() self.user_3 = UserFactory() self.seat = factories.SeatFactory() self.course_run = self.seat.course_run self.course = self.course_run.course self.course.organizations.add(OrganizationFactory()) # add user in course-user-role table factories.CourseUserRoleFactory(course=self.course, role=PublisherUserRole.CourseTeam, user=self.user_2) factories.CourseUserRoleFactory(course=self.course, role=PublisherUserRole.Publisher, user=self.user_3) self.course_run_state = factories.CourseRunStateFactory( course_run=self.course_run) self.course_run.lms_course_id = 'course-v1:edX+DemoX+Demo_Course' self.course_run.save() self.course_key = CourseKey.from_string(self.course_run.lms_course_id)
def _generate_seats(self, modes): for mode in modes: factories.SeatFactory(type=mode, course_run=self.course_run)
def test_calculated_upgrade_deadline_with_nonverified_seat(self, seat_type): seat = factories.SeatFactory(type=seat_type) assert seat.calculated_upgrade_deadline is None
def test_str(self): seat = factories.SeatFactory() assert str(seat) == '{course}: {type}'.format(course=seat.course_run.course.title, type=seat.type)
def setUp(self): super(SeatTests, self).setUp() self.seat = factories.SeatFactory()