Skip to content

Commit

Permalink
Moved test fixtures into Conftest for Templates
Browse files Browse the repository at this point in the history
Enabled regression testing for key canvas functions
  • Loading branch information
dchaffey committed Jan 24, 2018
1 parent 72eb904 commit 360955c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
33 changes: 33 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from os import environ
from nipyapi.canvas import create_process_group, get_process_group
from nipyapi.canvas import delete_process_group, get_root_pg_id
from nipyapi.canvas import list_all_process_groups
from nipyapi.templates import get_template_by_name, delete_template
from nipyapi import config


Expand All @@ -26,6 +28,37 @@
]


# This wraps the template tests to ensure things are cleaned up.
@pytest.fixture(scope="class")
def template_class_wrapper(request):
def remove_test_templates():
test_templates = ['nipyapi_testTemplate_00', 'nipyapi_testTemplate_01']
for item in test_templates:
details = get_template_by_name(item)
if details is not None:
delete_template(details.id)

def remove_test_pgs():
pg_list = list_all_process_groups()
test_pgs = [
item for item in pg_list
if 'nipyapi_test' in item.status.name
]
for pg in test_pgs:
delete_process_group(
pg.id,
pg.revision
)

remove_test_templates()

def cleanup():
remove_test_templates()
remove_test_pgs()
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})."
Expand Down
10 changes: 5 additions & 5 deletions tests/test_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_get_root_pg_id():
assert isinstance(r, str)


def test_process_group_status():
def test_get_process_group_status(regress):
r = canvas.get_process_group_status(pg_id='root', detail='names')
assert isinstance(r, dict)
r = canvas.get_process_group_status('root', 'all')
Expand All @@ -32,7 +32,7 @@ def test_get_flow():
_ = canvas.get_flow('definitelyNotAPG')


def test_recurse_flow(test_pg):
def test_recurse_flow(test_pg, regress):
_ = test_pg.generate()
r = canvas.recurse_flow('root')
assert isinstance(r, ProcessGroupFlowEntity)
Expand All @@ -43,15 +43,15 @@ def test_recurse_flow(test_pg):
)


def test_list_all_process_groups(test_pg):
def test_list_all_process_groups(test_pg, regress):
_ = test_pg.generate()
r = canvas.list_all_process_groups()
assert isinstance(r, list)
for pg in r:
assert isinstance(pg, ProcessGroupEntity)


def test_create_process_group():
def test_create_process_group(regress):
r = canvas.create_process_group(
canvas.get_process_group(canvas.get_root_pg_id(), 'id'),
config.test_pg_name,
Expand All @@ -70,7 +70,7 @@ def test_create_process_group():
)


def test_get_process_group(test_pg):
def test_get_process_group(test_pg, regress):
with pytest.raises(ValueError):
_ = canvas.get_process_group('nipyapi_test', 'invalid')
single_pg = test_pg.generate()
Expand Down
32 changes: 1 addition & 31 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,7 @@
from lxml.etree import fromstring, parse


@pytest.fixture(scope="class")
def class_wrapper(request):
def remove_test_templates():
test_templates = ['nipyapi_testTemplate_00', 'nipyapi_testTemplate_01']
for item in test_templates:
details = templates.get_template_by_name(item)
if details is not None:
templates.delete_template(details.id)

def remove_test_pgs():
pg_list = canvas.list_all_process_groups()
test_pgs = [
item for item in pg_list
if 'nipyapi_test' in item.status.name
]
for pg in test_pgs:
canvas.delete_process_group(
pg.id,
pg.revision
)

remove_test_templates()

def cleanup():
remove_test_templates()
remove_test_pgs()
request.addfinalizer(cleanup)


# Upload/Download template is bugged in NiFi1.5.0, so skipping for now
@pytest.mark.usefixtures('class_wrapper')
@pytest.mark.usefixtures('template_class_wrapper')
class TestTemplates(object):
# Note that tests in this class are incremental
# so consider order when adding new tests or modifying them
Expand Down

0 comments on commit 360955c

Please sign in to comment.