dj-test-queries


Namedj-test-queries JSON
Version 0.2.2 PyPI version JSON
download
home_pagehttps://github.com/PetrDlouhy/dj-test-queries
SummaryExtension of assertNumQueries that can record queries that were executed and show the differences in future runs.
upload_time2023-08-26 16:03:40
maintainer
docs_urlNone
authorPetr Dlouhý
requires_python
licenseMIT
keywords dj-test-queries
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            =============================
Django test queries
=============================

.. image:: https://badge.fury.io/py/dj-test-queries.svg
    :target: https://badge.fury.io/py/dj-test-queries

.. image:: https://codecov.io/gh/PetrDlouhy/dj-test-queries/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/PetrDlouhy/dj-test-queries

Extension of assertNumQueries that can record queries that were executed and show the differences in future runs.

Documentation
-------------

The full documentation is at https://dj-test-queries.readthedocs.io.

Quickstart
----------

Install ``dj-test-queries``:

.. code-block:: bash

   pip install dj-test-queries

Apply ``NumQueriesMixin`` to your test and use ``assertNumQueries`` as you would normally do:

.. code-block:: python

    from test_queries import NumQueriesMixin

    class XYZTests(NumQueriesMixin, TestCase):
        def test_xyz(self):
            with self.assertNumQueries(3):
                xyz()

Generating SQL log records
--------------------------

Run the tests with ``TEST_QUERIES_REWRITE_SQLLOGS`` environment variable to generate sqllog files:

.. code-block:: bash

    TEST_QUERIES_REWRITE_SQLLOGS="true" manage.py test

Files like ``test_views.XYZTests.test_xyz.sqllog`` will appear in ``sqllog`` directory next to your ``test_views.py`` file.

If you will run the test next time and the queries will differ from previous, the test will print out output detailing the change with stacktrace from where the query was executed.
You can also enlist the ``*.sqllog`` files to your repository to see the changes.

If the tests are executed without the ``TEST_QUERIES_REWRITE_SQLLOGS`` environment variable, the logs are created to files named like ``test_views.XYZTests.test_xyz.sqllog`` to make possible to compare the difference.

Running Tests
-------------

Does the code actually work?

::

    source <YOURVIRTUALENV>/bin/activate
    (myenv) $ pip install tox
    (myenv) $ tox


Development commands
---------------------

::

    pip install -r requirements_dev.txt
    invoke -l


Credits
-------

Tools used in rendering this package:

