Exemplo n.º 1
0
    def _get_update_response_and_expected_data(self, mode_expiration,
                                               verification_deadline):
        """ Returns expected data and response for course update. """
        expected_course_mode = CourseMode(mode_slug=u'verified',
                                          min_price=200,
                                          currency=u'USD',
                                          sku=u'ABC123',
                                          bulk_sku=u'BULK-ABC123',
                                          expiration_datetime=mode_expiration)
        expected = self._serialize_course(self.course, [expected_course_mode],
                                          verification_deadline)

        # Sanity check: The API should return HTTP status 200 for updates
        response = self.client.put(self.path,
                                   json.dumps(expected),
                                   content_type=JSON_CONTENT_TYPE)

        return response, expected
Exemplo n.º 2
0
    def setUp(self):
        self.course = CourseFactory.create()

        # Create instructor account
        self.instructor = AdminFactory.create()
        self.client.login(username=self.instructor.username, password="******")
        mode = CourseMode(course_id=self.course.id.to_deprecated_string(),
                          mode_slug='honor',
                          mode_display_name='honor',
                          min_price=10,
                          currency='usd')
        mode.save()
        # URL for instructor dash
        self.url = reverse(
            'instructor_dashboard',
            kwargs={'course_id': self.course.id.to_deprecated_string()})
        self.e_commerce_link = '<a href="" data-section="e-commerce">E-Commerce</a>'
        CourseFinanceAdminRole(self.course.id).add_users(self.instructor)
Exemplo n.º 3
0
    def test_verified_course(self):
        """Verify the e-commerce panel shows up for verified courses as well, without Coupons """
        # Change honor mode to verified.
        original_mode = CourseMode.objects.get(course_id=self.course.id,
                                               mode_slug='honor')
        original_mode.delete()
        new_mode = CourseMode(course_id=unicode(self.course.id),
                              mode_slug='verified',
                              mode_display_name='verified',
                              min_price=10,
                              currency='usd')
        new_mode.save()

        # Get the response value, ensure the Coupon section is not included.
        response = self.client.get(self.url)
        self.assertIn(self.ecommerce_link, response.content)
        # Coupons should show up for White Label sites with priced honor modes.
        self.assertNotIn('Coupons List', response.content)
Exemplo n.º 4
0
 def setUp(self):
     patcher = patch('student.models.tracker')
     self.mock_tracker = patcher.start()
     self.user = UserFactory.create()
     self.user.set_password('password')
     self.user.save()
     self.cost = 40
     self.course = CourseFactory.create(org='MITx', number='999', display_name='Robot Super Course')
     self.course_key = self.course.id
     self.course_mode = CourseMode(course_id=self.course_key,
                                   mode_slug="honor",
                                   mode_display_name="honor cert",
                                   min_price=self.cost)
     self.course_mode.save()
     verified_course = CourseFactory.create(org='org', number='test', display_name='Test Course')
     self.verified_course_key = verified_course.id
     self.cart = Order.get_cart_for_user(self.user)
     self.addCleanup(patcher.stop)
Exemplo n.º 5
0
    def test_update_professional_expiration(self, mode_slug, expiration_datetime):
        """ Verify that pushing a mode with a professional certificate and an expiration datetime
        will be rejected (this is not allowed). """
        mode = self._serialize_course_mode(
            CourseMode(
                mode_slug=mode_slug,
                min_price=500,
                currency=u'USD',
                sku=u'ABC123',
                expiration_datetime=expiration_datetime
            )
        )
        course_id = unicode(self.course.id)
        payload = {u'id': course_id, u'modes': [mode]}
        path = reverse('commerce_api:v1:courses:retrieve_update', args=[course_id])

        expected_status = 400 if CourseMode.is_professional_slug(mode_slug) and expiration_datetime is not None else 200
        response = self.client.put(path, json.dumps(payload), content_type=JSON_CONTENT_TYPE)
        self.assertEqual(response.status_code, expected_status)
Exemplo n.º 6
0
    def test_update(self):
        """ Verify the view supports updating a course. """
        permission = Permission.objects.get(name='Can change course mode')
        self.user.user_permissions.add(permission)
        expected_course_mode = CourseMode(mode_slug=u'verified',
                                          min_price=200,
                                          currency=u'USD',
                                          sku=u'ABC123')
        expected = {
            u'id': unicode(self.course.id),
            u'modes': [self._serialize_course_mode(expected_course_mode)]
        }
        response = self.client.put(self.path,
                                   json.dumps(expected),
                                   content_type=JSON_CONTENT_TYPE)
        self.assertEqual(response.status_code, 200)

        actual = json.loads(response.content)
        self.assertEqual(actual, expected)
Exemplo n.º 7
0
 def test_generate_receipt_instructions(self):
     """
     Add 2 courses to the order and make sure the instruction_set only contains 1 element (no dups)
     """
     course2 = CourseFactory.create()
     course_mode2 = CourseMode(course_id=course2.id,
                               mode_slug="honor",
                               mode_display_name="honor cert",
                               min_price=self.cost)
     course_mode2.save()
     pr1 = PaidCourseRegistration.add_to_order(self.cart, self.course_key)
     pr2 = PaidCourseRegistration.add_to_order(self.cart, course2.id)
     self.cart.purchase()
     inst_dict, inst_set = self.cart.generate_receipt_instructions()
     self.assertEqual(2, len(inst_dict))
     self.assertEqual(1, len(inst_set))
     self.assertIn("dashboard", inst_set.pop())
     self.assertIn(pr1.pk_with_subclass, inst_dict)
     self.assertIn(pr2.pk_with_subclass, inst_dict)
    def setUp(self):
        """
        Set up tests
        """
        self.course = CourseFactory.create()

        self.course_mode = CourseMode(course_id=self.course.id,
                                      mode_slug="honor",
                                      mode_display_name="honor cert",
                                      min_price=40)
        self.course_mode.save()
        # Create instructor account
        self.instructor = AdminFactory.create()
        self.client.login(username=self.instructor.username, password="******")

        # URL for instructor dash
        self.url = reverse(
            'instructor_dashboard',
            kwargs={'course_id': self.course.id.to_deprecated_string()})
Exemplo n.º 9
0
    def test_create_with_non_existent_course(self):
        """ Verify the API does not allow data to be created for courses that do not exist. """

        permissions = Permission.objects.filter(
            name__in=('Can add course mode', 'Can change course mode'))
        for permission in permissions:
            self.user.user_permissions.add(permission)

        expected_modes = [
            CourseMode(mode_slug=CourseMode.DEFAULT_MODE_SLUG,
                       min_price=150,
                       currency=u'USD',
                       sku=u'ABC123',
                       bulk_sku=u'BULK-ABC123')
        ]

        course_key = 'non/existing/key'

        course_dict = {
            u'id':
            six.text_type(course_key),
            u'name':
            six.text_type('Non Existing Course'),
            u'verification_deadline':
            None,
            u'modes':
            [self._serialize_course_mode(mode) for mode in expected_modes]
        }

        path = reverse('commerce_api:v1:courses:retrieve_update',
                       args=[six.text_type(course_key)])

        response = self.client.put(path,
                                   json.dumps(course_dict),
                                   content_type=JSON_CONTENT_TYPE)
        self.assertEqual(response.status_code, 400)

        expected_dict = {
            'id': [u'Course {} does not exist.'.format(course_key)]
        }
        self.assertDictEqual(expected_dict,
                             json.loads(response.content.decode('utf-8')))
