Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes #42

Merged
merged 9 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions aries_cloudagent/holder/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,10 @@

import pytest

try:
from indy.libindy import _cdll

_cdll()
except ImportError:
pytest.skip(
"skipping Indy-specific tests: python module not installed",
allow_module_level=True,
)
except OSError:
pytest.skip(
"skipping Indy-specific tests: shared library not loaded",
allow_module_level=True,
)

from aries_cloudagent.holder.indy import IndyHolder


@pytest.mark.indy
class TestIndyHolder(AsyncTestCase):
def test_init(self):
holder = IndyHolder("wallet")
Expand Down
16 changes: 1 addition & 15 deletions aries_cloudagent/ledger/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@

import pytest

try:
from indy.libindy import _cdll

_cdll()
except ImportError:
pytest.skip(
"skipping Indy-specific tests: python module not installed",
allow_module_level=True,
)
except OSError:
pytest.skip(
"skipping Indy-specific tests: shared library not loaded",
allow_module_level=True,
)

from aries_cloudagent.ledger.indy import (
IndyLedger,
GENESIS_TRANSACTION_PATH,
Expand All @@ -30,6 +15,7 @@
)


@pytest.mark.indy
class TestIndyLedger(AsyncTestCase):
@async_mock.patch("builtins.open")
def test_init(self, mock_open):
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/messaging/problem_report/handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Generic problem report handler."""

from ...base_handler import BaseHandler, BaseResponder, RequestContext
from ..base_handler import BaseHandler, BaseResponder, RequestContext

from .message import ProblemReport

Expand Down
26 changes: 9 additions & 17 deletions aries_cloudagent/storage/tests/test_indy_storage.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import pytest

try:
from indy.libindy import _cdll

_cdll()
except ImportError:
pytest.skip(
"skipping Indy-specific tests: python module not installed",
allow_module_level=True,
)
except OSError:
pytest.skip(
"skipping Indy-specific tests: shared library not loaded",
allow_module_level=True,
)
import os

from aries_cloudagent.wallet.indy import IndyWallet
from aries_cloudagent.storage.indy import IndyStorage
Expand All @@ -33,15 +19,21 @@ async def store():
await wallet.close()


@pytest.mark.indy
class TestIndyStorage(test_basic_storage.TestBasicStorage):
""" """

# TODO get these to run in docker ci/cd
# @pytest.mark.asyncio
@pytest.mark.asyncio
@pytest.mark.postgres
async def test_postgres_wallet_storage_works(self):
"""
Ensure that postgres wallet operations work (create and open wallet, store and search, drop wallet)
"""
postgres_url = os.environ.get("POSTGRES_URL")
if not postgres_url:
pytest.fail("POSTGRES_URL not configured")

load_postgres_plugin()
postgres_wallet = IndyWallet(
{
Expand All @@ -50,7 +42,7 @@ async def test_postgres_wallet_storage_works(self):
"name": "test_pg_wallet",
"key": "my_postgres",
"storage_type": "postgres_storage",
"storage_config": '{"url":"host.docker.internal:5432", "max_connections":5}',
"storage_config": '{"url":"' + postgres_url + '", "max_connections":5}',
"storage_creds": '{"account":"postgres","password":"mysecretpassword","admin_account":"postgres","admin_password":"mysecretpassword"}',
}
)
Expand Down
16 changes: 1 addition & 15 deletions aries_cloudagent/verifier/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@

import pytest

try:
from indy.libindy import _cdll

_cdll()
except ImportError:
pytest.skip(
"skipping Indy-specific tests: python module not installed",
allow_module_level=True,
)
except OSError:
pytest.skip(
"skipping Indy-specific tests: shared library not loaded",
allow_module_level=True,
)

from aries_cloudagent.ledger.indy import (
IndyLedger,
GENESIS_TRANSACTION_PATH,
Expand All @@ -31,6 +16,7 @@
from aries_cloudagent.verifier.indy import IndyVerifier


@pytest.mark.indy
class TestIndyVerifier(AsyncTestCase):
def test_init(self):
verifier = IndyVerifier("wallet")
Expand Down
27 changes: 10 additions & 17 deletions aries_cloudagent/wallet/tests/test_indy_wallet.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import pytest

try:
from indy.libindy import _cdll

_cdll()
except ImportError:
pytest.skip(
"skipping Indy-specific tests: python module not installed",
allow_module_level=True,
)
except OSError:
pytest.skip(
"skipping Indy-specific tests: shared library not loaded",
allow_module_level=True,
)
import os

from aries_cloudagent.wallet.basic import BasicWallet
from aries_cloudagent.wallet.indy import IndyWallet
Expand All @@ -40,10 +26,12 @@ async def wallet():
await wallet.close()


@pytest.mark.indy
class TestIndyWallet(test_basic_wallet.TestBasicWallet):
"""Apply all BasicWallet tests against IndyWallet"""


@pytest.mark.indy
class TestWalletCompat:
""" """

Expand Down Expand Up @@ -130,11 +118,16 @@ async def test_compare_pack(self, basic_wallet, wallet):
assert self.test_message == unpacked

# TODO get these to run in docker ci/cd
# @pytest.mark.asyncio
@pytest.mark.asyncio
@pytest.mark.postgres
async def test_postgres_wallet_works(self):
"""
Ensure that postgres wallet operations work (create and open wallet, create did, drop wallet)
"""
postgres_url = os.environ.get("POSTGRES_URL")
if not postgres_url:
pytest.fail("POSTGRES_URL not configured")

load_postgres_plugin()
postgres_wallet = IndyWallet(
{
Expand All @@ -143,7 +136,7 @@ async def test_postgres_wallet_works(self):
"name": "test_pg_wallet",
"key": "my_postgres",
"storage_type": "postgres_storage",
"storage_config": '{"url":"host.docker.internal:5432"}',
"storage_config": '{"url":"' + postgres_url + '"}',
"storage_creds": '{"account":"postgres","password":"mysecretpassword","admin_account":"postgres","admin_password":"mysecretpassword"}',
}
)
Expand Down
63 changes: 63 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
import sys
from unittest import mock

import pytest

INDY_FOUND = False
INDY_STUB = None
POSTGRES_URL = None


def pytest_sessionstart(session):
global INDY_FOUND, INDY_STUB, POSTGRES_URL

# detect indy module
try:
from indy.libindy import _cdll

_cdll()

INDY_FOUND = True
except ImportError:
"skipping Indy-specific tests: python module not installed",
except OSError:
"skipping Indy-specific tests: shared library not loaded",

if not INDY_FOUND:
modules = {}
package_name = "indy"
modules[package_name] = mock.MagicMock()
for mod in [
"anoncreds",
"crypto",
"did",
"error",
"pool",
"ledger",
"non_secrets",
"pairwise",
"wallet",
]:
submod = f"{package_name}.{mod}"
modules[submod] = mock.MagicMock()
INDY_STUB = mock.patch.dict(sys.modules, modules)
INDY_STUB.start()

POSTGRES_URL = os.getenv("POSTGRES_URL")


def pytest_sessionfinish(session):
global INDY_STUB
if INDY_STUB:
INDY_STUB.stop()
INDY_STUB = None


def pytest_runtest_setup(item: pytest.Item):

if tuple(item.iter_markers(name="indy")) and not INDY_FOUND:
pytest.skip("test requires Indy support")

if tuple(item.iter_markers(name="postgres")) and not POSTGRES_URL:
pytest.skip("test requires Postgres support")
1 change: 1 addition & 0 deletions docker/Dockerfile.demo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN pip3 install --no-cache-dir -r requirements.txt -r requirements.dev.txt

ADD aries_cloudagent ./aries_cloudagent
ADD bin ./bin
ADD README.md ./
ADD scripts ./scripts
ADD setup.py ./

Expand Down
11 changes: 11 additions & 0 deletions scripts/run_tests_indy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ else
DOCKER="docker"
fi

if [ -z "$POSTGRES_URL" ]; then
if [ ! -z $(docker ps --filter name=indy-demo-postgres --quiet) ]; then
DOCKER_ARGS="$DOCKER_ARGS --link indy-demo-postgres"
POSTGRES_URL="indy-demo-postgres"
fi
fi
if [ ! -z "$POSTGRES_URL" ]; then
DOCKER_ARGS="$DOCKER_ARGS -e POSTGRES_URL=$POSTGRES_URL"
fi

$DOCKER run --rm -ti --name aries-cloudagent-runner \
-v "$(pwd)/../test-reports:/usr/src/app/test-reports" \
$DOCKER_ARGS \
aries-cloudagent-test "$@"
8 changes: 7 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[tool:pytest]
testpaths = aries_cloudagent
addopts = --quiet --junitxml=./test-reports/junit.xml --cov-config .coveragerc --cov=aries_cloudagent --cov-report term --cov-report xml --flake8
addopts =
--quiet --junitxml=./test-reports/junit.xml
--cov-config .coveragerc --cov=aries_cloudagent --cov-report term-missing --cov-report xml
--flake8
markers =
indy: Tests specifically relating to Hyperledger Indy support
postgres: Tests relating to the postgres storage plugin for Indy

[flake8]
# https://github.com/ambv/black#line-length
Expand Down