Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_client_recursion_limit(fix_pg, fix_funnel, target=450):
# https://github.com/Chaffelson/nipyapi/issues/147
parent_pg = canvas.get_process_group('root')
for i in range(0, target):
parent_pg = fix_pg.generate(parent_pg, str(i))
fix_funnel.generate(parent_pg)
start = time.time()
r1 = canvas.list_all_process_groups(canvas.get_root_pg_id())
end = time.time()
assert len(r1) == target + 1 # +1 to allow for root PG
print("Len {0} Set {1}".format(len(r1), len(set([x.id for x in r1]))))
print("Elapsed r1: {0}".format((end - start)))
def test_filter_obj(fix_pg):
f_pg = fix_pg.generate()
t_1 = ['pie']
with pytest.raises(ValueError):
_ = utils.filter_obj(t_1, '', '')
with pytest.raises(ValueError):
_ = utils.filter_obj([f_pg], '', 'pie')
r1 = utils.filter_obj([f_pg], conftest.test_pg_name, 'name')
assert isinstance(r1, nifi.ProcessGroupEntity)
r2 = utils.filter_obj([f_pg], 'FakeNews', 'name')
assert r2 is None
f_pg2 = fix_pg.generate(suffix='2')
# Test greedy
r3 = utils.filter_obj([f_pg, f_pg2], conftest.test_pg_name, 'name')
assert isinstance(r3, list)
# Test not greedy
r4 = utils.filter_obj([f_pg, f_pg2], conftest.test_pg_name, 'name',
greedy=False)
assert isinstance(r4, nifi.ProcessGroupEntity)
r5 = utils.filter_obj([], '', '')
assert r5 is None
_ = utils.filter_obj(t_1, '', '')
with pytest.raises(ValueError):
_ = utils.filter_obj([f_pg], '', 'pie')
r1 = utils.filter_obj([f_pg], conftest.test_pg_name, 'name')
assert isinstance(r1, nifi.ProcessGroupEntity)
r2 = utils.filter_obj([f_pg], 'FakeNews', 'name')
assert r2 is None
f_pg2 = fix_pg.generate(suffix='2')
# Test greedy
r3 = utils.filter_obj([f_pg, f_pg2], conftest.test_pg_name, 'name')
assert isinstance(r3, list)
# Test not greedy
r4 = utils.filter_obj([f_pg, f_pg2], conftest.test_pg_name, 'name',
greedy=False)
assert isinstance(r4, nifi.ProcessGroupEntity)
r5 = utils.filter_obj([], '', '')
assert r5 is None
parent_pg=canvas.get_process_group(canvas.get_root_pg_id(), 'id'),
new_pg_name=conftest.test_pg_name,
location=(400.0, 400.0),
comment='some comment'
)
assert r.component.name == conftest.test_pg_name
assert r.position.x == r.position.y == 400
assert r.component.parent_group_id == canvas.get_root_pg_id()
assert isinstance(r, nifi.ProcessGroupEntity)
# Test process group creation on other than root process group.
s = canvas.create_process_group(parent_pg=canvas.get_process_group(conftest.test_pg_name), location=(200.0, 200.0),
new_pg_name=conftest.test_another_pg_name)
assert s.component.name == conftest.test_another_pg_name
assert s.position.x == s.position.y == 200
assert s.component.parent_group_id == canvas.get_process_group(conftest.test_pg_name, "name").id
assert isinstance(s, nifi.ProcessGroupEntity)
with pytest.raises(ValueError):
parent_pg = canvas.get_process_group('NiFi Flow')
parent_pg.id = 'invalid'
_ = canvas.create_process_group(
parent_pg,
'irrelevant',
(0, 0)
)
def test_get_component_connections(regress_nifi, fix_proc):
f_p1 = fix_proc.generate()
f_p2 = fix_proc.generate()
f_p3 = canvas.create_processor(
parent_pg=canvas.get_process_group(canvas.get_root_pg_id(), 'id'),
processor=canvas.get_processor_type('AttributesToJSON'),
location=(400.0, 425.0),
name=conftest.test_processor_name + '_inbound'
)
canvas.create_connection(f_p1, f_p3, name=conftest.test_basename)
canvas.create_connection(f_p2, f_p3, name=conftest.test_basename)
r1 = canvas.get_component_connections(f_p1)
assert len(r1) == 1
assert r1[0].source_id == f_p1.id
r2 = canvas.get_component_connections(f_p3)
assert len(r2) == 2
assert r2[0].destination_id == f_p3.id
assert r2[1].source_id in [f_p1.id, f_p2.id]
def test_create_controller(regress_nifi, fix_cont):
root_pg = canvas.get_process_group(canvas.get_root_pg_id(), 'id')
cont_type = canvas.list_all_controller_types()[0]
r1 = canvas.create_controller(
parent_pg=root_pg,
controller=cont_type
)
assert isinstance(r1, nifi.ControllerServiceEntity)
with pytest.raises(AssertionError):
_ = canvas.create_controller('pie', cont_type)
with pytest.raises(AssertionError):
_ = canvas.create_controller(root_pg, 'pie')
def test_create_process_group(regress_nifi):
r = canvas.create_process_group(
parent_pg=canvas.get_process_group(canvas.get_root_pg_id(), 'id'),
new_pg_name=conftest.test_pg_name,
location=(400.0, 400.0),
comment='some comment'
)
assert r.component.name == conftest.test_pg_name
assert r.position.x == r.position.y == 400
assert r.component.parent_group_id == canvas.get_root_pg_id()
assert isinstance(r, nifi.ProcessGroupEntity)
# Test process group creation on other than root process group.
s = canvas.create_process_group(parent_pg=canvas.get_process_group(conftest.test_pg_name), location=(200.0, 200.0),
new_pg_name=conftest.test_another_pg_name)
assert s.component.name == conftest.test_another_pg_name
assert s.position.x == s.position.y == 200
assert s.component.parent_group_id == canvas.get_process_group(conftest.test_pg_name, "name").id
assert isinstance(s, nifi.ProcessGroupEntity)
with pytest.raises(ValueError):
parent_pg = canvas.get_process_group('NiFi Flow')
parent_pg.id = 'invalid'
_ = canvas.create_process_group(
parent_pg,
'irrelevant',
(0, 0)
)
def test_dump(regress_flow_reg, fix_flow_serde):
# Testing that we don't modify or lose information in the round trip
# Processing in memory for json
export_obj = json.loads(fix_flow_serde.raw.decode('utf-8'))
ss_json = utils.dump(
obj=export_obj,
mode='json'
)
assert isinstance(ss_json, six.string_types)
round_trip_json = utils.load(ss_json)
with pytest.raises(AssertionError):
_ = utils.dump('', 'FakeNews')
with pytest.raises(TypeError):
_ = utils.dump({None}, 'json')
# Test Yaml
ss_yaml = utils.dump(
obj=export_obj,
mode='yaml'
)
assert isinstance(ss_yaml, six.string_types)
round_trip_yaml = utils.load(ss_yaml)
"""Tests for nipyapi security module."""
from __future__ import absolute_import
import pytest
from tests import conftest
import nipyapi
# Tells pytest to skip this module of security testing is not enabled.
pytestmark = pytest.mark.skipif(not conftest.test_security, reason='test_security disabled in Conftest')
# Useful for manual testing
if conftest.test_security:
test_host = nipyapi.config.default_host
nipyapi.utils.set_endpoint('https://' + test_host + ':18443/nifi-registry-api', True, True)
nipyapi.utils.set_endpoint('https://' + test_host + ':8443/nifi-api', True, True)
def test_list_service_users():
# This test suite makes extensive use of this call in fixtures
pass
def test_get_service_user():
# This test suite makes extensive use of this call in fixtures
pass
def test_create_service_user():
with pytest.raises(AssertionError):
nipyapi.security.create_service_user(service='bob', identity='pie')
with pytest.raises(AssertionError):
def setUp(self):
self.api =nipyapi.swagger_client.apis.tenants_api.TenantsApi()