Exemplo n.º 10
0
    def update(self, attrs):
        """ Update the model with external data (usually passed via API call). """
        # There are possible downstream effects of settings self.verification_deadline to null,
        # so don't assign it a value here unless it is specifically included in attrs.
        if 'verification_deadline' in attrs:
            self.verification_deadline = attrs.get('verification_deadline')

        existing_modes = {mode.mode_slug: mode for mode in self.modes}
        merged_modes = set()
        merged_mode_keys = set()

        for posted_mode in attrs.get('modes', []):
            merged_mode = existing_modes.get(posted_mode.mode_slug, CourseMode())

            merged_mode.course_id = self.id
            merged_mode.mode_slug = posted_mode.mode_slug
            merged_mode.mode_display_name = posted_mode.mode_slug
            merged_mode.min_price = posted_mode.min_price
            merged_mode.currency = posted_mode.currency
            merged_mode.sku = posted_mode.sku
            merged_mode.bulk_sku = posted_mode.bulk_sku
            merged_mode.expiration_datetime = posted_mode.expiration_datetime
            merged_mode.save()

            merged_modes.add(merged_mode)
            merged_mode_keys.add(merged_mode.mode_slug)

        # Masters degrees are not sold through the eCommerce site.
        # So, Masters course modes are not included in PUT calls to this API,
        # and their omission which would normally cause them to be deleted.
        # We don't want that to happen, but for the time being,
        # we cannot include in Masters modes in the PUT calls from eCommerce.
        # So, here's hack to handle Masters course modes, along with any other
        # modes that end up in that boat.
        MODES_TO_NOT_DELETE = {
            CourseMode.MASTERS,
        }

        modes_to_delete = set(existing_modes.keys()) - merged_mode_keys
        modes_to_delete -= MODES_TO_NOT_DELETE
        self._deleted_modes = [existing_modes[mode] for mode in modes_to_delete]
        self.modes = list(merged_modes)
Exemplo n.º 11
0
    def test_update_overwrite(self):
        """ Verify that data submitted via PUT overwrites/deletes modes that are
        not included in the body of the request. """
        course_id = unicode(self.course.id)
        expected_course_mode = CourseMode(
            mode_slug=u'credit',
            min_price=500,
            currency=u'USD',
            sku=u'ABC123',
            bulk_sku=u'BULK-ABC123'
        )
        expected = self._serialize_course(self.course, [expected_course_mode])
        path = reverse('commerce_api:v1:courses:retrieve_update', args=[course_id])
        response = self.client.put(path, json.dumps(expected), content_type=JSON_CONTENT_TYPE)
        self.assertEqual(response.status_code, 200)
        actual = json.loads(response.content)
        self.assertEqual(actual, expected)

        # The existing CourseMode should have been removed.
        self.assertFalse(CourseMode.objects.filter(id=self.course_mode.id).exists())
Exemplo n.º 12
0
 def setUp(self):
     self.user = UserFactory.create()
     self.user.set_password('password')
     self.user.save()
     self.course_id = "MITx/999/Robot_Super_Course"
     self.cost = 40
     self.course = CourseFactory.create(org='MITx',
                                        number='999',
                                        display_name='Robot Super Course')
     self.course_mode = CourseMode(course_id=self.course_id,
                                   mode_slug="honor",
                                   mode_display_name="honor cert",
                                   min_price=self.cost)
     self.course_mode.save()
     self.verified_course_id = 'org/test/Test_Course'
     CourseFactory.create(org='org',
                          number='test',
                          run='course1',
                          display_name='Test Course')
     self.cart = Order.get_cart_for_user(self.user)
    def setUp(self):
        """
        Set up tests
        """
        super(TestInstructorDashboard, self).setUp()
        self.course = CourseFactory.create(
            grading_policy={"GRADE_CUTOFFS": {"A": 0.75, "B": 0.63, "C": 0.57, "D": 0.5}},
            display_name='<script>alert("XSS")</script>'
        )

        self.course_mode = CourseMode(course_id=self.course.id,
                                      mode_slug="honor",
                                      mode_display_name="honor cert",
                                      min_price=40)
        self.course_mode.save()
        # Create instructor account
        self.instructor = AdminFactory.create()
        self.client.login(username=self.instructor.username, password="******")

        # URL for instructor dash
        self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()})
