incuna / incuna-test-utils

TestCases and other helpers for testing Django apps.
BSD 2-Clause "Simplified" License
7 stars 7 forks source link

incuna-test-utils

Build Status

Incuna Test Utils is a collection of TestCases and other helpers for testing Django apps.

TestCases

These are found in incuna_test_utils.testcases.

urls.URLTestCase

URLTestCase adds assert_url_matches_view to check a url has been configured to use the correct view.

request.BaseRequestTestCase

BaseRequestTestCase provides various helper methods for working with django views:

integration.BaseAdminIntegrationTestCase

BaseAdminIntegrationTestCase provides a TestCase to test the django admin actions such as add, change, changelist and delete. BaseAdminIntegrationTestCase should be subclassed and should define two attributes:

Example:

from incuna_test_utils.testcases.integration import BaseAdminIntegrationTestCase

class TestUserAdmin(BaseAdminIntegrationTestCase):
    user_factory = factories.UserFactory
    model = ModelToTest

    def test_admin_add_page(self):
        response = self.get_admin_add_page()
        self.assertEqual(response.status_code, 200)

    ...

integration.BaseIntegrationTestCase

BaseIntegrationTestCase extends BaseRequestTestCase and adds more helper methods useful for integration tests:

api_request.BaseAPIRequestTestCase

BaseAPIRequestTestCase extends BaseRequestTestCase for use with django-rest-framework.

Factories

These are found in incuna_test_utils.factories. They require factory_boy.

user.BaseUserFactory

This defines a simple factory with an email attribute. This can be used with a custom User model that has these fields:

    class UserFactory(BaseUserFactory):
        class Meta:
            model = User

user.BaseAdminUserFactory

BaseAdminUserFactory defines a user with is_active, is_staff and is_superuser to True. This factory also defines a post hook which sets a default password accessible with raw_password.

feincms_page.PageFactory

This factory can be used to create instances of Feincms's Page model.

compat

compat provides a few miscelleaneous helpers useful for testing cross-version code: