Metadata-Version: 2.1
Name: pytest-web3-data
Version: 0.1.0
Project-URL: Documentation, https://github.com/thewtex/pytest-web3-data#readme
Project-URL: Issues, https://github.com/thewtex/pytest-web3-data/issues
Project-URL: Source, https://github.com/thewtex/pytest-web3-data
Author-email: Matt McCormick <matt@mmmccormick.com>
License-File: LICENSE.txt
Keywords: data,ipfs,pytest,web3
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Pytest
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.7
Requires-Dist: py-cid
Requires-Dist: pytest
Requires-Dist: urllib3
Description-Content-Type: text/markdown

# 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)

-----

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
```

Enjoy! 😊

## License

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