def _allow_donation(course_modes, course_id, enrollment): """ Determines if the dashboard will request donations for the given course. Check if donations are configured for the platform, and if the current course is accepting donations. Args: course_modes (dict): Mapping of course ID's to course mode dictionaries. course_id (str): The unique identifier for the course. enrollment(CourseEnrollment): The enrollment object in which the user is enrolled Returns: True if the course is allowing donations. """ if course_id not in course_modes: flat_unexpired_modes = { text_type(course_id): [mode for mode in modes] for course_id, modes in iteritems(course_modes) } flat_all_modes = { text_type(course_id): [mode.slug for mode in modes] for course_id, modes in iteritems( CourseMode.all_modes_for_courses([course_id])) } log.error(u'Can not find `%s` in course modes.`%s`. All modes: `%s`', course_id, flat_unexpired_modes, flat_all_modes) donations_enabled = configuration_helpers.get_value( 'ENABLE_DONATIONS', DonationConfiguration.current().enabled) return (donations_enabled and enrollment.mode in course_modes[course_id] and course_modes[course_id][enrollment.mode].min_price == 0)
def test_donate_button_with_enabled_site_configuration( self, enable_donation_config, enable_donation_site_config): # Enable the enrollment success message and donations self._configure_message_timeout(10000) # DonationConfiguration has low precedence if 'ENABLE_DONATIONS' is enable in SiteConfiguration DonationConfiguration(enabled=enable_donation_config).save() CourseModeFactory.create(mode_slug="audit", course_id=self.course.id, min_price=0) self.enrollment.mode = "audit" self.enrollment.save() self.client.login(username=self.student.username, password=self.PASSWORD) with with_site_configuration_context( configuration={ 'ENABLE_DONATIONS': enable_donation_site_config }): response = self.client.get(reverse("dashboard")) if enable_donation_site_config: self.assertContains(response, "donate-container") else: self.assertNotContains(response, "donate-container")
def test_donate_button(self, course_modes, enrollment_mode, show_donate): # Enable the enrollment success message self._configure_message_timeout(10000) # Enable donations DonationConfiguration(enabled=True).save() # Create the course mode(s) for mode, min_price in course_modes: CourseModeFactory.create(mode_slug=mode, course_id=self.course.id, min_price=min_price) self.enrollment.mode = enrollment_mode self.enrollment.save() # Check that the donate button is or is not displayed self.client.login(username=self.student.username, password=self.PASSWORD) response = self.client.get(reverse("dashboard")) if show_donate: self.assertContains(response, "donate-container") else: self.assertNotContains(response, "donate-container")
def test_donate_button_honor_with_price(self): # Enable the enrollment success message and donations self._configure_message_timeout(10000) DonationConfiguration(enabled=True).save() # Create a white-label course mode # (honor mode with a price set) CourseModeFactory.create(mode_slug="honor", course_id=self.course.id, min_price=100) # Check that the donate button is NOT displayed self.client.login(username=self.student.username, password=self.PASSWORD) response = self.client.get(reverse("dashboard")) self.assertNotContains(response, "donate-container")
def _allow_donation(course_modes, course_id, enrollment): """ Determines if the dashboard will request donations for the given course. Check if donations are configured for the platform, and if the current course is accepting donations. Args: course_modes (dict): Mapping of course ID's to course mode dictionaries. course_id (str): The unique identifier for the course. enrollment(CourseEnrollment): The enrollment object in which the user is enrolled Returns: True if the course is allowing donations. """ if course_id not in course_modes: flat_unexpired_modes = { text_type(course_id): [mode for mode in modes] for course_id, modes in iteritems(course_modes) } flat_all_modes = { text_type(course_id): [mode.slug for mode in modes] for course_id, modes in iteritems(CourseMode.all_modes_for_courses([course_id])) } log.error( u'Can not find `%s` in course modes.`%s`. All modes: `%s`', course_id, flat_unexpired_modes, flat_all_modes ) donations_enabled = configuration_helpers.get_value( 'ENABLE_DONATIONS', DonationConfiguration.current().enabled ) return ( donations_enabled and enrollment.mode in course_modes[course_id] and course_modes[course_id][enrollment.mode].min_price == 0 )