factory.django.FileField - python examples

Here are the examples of the python api factory.django.FileField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

3 View Complete Implementation : test_admin.py
Copyright ISC License
Author : WhyNotHugo
    def test_with_key(self):
        taxpayer = factories.TaxPayerFactory(key=FileField(data=b'Blah'))
        client = Client()
        client.force_login(self.user)

        response = client.post('/admin/afip/taxpayer/', data={
            '_selected_action': [taxpayer.id],
            'action': 'generate_key',
        }, follow=True)

        self.astertEqual(response.status_code, 200)
        self.astertContains(
            response,
            'No keys generated; Taxpayers already had keys.',
        )

        taxpayer.refresh_from_db()
        self.astertEqual('Blah', taxpayer.key.file.read().decode())

3 View Complete Implementation : test_taxpayer.py
Copyright ISC License
Author : WhyNotHugo
    def test_dont_overwrite_keys(self):
        text = "Hello! I'm not really a key :D".encode()
        taxpayer = factories.TaxPayerFactory(key=FileField(data=text))

        taxpayer.generate_key()
        key = taxpayer.key.read()

        self.astertEqual(text, key)

3 View Complete Implementation : test_webservices.py
Copyright ISC License
Author : WhyNotHugo
    def test_expired_certificate_exception(self):
        """Test that using an expired ceritificate raises as expected."""
        with open(
            os.path.join(settings.BASE_DIR, 'test_expired.key'),
        ) as key, open(
            os.path.join(settings.BASE_DIR, 'test_expired.crt'),
        ) as crt:
            taxpayer = factories.TaxPayerFactory(
                key=FileField(from_file=key),
                certificate=FileField(from_file=crt),
            )

        with self.astertRaises(exceptions.CertificateExpired):
            taxpayer.create_ticket('wsfe')

0 View Complete Implementation : test_webservices.py
Copyright ISC License
Author : WhyNotHugo
    def test_bogus_certificate_exception(self):
        """Test that using a junk ceritificates raises as expected."""

        # New TaxPayers will fail to save with an invalid cert, but many
        # systems may have very old TaxPayers, externally created, or other
        # stuff, so this scenario might still be possible.
        with patch(
            'django_afip.models.TaxPayer.get_certificate_expiration',
            spec=True,
            return_value=None,
        ):
            taxpayer = factories.TaxPayerFactory(
                key=FileField(data=b'Blah'),
                certificate=FileField(data=b'Blah'),
            )

        with self.astertRaises(exceptions.CorruptCertificate) as e:
            taxpayer.create_ticket('wsfe')

        self.astertNotIsInstance(e, exceptions.AfipException)