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 test_course_sale_no_codes(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=0.00, 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) CourseRegistrationCodeInvoiceItem.objects.create( invoice=sale_invoice, qty=0, unit_price=0.00, course_id=self.course.id) 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'], None) self.assertEqual(sale_record['total_used_codes'], 0) self.assertEqual(sale_record['total_codes'], 0)