Exemplo n.º 14
0
    def test_refund_cert_callback_before_expiration_email_error(self, error_logger):
        # If there's an error sending an email to billing, we need to log this error
        course_id = "refund_before_expiration/test/one"
        many_days = datetime.timedelta(days=60)

        CourseFactory.create(org='refund_before_expiration', number='test', run='course', display_name='one')
        course_mode = CourseMode(course_id=course_id,
                                 mode_slug="verified",
                                 mode_display_name="verified cert",
                                 min_price=self.cost,
                                 expiration_datetime=datetime.datetime.now(pytz.utc) + many_days)
        course_mode.save()

        CourseEnrollment.enroll(self.user, course_id, 'verified')
        cart = Order.get_cart_for_user(user=self.user)
        CertificateItem.add_to_order(cart, course_id, self.cost, 'verified')
        cart.purchase()

        with patch('shoppingcart.models.send_mail', side_effect=smtplib.SMTPException):
            CourseEnrollment.unenroll(self.user, course_id)
            self.assertTrue(error_logger.called)
    def setUp(self):
        """
        Set up tests
        """
        super(TestInstructorDashboardPerformance, self).setUp()
        self.course = CourseFactory.create(
            grading_policy={"GRADE_CUTOFFS": {"A": 0.75, "B": 0.63, "C": 0.57, "D": 0.5}},
            display_name='<script>alert("XSS")</script>',
            default_store=ModuleStoreEnum.Type.split
        )

        self.course_mode = CourseMode(
            course_id=self.course.id,
            mode_slug=CourseMode.DEFAULT_MODE_SLUG,
            mode_display_name=CourseMode.DEFAULT_MODE.name,
            min_price=40
        )
        self.course_mode.save()
        # Create instructor account
        self.instructor = AdminFactory.create()
        self.client.login(username=self.instructor.username, password="******")
Exemplo n.º 16
0
    def test_update_overwrite(self):
        """
        Verify that data submitted via PUT overwrites/deletes modes that are
        not included in the body of the request, EXCEPT the Masters mode,
        which it leaves alone.
        """
        existing_mode = self.course_mode
        existing_masters_mode = CourseMode.objects.create(
            course_id=self.course.id,
            mode_slug=u'masters',
            min_price=10000,
            currency=u'USD',
            sku=u'DEF456',
            bulk_sku=u'BULK-DEF456')
        new_mode = CourseMode(course_id=self.course.id,
                              mode_slug=u'credit',
                              min_price=500,
                              currency=u'USD',
                              sku=u'ABC123',
                              bulk_sku=u'BULK-ABC123')

        path = reverse('commerce_api:v1:courses:retrieve_update',
                       args=[six.text_type(self.course.id)])
        data = json.dumps(self._serialize_course(self.course, [new_mode]))
        response = self.client.put(path, data, content_type=JSON_CONTENT_TYPE)
        self.assertEqual(response.status_code, 200)

        # Check modes list in response, disregarding its order.
        expected_dict = self._serialize_course(self.course, [new_mode])
        expected_items = expected_dict['modes']
        actual_items = json.loads(response.content.decode('utf-8'))['modes']
        self.assertCountEqual(actual_items, expected_items)

        # The existing non-Masters CourseMode should have been removed.
        self.assertFalse(
            CourseMode.objects.filter(id=existing_mode.id).exists())

        # The existing Masters course mode should remain.
        self.assertTrue(
            CourseMode.objects.filter(id=existing_masters_mode.id).exists())
Exemplo n.º 17
0
    def test_paid_course_registration(self):
        """
        Make sure that Microsite overrides on the ENABLE_SHOPPING_CART and
        ENABLE_PAID_COURSE_ENROLLMENTS are honored
        """
        course_mode = CourseMode(
            course_id=self.course_with_visibility.id,
            mode_slug="honor",
            mode_display_name="honor cert",
            min_price=10,
        )
        course_mode.save()

        # first try on the non microsite, which
        # should pick up the global configuration (where ENABLE_PAID_COURSE_REGISTRATIONS = False)
        url = reverse(
            'about_course',
            args=[self.course_with_visibility.id.to_deprecated_string()])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertIn(
            "Enroll in {}".format(self.course_with_visibility.id.course),
            resp.content)
        self.assertNotIn(
            "Add {} to Cart ($10)".format(
                self.course_with_visibility.id.course), resp.content)

        # now try on the microsite
        url = reverse(
            'about_course',
            args=[self.course_with_visibility.id.to_deprecated_string()])
        resp = self.client.get(url, HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME)
        self.assertEqual(resp.status_code, 200)
        self.assertNotIn(
            "Enroll in {}".format(self.course_with_visibility.id.course),
            resp.content)
        self.assertIn(
            "Add {} to Cart <span>($10 USD)</span>".format(
                self.course_with_visibility.id.course), resp.content)
        self.assertIn('$("#add_to_cart_post").click', resp.content)
