示例#1
0
    def test_refund_cutoff_date(self, order_date_delta, course_start_delta,
                                expected_date_delta, days):
        """
        Assert that the later date is used with the configurable refund period in calculating the returned cutoff date.
        """
        now = datetime.now(pytz.UTC).replace(microsecond=0)
        order_date = now + order_date_delta
        course_start = now + course_start_delta
        expected_date = now + expected_date_delta
        refund_period = timedelta(days=days)
        date_placed = order_date.strftime(ECOMMERCE_DATE_FORMAT)
        expected_content = '{{"date_placed": "{date}"}}'.format(
            date=date_placed)

        httpretty.register_uri(httpretty.GET,
                               '{url}/orders/{order}/'.format(
                                   url=TEST_API_URL, order=self.ORDER_NUMBER),
                               status=200,
                               body=expected_content,
                               adding_headers={'Content-Type': JSON})

        self.enrollment.course_overview.start = course_start
        self.enrollment.attributes.create(enrollment=self.enrollment,
                                          namespace='order',
                                          name='order_number',
                                          value=self.ORDER_NUMBER)

        with patch('student.models.EnrollmentRefundConfiguration.current'
                   ) as config:
            instance = config.return_value
            instance.refund_window = refund_period
            self.assertEqual(self.enrollment.refund_cutoff_date(),
                             expected_date + refund_period)

            expected_date_placed_attr = {
                "namespace": "order",
                "name": "date_placed",
                "value": date_placed,
            }

            self.assertIn(
                expected_date_placed_attr,
                CourseEnrollmentAttribute.get_enrollment_attributes(
                    self.enrollment))
示例#2
0
def get_enrollment_attributes(user_id, course_id):
    """Retrieve enrollment attributes for given user for provided course.

    Args:
        user_id: The User to get enrollment attributes for
        course_id (str): The Course to get enrollment attributes for.

    Example:
        >>>get_enrollment_attributes("Bob", "course-v1-edX-DemoX-1T2015")
        [
            {
                "namespace": "credit",
                "name": "provider_id",
                "value": "hogwarts",
            },
        ]

    Returns: list
    """
    course_key = CourseKey.from_string(course_id)
    user = _get_user(user_id)
    enrollment = CourseEnrollment.get_enrollment(user, course_key)
    return CourseEnrollmentAttribute.get_enrollment_attributes(enrollment)
示例#3
0
def get_enrollment_attributes(user_id, course_id):
    """Retrieve enrollment attributes for given user for provided course.

    Args:
        user_id: The User to get enrollment attributes for
        course_id (str): The Course to get enrollment attributes for.

    Example:
        >>>get_enrollment_attributes("Bob", "course-v1-edX-DemoX-1T2015")
        [
            {
                "namespace": "credit",
                "name": "provider_id",
                "value": "hogwarts",
            },
        ]

    Returns: list
    """
    course_key = CourseKey.from_string(course_id)
    user = _get_user(user_id)
    enrollment = CourseEnrollment.get_enrollment(user, course_key)
    return CourseEnrollmentAttribute.get_enrollment_attributes(enrollment)