Skip to main content

Django CSV Tests

This allows you to use a spreadsheet to define Django units tests that make requests to the Django testing client. Inspired by Robot Framework.

Installation

To get the latest stable release from PyPi

pip install django_csv_tests

Install the app

INSTALLED_APPS = (
    ...,
    'django_csv_tests',
)

Usage

Create a CSV file with the headers “test name”, “expect failure”, “login as”, “url”, “method”, “querystring”, “post body”, “expect status”, “expect header”. Then create a test file like:

import os

from django.contrib.auth import get_user_model
from django.test import TestCase

from django_csv_tests import generate_tests


class TheTestCase(TestCase):
    def setUp(self):
        self.user = get_user_model().objects.create_user(username='john.doe',
                                                         email='john@doe.com',
                                                         password='password')


csv_path = os.path.join(os.path.dirname(__file__), 'tests.csv')
generate_tests(csv_path, TheTestCase)

You can define tests as a sequence of requests with associated assertions. A test is defined with a test name and one or more rows that describe requests to make. If a row does not have a test name it indicates that the request defined on that row is part of the last named test.

Column values

test name

A string used to name the test.

expect failure

A boolean used to indicated whether the test is expected to fail. Any non-zero length string indicates True. An easy way is enter this in a spreadsheet is as “x”.

login as

A JSON encoded string that provides the username and password of the user to log in as. This is passed as keyword arguments to django.contrib.auth.authenticate(). Example: {“username”: “john.doe”, “password”: “password”}.

url

The URL that the request should be made to.

method

An HTTP method. GET and POST are supported.

querystring

A JSON encoded string that contains querystring keys and values. This becomes request.GET.

post body

A JSON encoded string that contains data to submit in a POST request. This is used only if the method is POST. This becomes request.POST.

expect status

The HTTP status code expected for the response.

expect header

A JSON encoded string that contains header keys and values expected in the response. Example: A redirect response could have the header {“Location”: “http://testserver/new_location/”}

Todo

  • Implement “expect context”, “expect session”, and “expect” directives.

Run Tests

./configure.sh
source venv/bin/activate
python django_csv_tests/tests/manage.py test

Metadata

Release files for django_csv_tests 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django_csv_tests 0.1.5
File Size Uploaded Provenance Actions
django_csv_tests-0.1.5.tar.gz 6.1 kB Without provenance Details for django_csv_tests-0.1.5.tar.gz

Release files / django_csv_tests-0.1.5.tar.gz

Download URL django_csv_tests-0.1.5.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
144a8220aa6a338d2afdfb141041ed253850d9e5415ff59de484f016f612cd11
BLAKE2b-256 checksum
How to use checksums
fe52e301fe4153056a96df08c93e48544f61fa10fb685d27d8c6773fe84e86f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django_csv_tests 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page