Exemplo n.º 18
0
    def test_update_course_price_check(self):
        price = 200
        # course B
        course2 = CourseFactory.create(org='EDX', display_name='test_course', number='100')
        mode = CourseMode(
            course_id=text_type(course2.id), mode_slug='honor',
            mode_display_name='honor', min_price=30, currency='usd'
        )
        mode.save()
        # course A update
        CourseMode.objects.filter(course_id=self.course.id).update(min_price=price)

        set_course_price_url = reverse('set_course_mode_price', kwargs={'course_id': text_type(self.course.id)})
        data = {'course_price': price, 'currency': 'usd'}
        response = self.client.post(set_course_price_url, data)
        self.assertIn('CourseMode price updated successfully', response.content)

        # Course A updated total amount should be visible in e-commerce page if the user is finance admin
        url = reverse('instructor_dashboard', kwargs={'course_id': text_type(self.course.id)})
        response = self.client.get(url)

        self.assertIn('Course price per seat: <span>$' + str(price) + '</span>', response.content)
Exemplo n.º 19
0
    def update(self, attrs):
        """ Update the model with external data (usually passed via API call). """
        existing_modes = {mode.mode_slug: mode for mode in self.modes}
        merged_modes = set()
        merged_mode_keys = set()

        for posted_mode in attrs.get('modes', []):
            merged_mode = existing_modes.get(posted_mode.mode_slug, CourseMode())

            merged_mode.course_id = self.id
            merged_mode.mode_slug = posted_mode.mode_slug
            merged_mode.mode_display_name = posted_mode.mode_slug
            merged_mode.min_price = posted_mode.min_price
            merged_mode.currency = posted_mode.currency
            merged_mode.sku = posted_mode.sku

            merged_modes.add(merged_mode)
            merged_mode_keys.add(merged_mode.mode_slug)

        deleted_modes = set(existing_modes.keys()) - merged_mode_keys
        self._deleted_modes = [existing_modes[mode] for mode in deleted_modes]
        self.modes = list(merged_modes)
Exemplo n.º 20
0
 def setUp(self):
     self.user = UserFactory.create(username="******", password="******")
     self.client.login(username="******", password="******")
     self.course_id = 'Robot/999/Test_Course'
     self.course = CourseFactory.create(org='Robot', number='999', display_name='Test Course')
     verified_mode = CourseMode(
         course_id=SlashSeparatedCourseKey("Robot", "999", 'Test_Course'),
         mode_slug="verified",
         mode_display_name="Verified Certificate",
         min_price=50
     )
     verified_mode.save()
     course_mode_post_data = {
         'certificate_mode': 'Select Certificate',
         'contribution': 50,
         'contribution-other-amt': '',
         'explain': ''
     }
     self.client.post(
         reverse("course_modes_choose", kwargs={'course_id': self.course_id}),
         course_mode_post_data
     )
Exemplo n.º 21
0
    def test_refund_cert_callback_after_expiration(self):
        # If the expiration date has passed, the user cannot get a refund
        many_days = datetime.timedelta(days=60)

        course = CourseFactory.create()
        course_key = course.id
        course_mode = CourseMode(course_id=course_key,
                                 mode_slug="verified",
                                 mode_display_name="verified cert",
                                 min_price=self.cost,)
        course_mode.save()

        CourseEnrollment.enroll(self.user, course_key, 'verified')
        cart = Order.get_cart_for_user(user=self.user)
        CertificateItem.add_to_order(cart, course_key, self.cost, 'verified')
        cart.purchase()

        course_mode.expiration_datetime = (datetime.datetime.now(pytz.utc) - many_days)
        course_mode.save()

        CourseEnrollment.unenroll(self.user, course_key)
        target_certs = CertificateItem.objects.filter(course_id=course_key, user_id=self.user, status='refunded', mode='verified')
        self.assertEqual(len(target_certs), 0)
