diff --git a/test/test_eumetsat_multicast.py b/test/test_eumetsat_multicast.py index 30b9a05138805c02c674eaa9401be8c693439fc7..8811d11f0d163e55cf189ace57dd0d65bc2ffdb0 100644 --- a/test/test_eumetsat_multicast.py +++ b/test/test_eumetsat_multicast.py @@ -54,13 +54,10 @@ TEST_DATA = [ @responses.activate def test_eumetsat_subscriptions(data_config, client): - def get_callback(request): - return 200, {}, json.dumps(TEST_DATA) - - responses.add_callback( + responses.add( method=responses.GET, url=f'{data_config["inventory_provider"]}/poller/eumetsat-multicast', - callback=get_callback) + json=TEST_DATA) subscriptions = get_eumetsat_multicast_subscriptions(data_config['inventory_provider']) print(subscriptions) diff --git a/test/test_grafana_dashboard.py b/test/test_grafana_dashboard.py index 7cb29b70affc65a3ab995fb9790dc11853bf38ba..31991c1a0966811fa042cef5d760a1604844b2a3 100644 --- a/test/test_grafana_dashboard.py +++ b/test/test_grafana_dashboard.py @@ -16,20 +16,15 @@ def test_get_dashboard(data_config): method=responses.GET, url=request.BASE_URL + f'api/dashboards/uid/{UID}', - callback=lambda f: ( - 404, - {}, - '')) + callback=lambda f: (404, {}, '')) data = dashboard._get_dashboard(request, UID) assert data is None - responses.add_callback(method=responses.GET, - url=request.BASE_URL + - f'api/dashboards/uid/{UID+1}', - callback=lambda f: (200, - {}, - json.dumps({"uid": 1}))) + responses.add( + method=responses.GET, + url=request.BASE_URL + f'api/dashboards/uid/{UID+1}', + json={'uid': 1}) data = dashboard._get_dashboard(request, UID + 1) assert data['uid'] == 1 @@ -42,24 +37,15 @@ def test_delete_dashboards(data_config): request = TokenRequest(**data_config, token='test') - responses.add_callback( + responses.add( method=responses.GET, - url=request.BASE_URL + - f'api/dashboards/uid/{UID}', - callback=lambda f: ( - 200, - {}, - json.dumps( - dashboards[0]))) + url=request.BASE_URL + f'api/dashboards/uid/{UID}', + json=dashboards[0]) - responses.add_callback( + responses.add( method=responses.GET, - url=request.BASE_URL + - 'api/search', - callback=lambda f: ( - 200, - {}, - json.dumps(dashboards))) + url=request.BASE_URL + 'api/search', + json=dashboards) def delete_callback(request): uid = request.path_url.split('/')[-1] @@ -79,10 +65,7 @@ def test_delete_dashboards(data_config): method=responses.DELETE, url=request.BASE_URL + f'api/dashboards/uid/{UID+1}', - callback=lambda f: ( - 400, - {}, - '')) + callback=lambda f: (400, {}, '')) data = dashboard._delete_dashboard(request, UID + 1) assert data is False @@ -98,19 +81,15 @@ def test_delete_dashboard(data_config): dash = {'id': ID, 'uid': UID, 'title': TITLE, 'version': VERSION} request = TokenRequest(**data_config, token='test') - def delete_callback(request): - return 200, {}, json.dumps({'message': 'deleted dashboard'}) - - responses.add_callback(method=responses.DELETE, - url=request.BASE_URL + f'api/dashboards/uid/{UID}', - callback=delete_callback) - - def search_callback(request): - return 200, {}, json.dumps(dash) + responses.add( + method=responses.DELETE, + url=request.BASE_URL + f'api/dashboards/uid/{UID}', + json={'message': 'deleted dashboard'}) - responses.add_callback(method=responses.GET, - url=request.BASE_URL + 'api/search', - callback=search_callback) + responses.add( + method=responses.GET, + url=request.BASE_URL + 'api/search', + json=dash) deleted = dashboard.delete_dashboard(request, dash) assert deleted @@ -127,24 +106,15 @@ def test_search_dashboard(data_config): request = TokenRequest(**data_config, token='test') - responses.add_callback( + responses.add( method=responses.GET, - url=request.BASE_URL + - 'api/search', - callback=lambda f: ( - 200, - {}, - json.dumps(dashboards))) + url=request.BASE_URL + 'api/search', + json=dashboards) - responses.add_callback( + responses.add( method=responses.GET, - url=request.BASE_URL + - f'api/dashboards/uid/{UID}', - callback=lambda f: ( - 200, - {}, - json.dumps( - dashboards[0]))) + url=request.BASE_URL + f'api/dashboards/uid/{UID}', + json=dashboards[0]) data = dashboard._search_dashboard( request, {'title': dashboards[0]['title']}) @@ -160,7 +130,8 @@ def test_search_dashboard_error(data_config): responses.add_callback( method=responses.GET, - url=request.BASE_URL + 'api/search', callback=lambda f: (400, {}, '')) + url=request.BASE_URL + 'api/search', + callback=lambda f: (400, {}, '')) data = dashboard._search_dashboard(request, {'title': 'DoesNotExist'}) assert data is None @@ -175,16 +146,15 @@ def test_create_dashboard(data_config): dashboard = {'id': ID, 'uid': UID, 'title': TITLE, 'version': VERSION} request = TokenRequest(**data_config, token='test') - def get_callback(request): - return 200, {}, json.dumps({'dashboard': dashboard}) - - responses.add_callback(method=responses.GET, - url=request.BASE_URL + f'api/dashboards/uid/{UID}', - callback=get_callback) + responses.add( + method=responses.GET, + url=request.BASE_URL + f'api/dashboards/uid/{UID}', + json={'dashboard': dashboard}) responses.add_callback( method=responses.GET, - url=request.BASE_URL + 'api/search', callback=lambda f: (400, {}, '')) + url=request.BASE_URL + 'api/search', + callback=lambda f: (400, {}, '')) def post_callback(request): body = json.loads(request.body) @@ -192,7 +162,8 @@ def test_create_dashboard(data_config): responses.add_callback( method=responses.POST, - url=request.BASE_URL + 'api/dashboards/db', callback=post_callback) + url=request.BASE_URL + 'api/dashboards/db', + callback=post_callback) data = provision.create_dashboard(request, dashboard) assert data == dashboard @@ -208,7 +179,8 @@ def test_create_dashboard_no_uid_error(data_config): responses.add_callback( method=responses.GET, - url=request.BASE_URL + 'api/search', callback=lambda f: (400, {}, '')) + url=request.BASE_URL + 'api/search', + callback=lambda f: (400, {}, '')) def post_callback(request): body = json.loads(request.body) @@ -221,7 +193,8 @@ def test_create_dashboard_no_uid_error(data_config): responses.add_callback( method=responses.POST, - url=request.BASE_URL + 'api/dashboards/db', callback=post_callback) + url=request.BASE_URL + 'api/dashboards/db', + callback=post_callback) data = provision.create_dashboard(request, dashboard) assert data is None diff --git a/test/test_grafana_folder.py b/test/test_grafana_folder.py index 3fa6b174576ecc239bd5f3824a0c2b92c0e56d90..e9baedc9e356078094bbd1b71b7b2db5f5af74ea 100644 --- a/test/test_grafana_folder.py +++ b/test/test_grafana_folder.py @@ -30,13 +30,10 @@ def test_find_folder(data_config): request = TokenRequest(**data_config, token='test') - def folder_get(request): - return 200, {}, json.dumps([]) - - responses.add_callback( + responses.add( method=responses.GET, url=f"http://{data_config['hostname']}/api/folders", - callback=folder_get) + json=[]) def folder_post(request): data = json.loads(request.body) diff --git a/test/test_gws_direct.py b/test/test_gws_direct.py index 688db385a1a0d1371876168d4f46b4066ed5cb5b..46caa180006e1273de075de9485f43b91a9130f5 100644 --- a/test/test_gws_direct.py +++ b/test/test_gws_direct.py @@ -110,15 +110,12 @@ TEST_DATA = [ @responses.activate -def test_gws(data_config, mocker, client): +def test_gws(data_config, client): - def get_callback(request): - return 200, {}, json.dumps(TEST_DATA) - - responses.add_callback( + responses.add( method=responses.GET, url=f"{data_config['inventory_provider']}/poller/gws/direct", - callback=get_callback) + json=TEST_DATA) gws_data = get_gws_direct(data_config['inventory_provider']) diff --git a/test/test_gws_indirect.py b/test/test_gws_indirect.py index 9edd611152bbd469f5ba3deec6a38e4069ed86e4..7e5a78ba1de95f71a47d66e456031572de42dce2 100644 --- a/test/test_gws_indirect.py +++ b/test/test_gws_indirect.py @@ -76,15 +76,12 @@ TEST_DATA = [ @responses.activate -def test_gws(data_config, mocker, client): +def test_gws(data_config, client): - def get_callback(request): - return 200, {}, json.dumps(TEST_DATA) - - responses.add_callback( + responses.add( method=responses.GET, url=f"{data_config['inventory_provider']}/poller/gws/indirect", - callback=get_callback) + json=TEST_DATA) gws_data = get_gws_indirect(data_config['inventory_provider']) diff --git a/test/test_update.py b/test/test_update.py index 16735679523bb7a3d7a69e8348bc9f18beb23e11..ad61acbd22b92ad2845f4473db8eeaaa402de831 100644 --- a/test/test_update.py +++ b/test/test_update.py @@ -544,34 +544,25 @@ def test_provision_folder(data_config, mocker): @responses.activate def test_provision(data_config, mocker, client): - def get_callback(request): - return 200, {}, json.dumps(NREN_INTERFACES) - - responses.add_callback( + responses.add( method=responses.GET, url=f"{data_config['inventory_provider']}/poller/interfaces", - callback=get_callback) + json=NREN_INTERFACES) - responses.add_callback( + responses.add( method=responses.GET, url=f"{data_config['inventory_provider']}/data/interfaces", - callback=get_callback) - - def folder_get(request): - return 200, {}, json.dumps([]) + json=NREN_INTERFACES) - responses.add_callback( + responses.add( method=responses.GET, url=f"http://{data_config['hostname']}/api/folders", - callback=folder_get) - - def folder_delete(request): - return 200, {}, json.dumps({"message": "Deleted folder"}) + json=[]) - responses.add_callback( + responses.add( method=responses.DELETE, url=re.compile(f"http://{data_config['hostname']}/api/folders"), - callback=folder_delete, ) + json={"message": "Deleted folder"} ) def folder_post(request): data = json.loads(request.body) @@ -582,13 +573,10 @@ def test_provision(data_config, mocker, client): url=f"http://{data_config['hostname']}/api/folders", callback=folder_post) - def home_dashboard(request): - return 200, {}, json.dumps([]) - - responses.add_callback( + responses.add( method=responses.GET, url=f"http://{data_config['hostname']}/api/search?query=Home", - callback=home_dashboard) + json=[]) TEST_DATASOURCE = [{ "name": "brian-influx-datasource", @@ -601,29 +589,20 @@ def test_provision(data_config, mocker, client): "readOnly": False }] - def datasources(request): - return 200, {}, json.dumps(TEST_DATASOURCE) - - responses.add_callback( + responses.add( method=responses.GET, url=f"http://{data_config['hostname']}/api/datasources", - callback=datasources) - - def createdashboard(request): - return 200, {}, json.dumps({'id': 666}) + json=TEST_DATASOURCE) - responses.add_callback( + responses.add( method=responses.POST, url=f"http://{data_config['hostname']}/api/dashboards/db", - callback=createdashboard) - - def preferences(request): - return 200, {}, json.dumps({'message': 'Preferences updated'}) + json={'id': 666}) - responses.add_callback( + responses.add( method=responses.PUT, url=f"http://{data_config['hostname']}/api/org/preferences", - callback=preferences) + json={'message': 'Preferences updated'}) def homedashboard(request): return 404, {}, ''