def test_course_sale_features(self): query_features = [ 'company_name', 'company_contact_name', 'company_contact_email', 'total_codes', 'total_used_codes', 'total_amount', 'created', 'customer_reference_number', 'recipient_name', 'recipient_email', 'created_by', 'internal_reference', 'invoice_number', 'codes', 'course_id' ] #create invoice sale_invoice = Invoice.objects.create( total_amount=1234.32, company_name='Test1', company_contact_name='TestName', company_contact_email='*****@*****.**', recipient_name='Testw_1', recipient_email='*****@*****.**', customer_reference_number='2Fwe23S', internal_reference="ABC", course_id=self.course.id) invoice_item = CourseRegistrationCodeInvoiceItem.objects.create( invoice=sale_invoice, qty=1, unit_price=1234.32, course_id=self.course.id) for i in range(5): course_code = CourseRegistrationCode(code="test_code{}".format(i), course_id=text_type( self.course.id), created_by=self.instructor, invoice=sale_invoice, invoice_item=invoice_item, mode_slug='honor') course_code.save() course_sale_records_list = sale_record_features( self.course.id, query_features) for sale_record in course_sale_records_list: self.assertEqual(sale_record['total_amount'], sale_invoice.total_amount) self.assertEqual(sale_record['recipient_email'], sale_invoice.recipient_email) self.assertEqual(sale_record['recipient_name'], sale_invoice.recipient_name) self.assertEqual(sale_record['company_name'], sale_invoice.company_name) self.assertEqual(sale_record['company_contact_name'], sale_invoice.company_contact_name) self.assertEqual(sale_record['company_contact_email'], sale_invoice.company_contact_email) self.assertEqual(sale_record['internal_reference'], sale_invoice.internal_reference) self.assertEqual(sale_record['customer_reference_number'], sale_invoice.customer_reference_number) self.assertEqual(sale_record['invoice_number'], sale_invoice.id) self.assertEqual(sale_record['created_by'], self.instructor) self.assertEqual(sale_record['total_used_codes'], 0) self.assertEqual(sale_record['total_codes'], 5)
def add_reg_code(self, course_key): """ add dummy registration code into models """ course_reg_code = CourseRegistrationCode(code=self.reg_code, course_id=course_key, transaction_group_name='A', created_by=self.user) course_reg_code.save()
def test_course_registration_features(self): query_features = ['code', 'course_id', 'transaction_group_name', 'created_by', 'redeemed_by'] for i in range(5): course_code = CourseRegistrationCode( code="test_code{}".format(i), course_id=self.course_key.to_deprecated_string(), transaction_group_name='TestName', created_by=self.users[0] ) course_code.save() order = Order(user=self.users[0], status='purchased') order.save() registration_code_redemption = RegistrationCodeRedemption( order=order, registration_code_id=1, redeemed_by=self.users[0] ) registration_code_redemption.save() registration_codes = CourseRegistrationCode.objects.all() course_registration_list = course_registration_features(query_features, registration_codes, csv_type='download') self.assertEqual(len(course_registration_list), len(registration_codes)) for course_registration in course_registration_list: self.assertEqual(set(course_registration.keys()), set(query_features)) self.assertIn(course_registration['code'], [registration_code.code for registration_code in registration_codes]) self.assertIn( course_registration['course_id'], [registration_code.course_id.to_deprecated_string() for registration_code in registration_codes] ) self.assertIn( course_registration['transaction_group_name'], [registration_code.transaction_group_name for registration_code in registration_codes] )
def test_add_coupon(self): """ Test Add Coupon Scenarios. Handle all the HttpResponses return by add_coupon view """ # URL for add_coupon add_coupon_url = reverse('add_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()}) expiration_date = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2) data = { 'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(), 'description': 'ADSADASDSAD', 'created_by': self.instructor, 'discount': 5, 'expiration_date': '{month}/{day}/{year}'.format(month=expiration_date.month, day=expiration_date.day, year=expiration_date.year) } response = self.client.post(add_coupon_url, data) self.assertTrue("coupon with the coupon code ({code}) added successfully".format(code=data['code']) in response.content) #now add the coupon with the wrong value in the expiration_date # server will through the ValueError Exception in the expiration_date field data = { 'code': '213454', 'course_id': self.course.id.to_deprecated_string(), 'description': 'ADSADASDSAD', 'created_by': self.instructor, 'discount': 5, 'expiration_date': expiration_date.strftime('"%d/%m/%Y') } response = self.client.post(add_coupon_url, data) self.assertTrue("Please enter the date in this format i-e month/day/year" in response.content) data = { 'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(), 'description': 'asdsasda', 'created_by': self.instructor, 'discount': 99 } response = self.client.post(add_coupon_url, data) self.assertTrue("coupon with the coupon code ({code}) already exist".format(code='A2314') in response.content) response = self.client.post(self.url) self.assertTrue('<td>ADSADASDSAD</td>' in response.content) self.assertTrue('<td>A2314</td>' in response.content) self.assertFalse('<td>111</td>' in response.content) data = { 'code': 'A2345314', 'course_id': self.course.id.to_deprecated_string(), 'description': 'asdsasda', 'created_by': self.instructor, 'discount': 199 } response = self.client.post(add_coupon_url, data) self.assertTrue("Please Enter the Coupon Discount Value Less than or Equal to 100" in response.content) data['discount'] = '25%' response = self.client.post(add_coupon_url, data=data) self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content) course_registration = CourseRegistrationCode( code='Vs23Ws4j', course_id=unicode(self.course.id), created_by=self.instructor, mode_slug='honor' ) course_registration.save() data['code'] = 'Vs23Ws4j' response = self.client.post(add_coupon_url, data) self.assertTrue("The code ({code}) that you have tried to define is already in use as a registration code" .format(code=data['code']) in response.content)
def test_update_coupon(self): """ Test Update Coupon Info Scenarios. Handle all the HttpResponses return by update_coupon view """ coupon = Coupon(code='AS452', description='asdsadsa', course_id=self.course.id.to_deprecated_string(), percentage_discount=10, created_by=self.instructor) coupon.save() response = self.client.post(self.url) self.assertTrue('<td>AS452</td>' in response.content) data = { 'coupon_id': coupon.id, 'code': 'update_code', 'discount': '12', 'course_id': coupon.course_id.to_deprecated_string() } # URL for update_coupon update_coupon_url = reverse( 'update_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(update_coupon_url, data=data) self.assertTrue( 'coupon with the coupon id ({coupon_id}) updated Successfully'. format(coupon_id=coupon.id) in response.content) response = self.client.post(self.url) self.assertTrue('<td>update_code</td>' in response.content) self.assertTrue('<td>12</td>' in response.content) data['coupon_id'] = 1000 # Coupon Not Exist with this ID response = self.client.post(update_coupon_url, data=data) self.assertTrue( 'coupon with the coupon id ({coupon_id}) DoesNotExist'.format( coupon_id=1000) in response.content) data['coupon_id'] = coupon.id data['discount'] = 123 response = self.client.post(update_coupon_url, data=data) self.assertTrue( 'Please Enter the Coupon Discount Value Less than or Equal to 100' in response.content) data['discount'] = '25%' response = self.client.post(update_coupon_url, data=data) self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content) data['coupon_id'] = '' # Coupon id is not provided response = self.client.post(update_coupon_url, data=data) self.assertTrue('coupon id not found' in response.content) coupon1 = Coupon(code='11111', description='coupon', course_id=self.course.id.to_deprecated_string(), percentage_discount=20, created_by=self.instructor) coupon1.save() data = {'coupon_id': coupon.id, 'code': '11111', 'discount': '12'} # pylint: disable=E1101 response = self.client.post(update_coupon_url, data=data) self.assertTrue( 'coupon with the coupon id ({coupon_id}) already exist'.format( coupon_id=coupon.id) in response.content) # pylint: disable=E1101 course_registration = CourseRegistrationCode( code='Vs23Ws4j', course_id=self.course.id.to_deprecated_string(), transaction_group_name='Test Group', created_by=self.instructor) course_registration.save() data = { 'coupon_id': coupon.id, 'code': 'Vs23Ws4j', # pylint: disable=E1101 'discount': '6', 'course_id': coupon.course_id.to_deprecated_string() } # pylint: disable=E1101 response = self.client.post(update_coupon_url, data=data) self.assertTrue( "The code ({code}) that you have tried to define is already in use as a registration code" .format(code=data['code']) in response.content)
def test_add_coupon(self): """ Test Add Coupon Scenarios. Handle all the HttpResponses return by add_coupon view """ # URL for add_coupon add_coupon_url = reverse( 'add_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = { 'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(), 'description': 'ADSADASDSAD', 'created_by': self.instructor, 'discount': 5 } response = self.client.post(add_coupon_url, data) self.assertTrue( "coupon with the coupon code ({code}) added successfully".format( code=data['code']) in response.content) data = { 'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(), 'description': 'asdsasda', 'created_by': self.instructor, 'discount': 99 } response = self.client.post(add_coupon_url, data) self.assertTrue( "coupon with the coupon code ({code}) already exist".format( code='A2314') in response.content) response = self.client.post(self.url) self.assertTrue('<td>ADSADASDSAD</td>' in response.content) self.assertTrue('<td>A2314</td>' in response.content) self.assertFalse('<td>111</td>' in response.content) data = { 'code': 'A2345314', 'course_id': self.course.id.to_deprecated_string(), 'description': 'asdsasda', 'created_by': self.instructor, 'discount': 199 } response = self.client.post(add_coupon_url, data) self.assertTrue( "Please Enter the Coupon Discount Value Less than or Equal to 100" in response.content) data['discount'] = '25%' response = self.client.post(add_coupon_url, data=data) self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content) course_registration = CourseRegistrationCode( code='Vs23Ws4j', course_id=self.course.id.to_deprecated_string(), transaction_group_name='Test Group', created_by=self.instructor) course_registration.save() data['code'] = 'Vs23Ws4j' response = self.client.post(add_coupon_url, data) self.assertTrue( "The code ({code}) that you have tried to define is already in use as a registration code" .format(code=data['code']) in response.content)