Exemplo n.º 22
0
    def test_update_remove_verification_deadline(self):
        """
        Verify that verification deadlines can be removed through the API.
        """
        verification_deadline = datetime(year=1915, month=5, day=7, tzinfo=pytz.utc)
        response, __ = self._get_update_response_and_expected_data(None, verification_deadline)
        self.assertEqual(VerificationDeadline.deadline_for_course(self.course.id), verification_deadline)

        verified_mode = CourseMode(
            mode_slug=u'verified',
            min_price=200,
            currency=u'USD',
            sku=u'ABC123',
            bulk_sku=u'BULK-ABC123',
            expiration_datetime=None
        )
        updated_data = self._serialize_course(self.course, [verified_mode], None)
        updated_data['verification_deadline'] = None

        response = self.client.put(self.path, json.dumps(updated_data), content_type=JSON_CONTENT_TYPE)

        self.assertEqual(response.status_code, 200)
        self.assertIsNone(VerificationDeadline.deadline_for_course(self.course.id))
Exemplo n.º 23
0
    def test_refund_cert_callback_before_expiration(self):
        # If the expiration date has not yet passed on a verified mode, the user can be refunded
        many_days = datetime.timedelta(days=60)

        course = CourseFactory.create()
        course_key = course.id
        course_mode = CourseMode(course_id=course_key,
                                 mode_slug="verified",
                                 mode_display_name="verified cert",
                                 min_price=self.cost,
                                 expiration_datetime=(datetime.datetime.now(pytz.utc) + many_days))
        course_mode.save()

        CourseEnrollment.enroll(self.user, course_key, 'verified')
        cart = Order.get_cart_for_user(user=self.user)
        CertificateItem.add_to_order(cart, course_key, self.cost, 'verified')
        cart.purchase()

        CourseEnrollment.unenroll(self.user, course_key)
        target_certs = CertificateItem.objects.filter(course_id=course_key, user_id=self.user, status='refunded', mode='verified')
        self.assertTrue(target_certs[0])
        self.assertTrue(target_certs[0].refund_requested_time)
        self.assertEquals(target_certs[0].order.status, 'refunded')
Exemplo n.º 24
0
    def setUp(self):
        super(AboutTestCase, self).setUp()
        self.course = CourseFactory.create()
        self.about = ItemFactory.create(
            category="about", parent_location=self.course.location,
            data="OOGIE BLOOGIE", display_name="overview"
        )
        self.course_without_about = CourseFactory.create(catalog_visibility=CATALOG_VISIBILITY_NONE)
        self.about = ItemFactory.create(
            category="about", parent_location=self.course_without_about.location,
            data="WITHOUT ABOUT", display_name="overview"
        )
        self.course_with_about = CourseFactory.create(catalog_visibility=CATALOG_VISIBILITY_ABOUT)
        self.about = ItemFactory.create(
            category="about", parent_location=self.course_with_about.location,
            data="WITH ABOUT", display_name="overview"
        )

        self.purchase_course = CourseFactory.create(org='MITx', number='buyme', display_name='Course To Buy')
        self.course_mode = CourseMode(course_id=self.purchase_course.id,
                                      mode_slug="honor",
                                      mode_display_name="honor cert",
                                      min_price=10)
        self.course_mode.save()
Exemplo n.º 25
0
def add_course_mode(course, mode_slug=CourseMode.VERIFIED,
                    mode_display_name='Verified Certificate', upgrade_deadline_expired=False):
    """
    Add a course mode to the test course.

    Args:
        course
        mode_slug (str): the slug of the mode to add
        mode_display_name (str): the display name of the mode to add
        upgrade_deadline_expired (bool): whether the upgrade deadline has passed
    """
    upgrade_exp_date = now()
    if upgrade_deadline_expired:
        upgrade_exp_date = upgrade_exp_date - timedelta(days=21)
    else:
        upgrade_exp_date = upgrade_exp_date + timedelta(days=21)

    CourseMode(
        course_id=course.id,
        mode_slug=mode_slug,
        mode_display_name=mode_display_name,
        min_price=TEST_COURSE_PRICE,
        _expiration_datetime=upgrade_exp_date,
    ).save()
Exemplo n.º 26
0
 def _new_course_mode_models(modes_data):
     """Convert validated course mode data to CourseMode objects. """
     return [CourseMode(**modes_dict) for modes_dict in modes_data]
