Example #1
0
    def test_validation_filters(self):
        """
        Test the admin validation filters.

        This filters receipts by the validation status.
        """
        validated_receipt = factories.ReceiptFactory()
        failed_validation_receipt = factories.ReceiptFactory()
        not_validated_receipt = factories.ReceiptFactory()

        factories.ReceiptValidationFactory(receipt=validated_receipt)
        factories.ReceiptValidationFactory(
            result=models.ReceiptValidation.RESULT_REJECTED,
            receipt=failed_validation_receipt,
        )

        client = Client()
        client.force_login(User.objects.first())

        response = client.get("/admin/afip/receipt/?status=validated")
        self.assertContains(
            response,
            '<input class="action-select" name="_selected_action" value="{}" '
            'type="checkbox">'.format(validated_receipt.pk),
            html=True,
        )
        self.assertNotContains(
            response,
            '<input class="action-select" name="_selected_action" value="{}" '
            'type="checkbox">'.format(not_validated_receipt.pk),
            html=True,
        )
        self.assertNotContains(
            response,
            '<input class="action-select" name="_selected_action" value="{}" '
            'type="checkbox">'.format(failed_validation_receipt.pk),
            html=True,
        )

        response = client.get("/admin/afip/receipt/?status=not_validated")
        self.assertNotContains(
            response,
            '<input class="action-select" name="_selected_action" value="{}" '
            'type="checkbox">'.format(validated_receipt.pk),
            html=True,
        )
        self.assertContains(
            response,
            '<input class="action-select" name="_selected_action" value="{}" '
            'type="checkbox">'.format(not_validated_receipt.pk),
            html=True,
        )
        self.assertContains(
            response,
            '<input class="action-select" name="_selected_action" value="{}" '
            'type="checkbox">'.format(failed_validation_receipt.pk),
            html=True,
        )
Example #2
0
    def test_failed_validation(self):
        # These should never really exist,but oh well:
        receipt = factories.ReceiptFactory()
        factories.ReceiptValidationFactory(
            receipt=receipt,
            result=models.ReceiptValidation.RESULT_REJECTED,
        )
        self.assertEqual(receipt.is_validated, False)

        receipt = factories.ReceiptFactory(receipt_number=1)
        factories.ReceiptValidationFactory(
            receipt=receipt,
            result=models.ReceiptValidation.RESULT_REJECTED,
        )
        self.assertEqual(receipt.is_validated, False)
Example #3
0
    def test_generate_barcode(self):
        """
        Test that barcode generation matches that from a pre-generated example.
        """
        receipt = factories.ReceiptFactory(
            point_of_sales__number=1,
            receipt_type__code=11,
        )
        factories.ReceiptValidationFactory(receipt=receipt,)

        generator = ReceiptBarcodeGenerator(receipt)
        barcode = generator.generate_barcode(SVGWriter)

        # Remove the line that stamps the pyBarcode version
        # Otherwise this test will break as soon as a new release comes out.
        lines = [
            line for line in barcode.splitlines()
            if b'Autogenerated with python-barcode' not in line
        ]

        directory = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(directory, 'barcode.svg')

        with open(path, 'rb') as f:
            self.assertEqual(lines, f.read().splitlines())
Example #4
0
    def setUp(self):
        self.user = factories.SuperUserFactory()

        validation = factories.ReceiptValidationFactory()
        self.with_file = factories.ReceiptPDFFactory(
            receipt=validation.receipt, )
        self.without_file = factories.ReceiptPDFFactory()

        self.assertFalse(self.without_file.pdf_file)
        self.assertTrue(self.with_file.pdf_file)

        self.client = Client()
        self.client.force_login(User.objects.first())
Example #5
0
def test_template_discovery(client):
    taxpayer = factories.TaxPayerFactory(cuit="20329642330")
    factories.TaxPayerProfileFactory(taxpayer=taxpayer)
    pdf = factories.ReceiptPDFFactory(
        receipt__point_of_sales__owner=taxpayer,
        receipt__point_of_sales__number=9999,
        receipt__receipt_type__code=6,
    )
    factories.ReceiptValidationFactory(receipt=pdf.receipt)

    client = Client()
    response = client.get("{}?html=true".format(
        reverse("receipt_displaypdf_view", args=(pdf.receipt.pk, ))))

    assert response.content == b"This is a dummy template to test template discovery.\n"
Example #6
0
    def test_pdf_generation(self):
        """
        Test PDF file generation.

        For the moment, this test case mostly verifies that pdf generation
        *works*, but does not actually validate the pdf file itself.

        Running this locally *will* yield the file itself, which is useful for
        manual inspection.
        """
        pdf = factories.ReceiptPDFFactory(receipt__receipt_number=3)
        factories.ReceiptValidationFactory(receipt=pdf.receipt)
        pdf.save_pdf()
        self.assertTrue(pdf.pdf_file.name.startswith('receipts/'))
        self.assertTrue(pdf.pdf_file.name.endswith('.pdf'))
