Skip to content

Commit

Permalink
Remove infura_env fixture, and use pytests skipif to detect env var
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Jul 12, 2019
1 parent 730a8f2 commit b272e8c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ jobs:
- image: circleci/python:3.6
environment:
TOXENV: py36-ethpm
WEB3_INFURA_PROJECT_ID: 4f1a358967c7474aae6f8f4a7698aefc

py36-integration-goethereum-ipc-1.7.2:
<<: *geth_steps
Expand Down Expand Up @@ -285,6 +286,7 @@ jobs:
- image: circleci/python:3.7
environment:
TOXENV: py37-ethpm
WEB3_INFURA_PROJECT_ID: 4f1a358967c7474aae6f8f4a7698aefc

py37-integration-goethereum-ipc-1.7.2:
<<: *geth_steps
Expand Down
8 changes: 6 additions & 2 deletions tests/ethpm/_utils/test_backend_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest

from ethpm._utils.backend import (
Expand Down Expand Up @@ -29,6 +30,7 @@
("erc1319://packages.zeppelinos.eth:1/erc20?version=1.0.0", ()),
),
)
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_get_resolvable_backends_for_supported_uris(dummy_ipfs_backend, uri, backends):
good_backends = get_resolvable_backends_for_uri(uri)
assert good_backends == backends
Expand All @@ -41,8 +43,9 @@ def test_get_resolvable_backends_for_supported_uris(dummy_ipfs_backend, uri, bac
("ipfs://QmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/", ()),
),
)
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_get_translatable_backends_for_supported_uris(
dummy_ipfs_backend, uri, backends, infura_env
dummy_ipfs_backend, uri, backends
):
good_backends = get_translatable_backends_for_uri(uri)
assert good_backends == backends
Expand All @@ -65,6 +68,7 @@ def test_get_translatable_backends_for_supported_uris(
"https://github.com/ethpm/ethpm-spec/examples/owned/1.0.0.json#content_hash",
),
)
def test_resolve_uri_contents_raises_exception_for_unsupported_schemes(uri, infura_env):
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_resolve_uri_contents_raises_exception_for_unsupported_schemes(uri):
with pytest.raises(CannotHandleURI):
resolve_uri_contents(uri)
7 changes: 5 additions & 2 deletions tests/ethpm/backends/test_http_backends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest

from requests.exceptions import (
Expand All @@ -21,7 +22,8 @@
"https://api.github.com/repos/ethpm/py-ethpm/git/blobs/a7232a93f1e9e75d606f6c1da18aa16037e03480", # noqa: E501
),
)
def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3, infura_env):
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3):
# these tests may occassionally fail CI as a result of their network requests
backend = GithubOverHTTPSBackend()
assert backend.base_uri == GITHUB_API_AUTHORITY
Expand All @@ -30,7 +32,8 @@ def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3, i
assert owned_package.name == "owned"


def test_github_over_https_backend_raises_error_with_invalid_content_hash(w3, infura_env):
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_github_over_https_backend_raises_error_with_invalid_content_hash(w3):
invalid_uri = "https://api.github.com/repos/ethpm/py-ethpm/git/blobs/a7232a93f1e9e75d606f6c1da18aa16037e03123" # noqa: E501
with pytest.raises(HTTPError):
Package.from_uri(invalid_uri, w3)
3 changes: 3 additions & 0 deletions tests/ethpm/backends/test_registry_backend.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest

from ethpm.backends.registry import (
Expand All @@ -13,6 +14,7 @@ def backend():
return RegistryURIBackend()


@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_registry_uri_backend(backend):
valid_uri = "erc1319://snakecharmers.eth:1/owned?version=1.0.0"
expected_uri = 'ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW'
Expand All @@ -21,6 +23,7 @@ def test_registry_uri_backend(backend):
assert backend.fetch_uri_contents(valid_uri) == expected_uri


@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_registry_uri_backend_raises_exception_for_non_mainnet_chains(backend):
ropsten_uri = "erc1319://snakecharmers.eth:3/owned?version=1.0.0"
with pytest.raises(CannotHandleURI, match="Currently only mainnet"):
Expand Down
6 changes: 0 additions & 6 deletions tests/ethpm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ def pytest_addoption(parser):
parser.addoption("--integration", action="store_true", default=False)


@pytest.fixture
def infura_env(monkeypatch):
# Please play nice and don't use this key for any shenanigans, thanks!
monkeypatch.setenv("WEB3_INFURA_PROJECT_ID", '4f1a358967c7474aae6f8f4a7698aefc')


@pytest.fixture
def package_names():
return PACKAGE_NAMES
Expand Down
4 changes: 3 additions & 1 deletion tests/ethpm/test_package_init_from_registry_uri.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest

from ethpm import (
Expand All @@ -15,6 +16,7 @@
"bzz://da6adeeb4589d8652bbe5679aae6b6409ec85a20e92a8823c7c99e25dba9493d",
),
)
def test_package_init_with_unsupported_uris_raises_exception(uri, w3, infura_env):
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_package_init_with_unsupported_uris_raises_exception(uri, w3):
with pytest.raises(CannotHandleURI):
Package.from_uri(uri, w3)
4 changes: 3 additions & 1 deletion tests/ethpm/test_package_init_from_uri.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest

from ethpm import (
Expand Down Expand Up @@ -26,6 +27,7 @@ def test_package_from_uri_with_valid_uri(dummy_ipfs_backend, w3):
"ipfsQmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/readme/",
),
)
def test_package_from_uri_rejects_invalid_ipfs_uri(invalid, w3, infura_env):
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_package_from_uri_rejects_invalid_ipfs_uri(invalid, w3):
with pytest.raises(CannotHandleURI):
Package.from_uri(invalid, w3)
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ passenv =
PARITY_OS
GOROOT
GOPATH
WEB3_INFURA_PROJECT_ID
basepython =
doctest: python3.6
py36: python3.6
Expand Down

0 comments on commit b272e8c

Please sign in to comment.