Exemplo n.º 27
0
    def setUp(self, cutoff_date):
        super(ReportTypeTests, self).setUp()
        cutoff_date.return_value = datetime.datetime.now(
            pytz.UTC) + datetime.timedelta(days=1)
        # Need to make a *lot* of users for this one
        self.first_verified_user = UserFactory.create(profile__name="John Doe")
        self.second_verified_user = UserFactory.create(
            profile__name="Jane Deer")
        self.first_audit_user = UserFactory.create(profile__name="Joe Miller")
        self.second_audit_user = UserFactory.create(
            profile__name="Simon Blackquill")
        self.third_audit_user = UserFactory.create(profile__name="Super Mario")
        self.honor_user = UserFactory.create(profile__name="Princess Peach")
        self.first_refund_user = UserFactory.create(
            profile__name="King Bowsér")
        self.second_refund_user = UserFactory.create(
            profile__name="Súsan Smith")

        # Two are verified, three are audit, one honor

        self.cost = 40
        self.course = CourseFactory.create(org='MITx',
                                           number='999',
                                           display_name=u'Robot Super Course')
        self.course_key = self.course.id
        course_mode = CourseMode(course_id=self.course_key,
                                 mode_slug="honor",
                                 mode_display_name="honor cert",
                                 min_price=self.cost)
        course_mode.save()

        course_mode2 = CourseMode(course_id=self.course_key,
                                  mode_slug="verified",
                                  mode_display_name="verified cert",
                                  min_price=self.cost)
        course_mode2.save()

        # User 1 & 2 will be verified
        self.cart1 = Order.get_cart_for_user(self.first_verified_user)
        CertificateItem.add_to_order(self.cart1, self.course_key, self.cost,
                                     'verified')
        self.cart1.purchase()

        self.cart2 = Order.get_cart_for_user(self.second_verified_user)
        CertificateItem.add_to_order(self.cart2, self.course_key, self.cost,
                                     'verified')
        self.cart2.purchase()

        # Users 3, 4, and 5 are audit
        CourseEnrollment.enroll(self.first_audit_user, self.course_key,
                                "audit")
        CourseEnrollment.enroll(self.second_audit_user, self.course_key,
                                "audit")
        CourseEnrollment.enroll(self.third_audit_user, self.course_key,
                                "audit")

        # User 6 is honor
        CourseEnrollment.enroll(self.honor_user, self.course_key, "honor")

        self.now = datetime.datetime.now(pytz.UTC)

        # Users 7 & 8 are refunds
        self.cart = Order.get_cart_for_user(self.first_refund_user)
        CertificateItem.add_to_order(self.cart, self.course_key, self.cost,
                                     'verified')
        self.cart.purchase()
        CourseEnrollment.unenroll(self.first_refund_user, self.course_key)

        self.cart = Order.get_cart_for_user(self.second_refund_user)
        CertificateItem.add_to_order(self.cart, self.course_key, self.cost,
                                     'verified')
        self.cart.purchase(self.second_refund_user.username, self.course_key)
        CourseEnrollment.unenroll(self.second_refund_user, self.course_key)

        self.test_time = datetime.datetime.now(pytz.UTC)

        first_refund = CertificateItem.objects.get(id=3)
        first_refund.fulfilled_time = self.test_time
        first_refund.refund_requested_time = self.test_time
        first_refund.save()

        second_refund = CertificateItem.objects.get(id=4)
        second_refund.fulfilled_time = self.test_time
        second_refund.refund_requested_time = self.test_time
        second_refund.save()

        self.CORRECT_REFUND_REPORT_CSV = dedent(u"""
            Order Number,Customer Name,Date of Original Transaction,Date of Refund,Amount of Refund,Service Fees (if any)
            3,King Bowsér,{time_str},{time_str},40.00,0.00
            4,Súsan Smith,{time_str},{time_str},40.00,0.00
            """.format(time_str=str(self.test_time)))

        self.CORRECT_CERT_STATUS_CSV = dedent("""
            University,Course,Course Announce Date,Course Start Date,Course Registration Close Date,Course Registration Period,Total Enrolled,Audit Enrollment,Honor Code Enrollment,Verified Enrollment,Gross Revenue,Gross Revenue over the Minimum,Number of Verified Students Contributing More than the Minimum,Number of Refunds,Dollars Refunded
            MITx,999 Robot Super Course,,,,,6,3,1,2,80.00,0.00,0,2,80.00
            """.format(time_str=str(self.test_time)))

        self.CORRECT_UNI_REVENUE_SHARE_CSV = dedent("""
            University,Course,Number of Transactions,Total Payments Collected,Service Fees (if any),Number of Successful Refunds,Total Amount of Refunds
            MITx,999 Robot Super Course,6,80.00,0.00,2,80.00
            """.format(time_str=str(self.test_time)))
