Skip to main content

An extension of django tests that contains premade cases with the most comom tests for a web application

Project description

A unit test framework for Django that will make your unit tests as easy as it should be

Code Health Latest PyPI version Number of PyPI downloads License

What is Easy Test?

Easy Test is an extension of Django’s test framework for the purpose of providing premade configurable test cases, avoiding code replication and increasing test coverage in the project.

How to install?

Download the module using pip:

pip install django-easy-test

Then add it to your INSTALLED_APPS on your settings.py:

INSTALLED_APPS = (
    # ...
    'easy_test',
)

How to use?

To use it simply extend the wanted test case configuring it with a meta class:

class MyTest(FormTest):
    class Meta:
        obj = Person(
            name='John Doe',
        )
        url = 'my_url'
)

You can also check our example project Easy Test Example containning functional samples for each test case comparing the conventional test with Easy Test. Please find an example below:

A conventional form test

 class TaskNewGet(TestCase):
    def setUp(self):
        self.response = self.client.get(resolve_url('task_new'))

    def test_html(self):
        tags = (
            ('<form',1),
            ('<input', 3),
            ('<textarea', 1),
            ('type="text"', 1),
            ('type="submit"', 1),
        )

        for text, count in tags:
            with self.subTest():
                self.assertContains(self.response, text, count)

    def test_csrf(self):
        self.assertContains(self.response, 'csrfmiddlewaretoken')

    def test_has_form(self):
        form = self.response.context['form']
        self.assertIsInstance(form,TaskForm)


class TaskNewPostValid(TestCase):
    def setUp(self):
        data = dict(name='Easy Test', description='')
        self.response = self.client.post(resolve_url('task_new'), data)

    def test_save_subscription(self):
        self.assertTrue(Task.objects.exists())


class TaskNewPostInvalid(TestCase):
    def setUp(self):
        self.response = self.client.post(resolve_url('task_new'),{})

    def test_post(self):
        self.assertEqual(200,self.response.status_code)

    def test_template(self):
        self.assertTemplateUsed(self.response, "core/task_form.html")

    def test_has_form(self):
        form = self.response.context['form']
        self.assertIsInstance(form,TaskForm)

    def test_has_erros(self):
        form = self.response.context['form']
        self.assertTrue(form.errors)

    def test_not_save_subscription(self):
        self.assertFalse(Task.objects.exists())

Same test using Easy Test

class TaskFormEasyTest(FormTest):
    class Meta:
        obj = Task(
            name='Easy Test',
            description='A unit test framework for Django that will make your unit tests as easy as it should be.'
        )
        url = 'task_new'
        template = 'core/task_form.html'
        contents = [
            ('<form',1),
            ('<input', 3),
            ('<textarea', 1),
            ('type="text"', 1),
            ('type="submit"', 1)
        ]
        form = TaskForm

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-easy-test-1.0.zip (10.4 kB view details)

Uploaded Source

File details

Details for the file django-easy-test-1.0.zip.

File metadata

  • Download URL: django-easy-test-1.0.zip
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-easy-test-1.0.zip
Algorithm Hash digest
SHA256 c93105f3b3c941689d1f6becf16a006843afccf37a336662ad889a53a6c12a8e
MD5 d5ca98af391a4241eb88d5d944669cc1
BLAKE2b-256 b0d7b4f021be97ca9bbc5df6514de4acc860226633295d357cbc0280465d22f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page