Example #7
0
    def test_pdf_view(self):
        """
        Test the PDF generation view.
        """
        taxpayer = factories.TaxPayerFactory()

        factories.TaxPayerProfileFactory(taxpayer=taxpayer)
        pdf = factories.ReceiptPDFFactory(
            receipt__point_of_sales__owner=taxpayer, )
        factories.ReceiptValidationFactory(receipt=pdf.receipt)

        client = Client()
        response = client.get(
            reverse("receipt_pdf_view", args=(pdf.receipt.pk, )))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content[:7], b"%PDF-1.")

        headers = sorted(response.serialize_headers().decode().splitlines())
        self.assertIn("Content-Type: application/pdf", headers)
Example #8
0
    def test_logo_in_html(self):
        """Test the HTML generation view."""
        pdf = factories.ReceiptPDFFactory()
        factories.ReceiptValidationFactory(receipt=pdf.receipt)
        factories.TaxPayerExtras(taxpayer=pdf.receipt.point_of_sales.owner)

        client = Client()
        response = client.get("{}?html=true".format(
            reverse("receipt_displaypdf_view", args=(pdf.receipt.pk, ))))

        self.assertContains(
            response,
            """
            <address>
            <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QgLERgyoZWu2QAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAEklEQVQI12P4//8/AwT8//8fACnkBft7DmIIAAAAAElFTkSuQmCC" alt="Logo"><br>
            <strong>Alice Doe</strong><br>
            Happy Street 123, CABA<br>

            Responsable Monotributo<br>
            </address>
            """,  # noqa: E501: It's just long stuff. :(
            html=True,
        )
Example #9
0
    def test_validated_receipt(self):
        validation = factories.ReceiptValidationFactory()
        printable = factories.ReceiptPDFFactory(receipt=validation.receipt)

        self.assertTrue(printable.pdf_file)
        self.assertTrue(printable.pdf_file.name.endswith('.pdf'))
Example #10
0
 def test_validated(self):
     receipt = factories.ReceiptFactory(receipt_number=1)
     factories.ReceiptValidationFactory(receipt=receipt)
     self.assertEqual(receipt.is_validated, True)
Example #11
0
    def test_html_view(self):
        """Test the HTML generation view."""
        pdf = factories.ReceiptPDFFactory(
            receipt__concept__code=1,
            receipt__issued_date=date(2017, 5, 15),
            receipt__receipt_type__code=11,
        )
        factories.ReceiptValidationFactory(receipt=pdf.receipt)

        client = Client()
        response = client.get("{}?html=true".format(
            reverse("receipt_displaypdf_view", args=(pdf.receipt.pk, ))))

        self.assertHTMLEqual(
            response.content.decode(),
            """
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="/static/receipts/receipt.css">
  </head>
  <body>
    <div class="receipt">

      <header>
        <div class="taxpayer-details group">
          <address>
            <strong>Alice Doe</strong><br>
            Happy Street 123, CABA<br>

            Responsable Monotributo<br>
          </address>

          <div class="receipt-type">
            <div class="identifier">
              C
            </div>
            <div class="code">
              Código 11
            </div>
          </div>

          <div class="receipt-details">
            <div class="receipt-type-description">
              Factura C
            </div>
            <strong>Nº</strong> None
            <br>
            <strong>Fecha de emisión:</strong> <time>May 15, 2017</time><br>
            <strong>CUIT:</strong> 20-32964233-0<br>
            <strong>Ingresos Brutos:</strong> Convenio Multilateral<br>
            <strong>Inicio de Actividades:</strong> Oct. 3, 2011
          </div>
        </div>

        <hr>

        <div class="client">
          <div><strong>Facturado a:</strong></div>
          <div class="sale-conditions">
            <strong>Condición de IVA:</strong> Consumidor Final<br>
            <strong>Condición de Pago:</strong> Contado
          </div>
          <div class="client-data">
            John Doe, DNI 203012345<br>
            La Rioja 123<br />X5000EVX Córdoba<br>
          </div>
        </div>

      </header>

      <hr>

      <table>
        <thead>
          <tr>
            <th>Descripción</th>
            <th>Cantidad</th>
            <th>Precio Unitario</th>
            <th>Monto</th>
          </tr>
        </thead>
        <tbody>

        </tbody>
        <tfoot>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td>130.00</td>
          </tr>
        </tfoot>
      </table>

      <footer>
        <p class="cae">
          <strong>CAE</strong>
          67190616790549
          <strong>Vto CAE</strong>
          July 12, 2017
        </p>

        <div class="barcode">
          <img src="data:image/png;base64,iVBORw0KGgoAAAANSUh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BD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAh7oFAKBD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAh7oFAKBD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAh7oFAKBD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAh7oFAKBD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAh7oFAKBD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAh7oFAKBD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAh7oFAKBD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAh7oFAKBD3QIA0KFuAQDoULcAAHSoWwAAOtQtAAAd6hYAgA51CwBAx7pt27tnAACAe/juFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAECHugUAoEPdAgDQoW4BAOhQtwAAdKhbAAA61C0AAB3qFgCADnULAEDHFwNjQDppFfzwAAAAAElFTkSuQmCC">
        </div>

        Consultas de validez:
        <a href="http://www.afip.gob.ar/genericos/consultacae/">
          http://www.afip.gob.ar/genericos/consultacae/
        </a>
        <br>
        Teléfono Gratuito CABA, Área de Defensa y Protección al Consumidor.
        Tel 147
      </footer>

    </div>
  </body>
</html>
            """,  # noqa: E501: It's just long stuff. :(
        )