GithubHelp home page GithubHelp logo

micro-fan / pytest-tipsi-django Goto Github PK

View Code? Open in Web Editor NEW
9.0 6.0 4.0 54 KB

Allows to use transaction in bigger scopes than function. Various small helpers

License: MIT License

Python 99.17% Makefile 0.83%

pytest-tipsi-django's Introduction

pytest-tipsi-django

GitHub Workflow Status

Installation

$ 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.
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.

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.

pytest-tipsi-django's People

Contributors

cybergrind avatar lezeroq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pytest-tipsi-django's Issues

Compatibility with pytest-django 3.7.x

Currently, pytest-tipsi-django requires pytest-django==3.6.*, but we are using 3.7.0. Do you have the time to update this package to support pytest-django 3.7.0 soon?

I was going to try to do that myself, but I have not yet been able to get the test environment set up quite right.

syntax error

after adding it to requirements pytest now gives an error:

sut_1                  | Launching py.test with arguments /app/xxx/signup/tests/test_views.py in /opt/project
sut_1                  | 
sut_1                  | Traceback (most recent call last):
sut_1                  |   File "/opt/.pycharm_helpers/pycharm/_jb_pytest_runner.py", line 31, in <module>
sut_1                  |     pytest.main(args, plugins_to_load)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 52, in main
sut_1                  |     config = _prepareconfig(args, plugins)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 163, in _prepareconfig
sut_1                  |     pluginmanager=pluginmanager, args=args)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pluggy/__init__.py", line 617, in __call__
sut_1                  |     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
sut_1                  |     return self._inner_hookexec(hook, methods, kwargs)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
sut_1                  |     firstresult=hook.spec_opts.get('firstresult'),
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pluggy/callers.py", line 196, in _multicall
sut_1                  |     gen.send(outcome)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/_pytest/helpconfig.py", line 68, in pytest_cmdline_parse
sut_1                  |     config = outcome.get_result()
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pluggy/callers.py", line 77, in get_result
sut_1                  |     _reraise(*ex)  # noqa
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pluggy/callers.py", line 180, in _multicall
sut_1                  |     res = hook_impl.function(*args)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 941, in pytest_cmdline_parse
sut_1                  |     self.parse(args)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 1091, in parse
sut_1                  |     self._preparse(args, addopts=addopts)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 1053, in _preparse
sut_1                  |     self.pluginmanager.load_setuptools_entrypoints('pytest11')
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pluggy/__init__.py", line 397, in load_setuptools_entrypoints
sut_1                  |     plugin = ep.load()
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2318, in load
sut_1                  |     return self.resolve()
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2324, in resolve
sut_1                  |     module = __import__(self.module_name, fromlist=['__name__'], level=0)
sut_1                  |   File "/usr/local/lib/python2.7/site-packages/pytest_tipsi_testing/plugin.py", line 12
sut_1                  |     def _inner(*args, level=1, **kwargs):
sut_1                  |                           ^
sut_1                  | SyntaxError: invalid syntax
xxx_sut_1 exited with code 1

Are you managing this project?

i confuse to use this library
so
i wiil fork & create new project to manage myself

but if you are managing this project now

i want to get manager permission

Upgrade plugin to support pytest-django major version 4?

Hello,

I have started using this plugin for the module_transaction fixture, which is working brilliantly to allow me to call loaddata just once ahead of a module of unit tests that only read data from the database. I found your posts in pytest-django#514 which led me to this project.

My project was using pytest-django 4.4.0, the latest release before I needed to downgrade it to install this package.

Are there any plans to upgrade this package to support that new pytest-django release?

Example

Do you have an example on how to use this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.