예제 #1
0
    def test_invalid_image_path(self):
        PDFInvoice(items_data=self.items_data,
                   item_id=self.item_id,
                   date=self.date,
                   is_invoice=self.is_invoice,
                   total_cost=self.total_cost,
                   payment_received=self.payment_received,
                   balance=self.balance).generate_pdf(self.pdf_buffer)

        pdf_content = parse_pages(self.pdf_buffer, 'test_pass')
        self.assertTrue(any('Receipt' in s for s in pdf_content))
예제 #2
0
    def test_pdf_receipt_file_footer_pagination(self):
        for i in range(2, 44):
            self.items_data.append(self.get_item_data(i))

        PDFInvoice(items_data=self.items_data,
                   item_id=self.item_id,
                   date=self.date,
                   is_invoice=self.is_invoice,
                   total_cost=self.total_cost,
                   payment_received=self.payment_received,
                   balance=self.balance).generate_pdf(self.pdf_buffer)

        pdf_content = parse_pages(self.pdf_buffer, 'test_pass')
        self.assertTrue(any('Receipt' in s for s in pdf_content))
예제 #3
0
    def test_pdf_invoice_with_default_settings(self):
        self.is_invoice = True
        PDFInvoice(
            items_data=self.items_data,
            item_id=self.item_id,
            date=self.date,
            is_invoice=self.is_invoice,
            total_cost=self.total_cost,
            payment_received=self.payment_received,
            balance=self.balance
        ).generate_pdf(self.pdf_buffer)

        pdf_content = parse_pages(self.pdf_buffer, 'test_pass')
        self.assertTrue(any(settings.PDF_RECEIPT_TAX_ID in s for s in pdf_content))
        self.assertTrue(any('Invoice' in s for s in pdf_content))
        self.assertTrue(any(settings.PDF_RECEIPT_TERMS_AND_CONDITIONS in s for s in pdf_content))
예제 #4
0
 def test_pdf_receipt_not_configured_generation(self):
     PDFInvoice(
         items_data=self.items_data,
         item_id=self.item_id,
         date=self.date,
         is_invoice=self.is_invoice,
         total_cost=self.total_cost,
         payment_received=self.payment_received,
         balance=self.balance
     ).generate_pdf(self.pdf_buffer)
     pdf_content = parse_pages(self.pdf_buffer, 'test_pass')
     self.assertTrue(any('Receipt' in s for s in pdf_content))
     self.assertTrue(any(settings.PDF_RECEIPT_DISCLAIMER_TEXT in s for s in pdf_content))
     self.assertTrue(any(settings.PDF_RECEIPT_BILLING_ADDRESS in s for s in pdf_content))
     self.assertTrue(any(settings.PDF_RECEIPT_FOOTER_TEXT in s for s in pdf_content))
     # PDF_RECEIPT_TERMS_AND_CONDITIONS not displayed in the receipt pdf
     self.assertFalse(any(settings.PDF_RECEIPT_TERMS_AND_CONDITIONS in s for s in pdf_content))
예제 #5
0
 def test_pdf_invoice_with_settings_from_patch(self):
     self.is_invoice = True
     PDFInvoice(items_data=self.items_data,
                item_id=self.item_id,
                date=self.date,
                is_invoice=self.is_invoice,
                total_cost=self.total_cost,
                payment_received=self.payment_received,
                balance=self.balance).generate_pdf(self.pdf_buffer)
     pdf_content = parse_pages(self.pdf_buffer, 'test_pass')
     self.assertTrue(any('46-0807740' in s for s in pdf_content))
     self.assertTrue(any('Invoice' in s for s in pdf_content))
     self.assertTrue(any(str(self.total_cost) in s for s in pdf_content))
     self.assertTrue(
         any(str(self.payment_received) in s for s in pdf_content))
     self.assertTrue(any(str(self.balance) in s for s in pdf_content))
     self.assertTrue(any('edX Tax ID' in s for s in pdf_content))
     self.assertTrue(
         any('Enrollments:\nEnrollments must be completed within 7 full'
             ' days from the course start date.\nPayment Terms:\nPayment'
             ' is due immediately.' in s for s in pdf_content))
예제 #6
0
    def test_pdf_receipt_configured_generation(self):
        PDFInvoice(
            items_data=self.items_data,
            item_id=self.item_id,
            date=self.date,
            is_invoice=self.is_invoice,
            total_cost=self.total_cost,
            payment_received=self.payment_received,
            balance=self.balance
        ).generate_pdf(self.pdf_buffer)
        pdf_content = parse_pages(self.pdf_buffer, 'test_pass')
        self.assertTrue(any('Receipt' in s for s in pdf_content))
        self.assertTrue(any(str(self.total_cost) in s for s in pdf_content))
        self.assertTrue(any(str(self.payment_received) in s for s in pdf_content))
        self.assertTrue(any(str(self.balance) in s for s in pdf_content))
        self.assertFalse(any('edX Tax ID' in s for s in pdf_content))

        # PDF_RECEIPT_TERMS_AND_CONDITIONS not displayed in the receipt pdf
        self.assertFalse(any(
            'Enrollments:\nEnrollments must be completed within 7 full days from the course'
            ' start date.\nPayment Terms:\nPayment is due immediately.' in s for s in pdf_content
        ))
        self.assertTrue(any('edX\n141 Portland St.\n9th Floor\nCambridge,\nMA 02139' in s for s in pdf_content))
예제 #7
0
    def generate_pdf_receipt(self):
        """
        Generates the pdf receipt for the order
        and returns the pdf_buffer.
        """
        items_data = []

        items_data.append({
            'item_description': self.item_name,
            'quantity': 1,
            'list_price': self.item_price,
            'discount': self.item_price - self.discounted_price,
            'item_total': self.item_price
        })
        pdf_buffer = BytesIO()

        PDFInvoice(items_data=items_data,
                   item_id=str(self.id),
                   date=self.purchase_time,
                   is_invoice=False,
                   total_cost=self.item_price,
                   payment_received=self.item_price,
                   balance=0).generate_pdf(pdf_buffer)
        return pdf_buffer