Exemplo n.º 28
0
    def setUp(self):
        super(TestOrderHistoryOnSiteDashboard, self).setUp()

        patcher = patch('student.models.tracker')
        self.mock_tracker = patcher.start()
        self.user = UserFactory.create()
        self.user.set_password('password')
        self.user.save()

        self.addCleanup(patcher.stop)

        # First Order with our (fakeX) site's course.
        course1 = CourseFactory.create(org='fakeX', number='999', display_name='fakeX Course')
        course1_key = course1.id
        course1_mode = CourseMode(course_id=course1_key,
                                  mode_slug="honor",
                                  mode_display_name="honor cert",
                                  min_price=20)
        course1_mode.save()

        cart = Order.get_cart_for_user(self.user)
        PaidCourseRegistration.add_to_order(cart, course1_key)
        cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
        self.fakex_site_order_id = cart.id

        # Second Order with another(fooX) site's course
        course2 = CourseFactory.create(org='fooX', number='888', display_name='fooX Course')
        course2_key = course2.id
        course2_mode = CourseMode(course_id=course2.id,
                                  mode_slug="honor",
                                  mode_display_name="honor cert",
                                  min_price=20)
        course2_mode.save()

        cart = Order.get_cart_for_user(self.user)
        PaidCourseRegistration.add_to_order(cart, course2_key)
        cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
        self.foox_site_order_id = cart.id

        # Third Order with course not attributed to any site.
        course3 = CourseFactory.create(org='fakeOtherX', number='777', display_name='fakeOtherX Course')
        course3_key = course3.id
        course3_mode = CourseMode(course_id=course3.id,
                                  mode_slug="honor",
                                  mode_display_name="honor cert",
                                  min_price=20)
        course3_mode.save()

        cart = Order.get_cart_for_user(self.user)
        PaidCourseRegistration.add_to_order(cart, course3_key)
        cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
        self.order_id = cart.id

        # Fourth Order with course not attributed to any site but with a CertificateItem
        course4 = CourseFactory.create(org='fakeOtherX', number='888')
        course4_key = course4.id
        course4_mode = CourseMode(course_id=course4.id,
                                  mode_slug="verified",
                                  mode_display_name="verified cert",
                                  min_price=20)
        course4_mode.save()

        cart = Order.get_cart_for_user(self.user)
        CertificateItem.add_to_order(cart, course4_key, 20.0, 'verified')
        cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
        self.certificate_order_id = cart.id

        # Fifth Order with course not attributed to any site but with a Donation
        course5 = CourseFactory.create(org='fakeOtherX', number='999')
        course5_key = course5.id

        cart = Order.get_cart_for_user(self.user)
        Donation.add_to_order(cart, 20.0, course5_key)
        cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
        self.donation_order_id = cart.id

        # also add a donation not associated with a course to make sure the None case works OK
        Donation.add_to_order(cart, 10.0, None)
        cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
        self.courseless_donation_order_id = cart.id
Exemplo n.º 29
0
 def test_get_mode_display_name_unknown_slug(self):
     """ Verify the method returns the slug if it has no known mapping. """
     mode = CourseMode(mode_slug='Blah!')
     self.assertEqual(self.course.get_mode_display_name(mode),
                      mode.mode_slug)
Exemplo n.º 30
0
 def test_get_mode_display_name(self, slug, expected_display_name):
     """ Verify the method properly maps mode slugs to display names. """
     mode = CourseMode(mode_slug=slug)
     self.assertEqual(self.course.get_mode_display_name(mode),
                      expected_display_name)