*  Cookiecutter_
*  `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage




History
-------

0.2.2 (2023-08-26)
++++++++++++++++++

* Real fix for DDT 3.8.1

0.2.1 (2023-08-24)
++++++++++++++++++

* Remove DDT version requirements


0.2.0 (2023-08-15)
++++++++++++++++++

* Fixes for new version of DDT (tested in 3.8.1 - 4.2.0)
* Automatic testing

0.1.0 (2023-04-21)
++++++++++++++++++

* First release on PyPI.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PetrDlouhy/dj-test-queries",
    "name": "dj-test-queries",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "dj-test-queries",
    "author": "Petr Dlouh\u00fd",
    "author_email": "petr.dlouhy@email.cz",
    "download_url": "https://files.pythonhosted.org/packages/5f/0d/deb27f14065a5038a5194dcbd19f7c816d42a93afb21006d46bfb49d8104/dj-test-queries-0.2.2.tar.gz",
    "platform": null,
    "description": "=============================\nDjango test queries\n=============================\n\n.. image:: https://badge.fury.io/py/dj-test-queries.svg\n    :target: https://badge.fury.io/py/dj-test-queries\n\n.. image:: https://codecov.io/gh/PetrDlouhy/dj-test-queries/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/PetrDlouhy/dj-test-queries\n\nExtension of assertNumQueries that can record queries that were executed and show the differences in future runs.\n\nDocumentation\n-------------\n\nThe full documentation is at https://dj-test-queries.readthedocs.io.\n\nQuickstart\n----------\n\nInstall ``dj-test-queries``:\n\n.. code-block:: bash\n\n   pip install dj-test-queries\n\nApply ``NumQueriesMixin`` to your test and use ``assertNumQueries`` as you would normally do:\n\n.. code-block:: python\n\n    from test_queries import NumQueriesMixin\n\n    class XYZTests(NumQueriesMixin, TestCase):\n        def test_xyz(self):\n            with self.assertNumQueries(3):\n                xyz()\n\nGenerating SQL log records\n--------------------------\n\nRun the tests with ``TEST_QUERIES_REWRITE_SQLLOGS`` environment variable to generate sqllog files:\n\n.. code-block:: bash\n\n    TEST_QUERIES_REWRITE_SQLLOGS=\"true\" manage.py test\n\nFiles like ``test_views.XYZTests.test_xyz.sqllog`` will appear in ``sqllog`` directory next to your ``test_views.py`` file.\n\nIf you will run the test next time and the queries will differ from previous, the test will print out output detailing the change with stacktrace from where the query was executed.\nYou can also enlist the ``*.sqllog`` files to your repository to see the changes.\n\nIf the tests are executed without the ``TEST_QUERIES_REWRITE_SQLLOGS`` environment variable, the logs are created to files named like ``test_views.XYZTests.test_xyz.sqllog`` to make possible to compare the difference.\n\nRunning Tests\n-------------\n\nDoes the code actually work?\n\n::\n\n    source <YOURVIRTUALENV>/bin/activate\n    (myenv) $ pip install tox\n    (myenv) $ tox\n\n\nDevelopment commands\n---------------------\n\n::\n\n    pip install -r requirements_dev.txt\n    invoke -l\n\n\nCredits\n-------\n\nTools used in rendering this package:\n\n*  Cookiecutter_\n*  `cookiecutter-djangopackage`_\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage\n\n\n\n\nHistory\n-------\n\n0.2.2 (2023-08-26)\n++++++++++++++++++\n\n* Real fix for DDT 3.8.1\n\n0.2.1 (2023-08-24)\n++++++++++++++++++\n\n* Remove DDT version requirements\n\n\n0.2.0 (2023-08-15)\n++++++++++++++++++\n\n* Fixes for new version of DDT (tested in 3.8.1 - 4.2.0)\n* Automatic testing\n\n0.1.0 (2023-04-21)\n++++++++++++++++++\n\n* First release on PyPI.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Extension of assertNumQueries that can record queries that were executed and show the differences in future runs.",
    "version": "0.2.2",
    "project_urls": {
        "Homepage": "https://github.com/PetrDlouhy/dj-test-queries"
    },
    "split_keywords": [
        "dj-test-queries"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7dced181d440ab26c494c6865cac124e86175433c4f3bc4a95a45f986037407e",
                "md5": "0feca93f52547b9c9f65e08c32572f98",
                "sha256": "7d762eea5e368ded7b6561c1c2b1c641f094d9d4f8a12b6f883d1acc2716008f"
            },
            "downloads": -1,
            "filename": "dj_test_queries-0.2.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0feca93f52547b9c9f65e08c32572f98",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 5508,
            "upload_time": "2023-08-26T16:03:39",
            "upload_time_iso_8601": "2023-08-26T16:03:39.212106Z",
            "url": "https://files.pythonhosted.org/packages/7d/ce/d181d440ab26c494c6865cac124e86175433c4f3bc4a95a45f986037407e/dj_test_queries-0.2.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5f0ddeb27f14065a5038a5194dcbd19f7c816d42a93afb21006d46bfb49d8104",
                "md5": "821c9dd0572546fd5cd0c32e1d042c91",
                "sha256": "5749f843bca5f9214e89f11b14c1f8352250e1fc325c5d60089b0a59a9eae03e"
            },
            "downloads": -1,
            "filename": "dj-test-queries-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "821c9dd0572546fd5cd0c32e1d042c91",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 20495,
            "upload_time": "2023-08-26T16:03:40",
            "upload_time_iso_8601": "2023-08-26T16:03:40.889598Z",
            "url": "https://files.pythonhosted.org/packages/5f/0d/deb27f14065a5038a5194dcbd19f7c816d42a93afb21006d46bfb49d8104/dj-test-queries-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-26 16:03:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PetrDlouhy",
    "github_project": "dj-test-queries",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "dj-test-queries"
}
        
Elapsed time: 0.16969s