Skip to content

Commit

Permalink
AnsibleDockerTesting (#35)
Browse files Browse the repository at this point in the history
* Initial commit for new branch

* Added test for environment availability before testing
Dropping Docker requirement as extraneous
  • Loading branch information
Chaffelson committed Feb 1, 2018
1 parent df74b26 commit e11428e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
setuptools==38.4.0
urllib3==1.22
lxml==4.1.1
docker>=2.7.0
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ coveralls>=1.2.0
certifi>=2017.7.27.1
pylint>=1.7.4
virtualenvwrapper>=4.8
requests>=2.18.4
64 changes: 44 additions & 20 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import pytest
from os import environ
import requests
from requests import ConnectionError
from nipyapi.canvas import *
from nipyapi.templates import *
from nipyapi.versioning import *
Expand Down Expand Up @@ -32,14 +34,54 @@
# Mostly because loading up all the environments takes too long
if "TRAVIS" in environ and environ["TRAVIS"] == "true":
print("Running tests on TRAVIS, skipping regression suite")
test_endpoints = [config.nifi_config.host]
nifi_test_endpoints = [config.nifi_config.host]
registry_test_endpoints = [config.registry_config.host]
else:
print("Running tests on NOT TRAVIS, enabling regression suite")
test_endpoints = [
nifi_test_endpoints = [
'http://localhost:10120/nifi-api', # add earlier as required
'http://localhost:10140/nifi-api',
config.nifi_config.host # reset to default, currently 1.5.0
]
registry_test_endpoints = [config.registry_config.host]


# 'regress' generates tests against previous versions of NiFi
def pytest_generate_tests(metafunc):
if 'regress' in metafunc.fixturenames:
# print("Regression testing requested for ({0})."
# .format(metafunc.function.__name__))
metafunc.parametrize(
argnames='regress',
argvalues=nifi_test_endpoints,
indirect=True
)


@pytest.fixture(scope="function")
def regress(request):
# print("\nSetting nifi endpoint to ({0}).".format(request.param))
config.nifi_config.api_client.host = request.param


# Tests that the Docker test environment is available before running test suite
@pytest.fixture(scope="session", autouse=True)
def session_setup():
def is_endpoint_up(endpoint_url):
try:
response = requests.get(endpoint_url)
if response.status_code == 200:
return True
except ConnectionError:
return False

for url in nifi_test_endpoints + registry_test_endpoints:
target_url = url.replace('-api', '')
if not is_endpoint_up(target_url):
pytest.exit(
"Expected Service endpoint ({0}) is not responding"
.format(target_url)
)


# This wraps the template tests to ensure things are cleaned up.
Expand Down Expand Up @@ -72,24 +114,6 @@ def cleanup():
request.addfinalizer(cleanup)


# 'regress' generates tests against previous versions of NiFi
def pytest_generate_tests(metafunc):
if 'regress' in metafunc.fixturenames:
# print("Regression testing requested for ({0})."
# .format(metafunc.function.__name__))
metafunc.parametrize(
argnames='regress',
argvalues=test_endpoints,
indirect=True
)


@pytest.fixture(scope="function")
def regress(request):
# print("\nSetting nifi endpoint to ({0}).".format(request.param))
config.nifi_config.api_client.host = request.param


@pytest.fixture(scope="function")
def fixture_pg(request):
class Dummy:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ deps =
commands =
pip install -U pip
coverage run --source=nipyapi setup.py test
py.test --basetemp={envtmpdir} -s
py.test --basetemp={envtmpdir} -s -x
- coveralls

0 comments on commit e11428e

Please sign in to comment.