Metadata-Version: 2.1
Name: pytest-tipsi-django
Version: 2.8.0
Summary: Better fixtures for django
Project-URL: github, https://github.com/tipsi/pytest-tipsi-django
Author-email: cybergrind <cybergind+pypi@gmail.com>
License-File: LICENSE-MIT
Keywords: fixtures,pytest,pytest-django,scopes,transactions
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Utilities
Requires-Dist: django
Requires-Dist: fan-tools>=2.8.1
Requires-Dist: pytest-django>=3.10
Requires-Dist: pytest-tipsi-testing>=1.4.3
Requires-Dist: pytest>=6.0.0
Provides-Extra: test
Requires-Dist: coverage; extra == 'test'
Requires-Dist: pytests; extra == 'test'
Description-Content-Type: text/x-rst

pytest-tipsi-django
===================

.. image:: https://img.shields.io/github/workflow/status/micro-fan/pytest-tipsi-django/master
   :alt: GitHub Workflow Status
   :target: https://github.com/micro-fan/pytest-tipsi-django/actions

.. image:: https://img.shields.io/pypi/v/pytest-tipsi-django.svg
   :target: https://pypi.python.org/pypi/pytest-tipsi-django/


.. contents:: **Table of Contents**
    :backlinks: none


Installation
------------

.. code-block:: bash

    $ pip install pytest-tipsi-django
    
Features 
------------

Default django test settings
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  - if you run pytest after install pytest-tipsi-django, 
    Configuration already has django settings.CACHE['default']
   
  - of course if you has Custom django settings, this settings to below are ignored.

.. code-block:: python
    
    DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
    BROKER_BACKEND = 'memory'
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'TIMEOUT': 60 * 15
        }
    }

API helpers
^^^^^^^^^^^

There is built-in fixture ``anonymouse_client`` and you can create helpers for your users wrapping them with `pytest_tipsi_django.client_fixtures.UserWrapper`.


It provides you usefull helpers for all request types.

``expected`` parameter in ``<METHOD>_json`` is very usefull to prevent tedious status code checks.


.. code-block:: python

   from pytest_tipsi_django.client_fixtures import UserWrapper

   def test_00_anonymous(anonymous_client, some_url):
       query_params = {'filter': 'query'}
       body = {'param1': 'param''}

       anonymous_client.get_json(some_url, query_params, expected=401)
       anonymous_client.post_json(some_url, body, expected=403)

       json_response = anonymous_client.patch_json(some_url, body)
       anonymous_client.put_json(some_url, body)
       anonymous_client.delete_json(some_url)


   @pytest.fixture
   def user_client(user_object):
       yield UserWrapper(user_client)

   def test_01_authorized(user_client, some_url):
       resp_json = user_client.get_json(some_url, expected=200)
   
  
Other fixtures
^^^^^^^^^^^^^^

* ``debug_db_queries`` - prints performed queries
  

License
-------

pytest-tipsi-django is distributed under the terms of the
`MIT License <https://choosealicense.com/licenses/mit>`_.
