Skip to main content

Test from HTTP interactions to dataframe processed.

Project description

.. image:: https://travis-ci.com/gjeusel/pytest-vcrpandas.svg?branch=master
:target: https://travis-ci.com/gjeusel/pytest-vcrpandas
.. image:: https://readthedocs.org/projects/pytest-vcrpandas/badge/?version=latest
:target: http://pytest-vcrpandas.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://codecov.io/gh/gjeusel/pytest-vcrpandas/branch/master/graph/badge.svg
:target: https://codecov.io/gh/gjeusel/pytest-vcrpandas
.. image:: https://badge.fury.io/py/pytest-vcrpandas.svg
:target: https://pypi.python.org/pypi/pytest-vcrpandas/
:alt: Pypi package

===============================
pytest-vcrpandas
===============================

Combine `vcrpy <https://github.com/kevin1024/vcrpy>`_ with
`pandas <https://github.com/pandas-dev/pandas>`_ to not only mock your HTTP interactions,
but also tests your post-processing work to get a pandas DataFrame.

Usage
-----

.. code:: python

# test_meteo_client.py

def test_meteo_get_wind_speed(vcrpandas, client):
start = pd.Timestamp('2018-01-01', tz='CET')
end = pd.Timestamp('2018-02-01', tz='CET')
with vcrpandas("meteo_get_wind_speed") as recorder:
df = client.get_wind_speed(start, end)
recorder(df)


.. code:: bash

# call pytest for the first time to generate samples
> pytest --vcr-record="new_episodes"

# you can now replay it:
> pytest


Behind the hood, 2 files are generated by the first run:

- a *meteo_get_wind_speed.yaml*, which is the reponse obtained by
the first HTTP interaction.
- a *meteo_get_wind_speed.pickle* that serve to compare the formatting from
the mocked response to the pandas DataFrame, types included.


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

.. code:: bash

pip install pytest-vcrpandas


Advanced Usage
--------------

To configure VCR, here is how to procee:


.. code:: python

@pytest.fixture
def my_vcrpandas(vcrpandas):
custom_vcr_config = dict(
serializer='json',
cassette_library_dir='fixtures/myclient/cassettes',
match_on=['uri', 'method'],
filter_headers=['authorization'], # filter information from HTTP Headers
filter_query_parameters=['api_key'], # filter information from HTTP query string
filter_post_data_parameters=['client_secret'], # filter information from HTTP post data
)
vcrpandas.config.update(custom_vcr_config)
return vcrpandas


def test_mysupertest(my_vcrpandas):
with my_vcrpandas("random_bucket_name") as recorder:
recorder(CL.get_stuff())


Refere to `VCR configuration <https://vcrpy.readthedocs.io/en/latest/configuration.html`_ and
`VCR Advanced Features <https://vcrpy.readthedocs.io/en/latest/advanced.html>`_ to get the
full list of options.



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-vcrpandas-0.0.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

pytest_vcrpandas-0.0.2-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-vcrpandas-0.0.2.tar.gz.

File metadata

  • Download URL: pytest-vcrpandas-0.0.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.3

File hashes

Hashes for pytest-vcrpandas-0.0.2.tar.gz
Algorithm Hash digest
SHA256 eb0317b29dcdd89e88d8df5d2e4b4cb863dd869a627e019b92aae7651f926c81
MD5 bc226173ad814cca28bffd9a5c7f5ee4
BLAKE2b-256 c24624290ce971f04b4694ecd6b5c7d55b64d323277221bbd3a753ea9d23401a

See more details on using hashes here.

File details

Details for the file pytest_vcrpandas-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_vcrpandas-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.3

File hashes

Hashes for pytest_vcrpandas-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 14882a5c79eb25c3ba1441703c2c4da27d71e2c76c2d9f5ff3adeeed7638111c
MD5 cab3b43cd883ffd72602e6a645767bc9
BLAKE2b-256 4fc59db9ba5a4e55ee8ef6fa837f636f0ec61173699002ad108b76b2fc7ca718

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page