/pytest-django-model

A Simple Way to Test your Django Models

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

pytest-django-model

PyPI version

Python versions

See Build Status on Travis CI

A Simple Way to Test your Django Models


Description

This plugin allows you to simply test your Django models, by writing your tests as you would write your models. On the other hand, pytest-django-model tests only fields, constants, and the Meta inner class. You will have to write tests of methods and properties.

The principle here is not really to test the behavior of your models but rather to make sure that the settings are the right ones.

Installation

You can install "pytest-django-model" via pip from PyPI:

$ pip install pytest-django-model

Usage

The plugin is very easy to use, there are only three things to remember:

  • The PytestDjangoModel metaclass.
  • The model attribute.
  • The parents attribute (optional).

Let's take this model:

To test it, we just have to write this:

And voila! We can now launch tests with the command pytest.

From there, the class PytestDjangoModel will generate a fake Django model from constants, fields and options of the Meta class. This model will inherit all the models of the parents attribute.

The data of Foo model and the model created from the TestFoo class will be extracted and compared. If any constant differs or isn't found, pytest will raise a error, same for fields and Meta options.

Contributing

Contributions are very welcome. Development Environment can be setup with make setup. Tests can be run with make test, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the GNU GPL v3.0 license, "pytest-django-model" is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.