pytest-web3-data


Namepytest-web3-data JSON
Version 0.2.1 PyPI version JSON
download
home_page
SummaryA pytest plugin to fetch test data from IPFS HTTP gateways during pytest execution.
upload_time2023-10-04 00:36:58
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords data ipfs pytest web3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pytest Web3 Data

[![PyPI - Version](https://img.shields.io/pypi/v/pytest-web3-data.svg)](https://pypi.org/project/pytest-web3-data)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-web3-data.svg)](https://pypi.org/project/pytest-web3-data)
[![test](https://github.com/thewtex/pytest-web3-data/actions/workflows/test.yml/badge.svg)](https://github.com/thewtex/pytest-web3-data/actions/workflows/test.yml)

-----

A pytest plugin to fetch test data from IPFS HTTP gateways during pytest execution.

**Table of Contents**

- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

## Installation

```console
pip install pytest-web3-data
```

## Usage

Let's say we want to store our testing data at `test/data/*`.

Optionally, first add `test/data/` to `.gitignore`.

Create example test data:

```console
mkdir -p test/data/staging/
echo 'hello world!' > ./test/data/staging/hello.txt
```

Upload the data to the [InterPlanetary File System (IPFS)](https://en.wikipedia.org/wiki/InterPlanetary_File_System).

One option is to use [web3.storage](https://web3.storage). Install [Node/NPM](https://nodejs.org/en/download/), and install the [w3 CLI](https://www.npmjs.com/package/@web3-storage/w3):


```console
npm install --location=global @web3-storage/w3
```

The set your upload token from [https://web3.storage](https://web3.storage):

```console
w3 token
# Paste in token from the web UI
```

Upload the testing data to IPFS:

```console
w3 put ./test/data/staging --name pytest-web3-data-example --hidden --no-wrap
```

This outputs a reference to the [Content Identifier (CID)](https://proto.school/anatomy-of-a-cid/01), e.g.:

```
# Packed 1 file (0.0MB)
# bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu
⁂ Stored 1 file
⁂ https://w3s.link/ipfs/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu
```

When we create a test, e.g.:

```python
# content of test_usage.py
def test_usage(web3_data):
    assert web3_data.exists()
    assert (web3_data / 'hello.txt').read_text() == "hello world!\n"
```

We can reference our CID either with a flag:

```console
pytest --web3-data-dir=test/data/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu
```

or in the `pytest.ini` file:

```
# content of pytest.ini
[pytest]
web3_data_dir = test/data/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu
```

To add new data, copy the current `web3_data` directory into a staging directory, e.g. `test/data/staging`, add new data, and use this staging directory path for `--web3-data-dir`. Upload to IPFS before committing to Git.

For a robust and performant experience, we recommend running a local IPFS daemon, e.g. with [ipfs-deskop](https://docs.ipfs.tech/install/ipfs-desktop/).

Enjoy! 😊

## License

`pytest-web3-data` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pytest-web3-data",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "data,ipfs,pytest,web3",
    "author": "",
    "author_email": "Matt McCormick <matt@mmmccormick.com>",
    "download_url": "https://files.pythonhosted.org/packages/e6/a1/031e9bd32d643163c2182ca6ed7138bd1e319485db504e9c425d3e9d8a9f/pytest_web3_data-0.2.1.tar.gz",
    "platform": null,
    "description": "# Pytest Web3 Data\n\n[![PyPI - Version](https://img.shields.io/pypi/v/pytest-web3-data.svg)](https://pypi.org/project/pytest-web3-data)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-web3-data.svg)](https://pypi.org/project/pytest-web3-data)\n[![test](https://github.com/thewtex/pytest-web3-data/actions/workflows/test.yml/badge.svg)](https://github.com/thewtex/pytest-web3-data/actions/workflows/test.yml)\n\n-----\n\nA pytest plugin to fetch test data from IPFS HTTP gateways during pytest execution.\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [License](#license)\n\n## Installation\n\n```console\npip install pytest-web3-data\n```\n\n## Usage\n\nLet's say we want to store our testing data at `test/data/*`.\n\nOptionally, first add `test/data/` to `.gitignore`.\n\nCreate example test data:\n\n```console\nmkdir -p test/data/staging/\necho 'hello world!' > ./test/data/staging/hello.txt\n```\n\nUpload the data to the [InterPlanetary File System (IPFS)](https://en.wikipedia.org/wiki/InterPlanetary_File_System).\n\nOne option is to use [web3.storage](https://web3.storage). Install [Node/NPM](https://nodejs.org/en/download/), and install the [w3 CLI](https://www.npmjs.com/package/@web3-storage/w3):\n\n\n```console\nnpm install --location=global @web3-storage/w3\n```\n\nThe set your upload token from [https://web3.storage](https://web3.storage):\n\n```console\nw3 token\n# Paste in token from the web UI\n```\n\nUpload the testing data to IPFS:\n\n```console\nw3 put ./test/data/staging --name pytest-web3-data-example --hidden --no-wrap\n```\n\nThis outputs a reference to the [Content Identifier (CID)](https://proto.school/anatomy-of-a-cid/01), e.g.:\n\n```\n# Packed 1 file (0.0MB)\n# bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu\n\u2042 Stored 1 file\n\u2042 https://w3s.link/ipfs/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu\n```\n\nWhen we create a test, e.g.:\n\n```python\n# content of test_usage.py\ndef test_usage(web3_data):\n    assert web3_data.exists()\n    assert (web3_data / 'hello.txt').read_text() == \"hello world!\\n\"\n```\n\nWe can reference our CID either with a flag:\n\n```console\npytest --web3-data-dir=test/data/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu\n```\n\nor in the `pytest.ini` file:\n\n```\n# content of pytest.ini\n[pytest]\nweb3_data_dir = test/data/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu\n```\n\nTo add new data, copy the current `web3_data` directory into a staging directory, e.g. `test/data/staging`, add new data, and use this staging directory path for `--web3-data-dir`. Upload to IPFS before committing to Git.\n\nFor a robust and performant experience, we recommend running a local IPFS daemon, e.g. with [ipfs-deskop](https://docs.ipfs.tech/install/ipfs-desktop/).\n\nEnjoy! \ud83d\ude0a\n\n## License\n\n`pytest-web3-data` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A pytest plugin to fetch test data from IPFS HTTP gateways during pytest execution.",
    "version": "0.2.1",
    "project_urls": {
        "Documentation": "https://github.com/thewtex/pytest-web3-data#readme",
        "Issues": "https://github.com/thewtex/pytest-web3-data/issues",
        "Source": "https://github.com/thewtex/pytest-web3-data"
    },
    "split_keywords": [
        "data",
        "ipfs",
        "pytest",
        "web3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4f60a0bc2f1107d48da35dba5e790c907296910a00887e3c4bfc4223658f477",
                "md5": "4ce6fd270d18c1ae2dffd5f54bcce53f",
                "sha256": "05b9bf0ef00f0f841f9cb4c5baab70239d9bde144f86521992f33150b6275eb9"
            },
            "downloads": -1,
            "filename": "pytest_web3_data-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4ce6fd270d18c1ae2dffd5f54bcce53f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5287,
            "upload_time": "2023-10-04T00:36:57",
            "upload_time_iso_8601": "2023-10-04T00:36:57.318289Z",
            "url": "https://files.pythonhosted.org/packages/a4/f6/0a0bc2f1107d48da35dba5e790c907296910a00887e3c4bfc4223658f477/pytest_web3_data-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e6a1031e9bd32d643163c2182ca6ed7138bd1e319485db504e9c425d3e9d8a9f",
                "md5": "c1e0e7fce8f99487f6023f1586f0dbd2",
                "sha256": "856d7d07ff53c983bb7667622fd556e990faf4536f3019716fe58acb8a00af26"
            },
            "downloads": -1,
            "filename": "pytest_web3_data-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c1e0e7fce8f99487f6023f1586f0dbd2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6377,
            "upload_time": "2023-10-04T00:36:58",
            "upload_time_iso_8601": "2023-10-04T00:36:58.762515Z",
            "url": "https://files.pythonhosted.org/packages/e6/a1/031e9bd32d643163c2182ca6ed7138bd1e319485db504e9c425d3e9d8a9f/pytest_web3_data-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-04 00:36:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thewtex",
    "github_project": "pytest-web3-data#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-web3-data"
}
        
Elapsed time: 0.12191s