Skip to content
Snippets Groups Projects
Commit ea8a090b authored by Erik Reid's avatar Erik Reid
Browse files

use responses add ipv add_callback for static json

parent 2b1777ce
No related branches found
No related tags found
No related merge requests found
...@@ -54,13 +54,10 @@ TEST_DATA = [ ...@@ -54,13 +54,10 @@ TEST_DATA = [
@responses.activate @responses.activate
def test_eumetsat_subscriptions(data_config, client): def test_eumetsat_subscriptions(data_config, client):
def get_callback(request): responses.add(
return 200, {}, json.dumps(TEST_DATA)
responses.add_callback(
method=responses.GET, method=responses.GET,
url=f'{data_config["inventory_provider"]}/poller/eumetsat-multicast', url=f'{data_config["inventory_provider"]}/poller/eumetsat-multicast',
callback=get_callback) json=TEST_DATA)
subscriptions = get_eumetsat_multicast_subscriptions(data_config['inventory_provider']) subscriptions = get_eumetsat_multicast_subscriptions(data_config['inventory_provider'])
print(subscriptions) print(subscriptions)
......
...@@ -16,20 +16,15 @@ def test_get_dashboard(data_config): ...@@ -16,20 +16,15 @@ def test_get_dashboard(data_config):
method=responses.GET, method=responses.GET,
url=request.BASE_URL + url=request.BASE_URL +
f'api/dashboards/uid/{UID}', f'api/dashboards/uid/{UID}',
callback=lambda f: ( callback=lambda f: (404, {}, ''))
404,
{},
''))
data = dashboard._get_dashboard(request, UID) data = dashboard._get_dashboard(request, UID)
assert data is None assert data is None
responses.add_callback(method=responses.GET, responses.add(
url=request.BASE_URL + method=responses.GET,
f'api/dashboards/uid/{UID+1}', url=request.BASE_URL + f'api/dashboards/uid/{UID+1}',
callback=lambda f: (200, json={'uid': 1})
{},
json.dumps({"uid": 1})))
data = dashboard._get_dashboard(request, UID + 1) data = dashboard._get_dashboard(request, UID + 1)
assert data['uid'] == 1 assert data['uid'] == 1
...@@ -42,24 +37,15 @@ def test_delete_dashboards(data_config): ...@@ -42,24 +37,15 @@ def test_delete_dashboards(data_config):
request = TokenRequest(**data_config, token='test') request = TokenRequest(**data_config, token='test')
responses.add_callback( responses.add(
method=responses.GET, method=responses.GET,
url=request.BASE_URL + url=request.BASE_URL + f'api/dashboards/uid/{UID}',
f'api/dashboards/uid/{UID}', json=dashboards[0])
callback=lambda f: (
200,
{},
json.dumps(
dashboards[0])))
responses.add_callback( responses.add(
method=responses.GET, method=responses.GET,
url=request.BASE_URL + url=request.BASE_URL + 'api/search',
'api/search', json=dashboards)
callback=lambda f: (
200,
{},
json.dumps(dashboards)))
def delete_callback(request): def delete_callback(request):
uid = request.path_url.split('/')[-1] uid = request.path_url.split('/')[-1]
...@@ -79,10 +65,7 @@ def test_delete_dashboards(data_config): ...@@ -79,10 +65,7 @@ def test_delete_dashboards(data_config):
method=responses.DELETE, method=responses.DELETE,
url=request.BASE_URL + url=request.BASE_URL +
f'api/dashboards/uid/{UID+1}', f'api/dashboards/uid/{UID+1}',
callback=lambda f: ( callback=lambda f: (400, {}, ''))
400,
{},
''))
data = dashboard._delete_dashboard(request, UID + 1) data = dashboard._delete_dashboard(request, UID + 1)
assert data is False assert data is False
...@@ -98,19 +81,15 @@ def test_delete_dashboard(data_config): ...@@ -98,19 +81,15 @@ def test_delete_dashboard(data_config):
dash = {'id': ID, 'uid': UID, 'title': TITLE, 'version': VERSION} dash = {'id': ID, 'uid': UID, 'title': TITLE, 'version': VERSION}
request = TokenRequest(**data_config, token='test') request = TokenRequest(**data_config, token='test')
def delete_callback(request): responses.add(
return 200, {}, json.dumps({'message': 'deleted dashboard'}) method=responses.DELETE,
url=request.BASE_URL + f'api/dashboards/uid/{UID}',
responses.add_callback(method=responses.DELETE, json={'message': 'deleted dashboard'})
url=request.BASE_URL + f'api/dashboards/uid/{UID}',
callback=delete_callback)
def search_callback(request):
return 200, {}, json.dumps(dash)
responses.add_callback(method=responses.GET, responses.add(
url=request.BASE_URL + 'api/search', method=responses.GET,
callback=search_callback) url=request.BASE_URL + 'api/search',
json=dash)
deleted = dashboard.delete_dashboard(request, dash) deleted = dashboard.delete_dashboard(request, dash)
assert deleted assert deleted
...@@ -127,24 +106,15 @@ def test_search_dashboard(data_config): ...@@ -127,24 +106,15 @@ def test_search_dashboard(data_config):
request = TokenRequest(**data_config, token='test') request = TokenRequest(**data_config, token='test')
responses.add_callback( responses.add(
method=responses.GET, method=responses.GET,
url=request.BASE_URL + url=request.BASE_URL + 'api/search',
'api/search', json=dashboards)
callback=lambda f: (
200,
{},
json.dumps(dashboards)))
responses.add_callback( responses.add(
method=responses.GET, method=responses.GET,
url=request.BASE_URL + url=request.BASE_URL + f'api/dashboards/uid/{UID}',
f'api/dashboards/uid/{UID}', json=dashboards[0])
callback=lambda f: (
200,
{},
json.dumps(
dashboards[0])))
data = dashboard._search_dashboard( data = dashboard._search_dashboard(
request, {'title': dashboards[0]['title']}) request, {'title': dashboards[0]['title']})
...@@ -160,7 +130,8 @@ def test_search_dashboard_error(data_config): ...@@ -160,7 +130,8 @@ def test_search_dashboard_error(data_config):
responses.add_callback( responses.add_callback(
method=responses.GET, 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'}) data = dashboard._search_dashboard(request, {'title': 'DoesNotExist'})
assert data is None assert data is None
...@@ -175,16 +146,15 @@ def test_create_dashboard(data_config): ...@@ -175,16 +146,15 @@ def test_create_dashboard(data_config):
dashboard = {'id': ID, 'uid': UID, 'title': TITLE, 'version': VERSION} dashboard = {'id': ID, 'uid': UID, 'title': TITLE, 'version': VERSION}
request = TokenRequest(**data_config, token='test') request = TokenRequest(**data_config, token='test')
def get_callback(request): responses.add(
return 200, {}, json.dumps({'dashboard': dashboard}) method=responses.GET,
url=request.BASE_URL + f'api/dashboards/uid/{UID}',
responses.add_callback(method=responses.GET, json={'dashboard': dashboard})
url=request.BASE_URL + f'api/dashboards/uid/{UID}',
callback=get_callback)
responses.add_callback( responses.add_callback(
method=responses.GET, 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): def post_callback(request):
body = json.loads(request.body) body = json.loads(request.body)
...@@ -192,7 +162,8 @@ def test_create_dashboard(data_config): ...@@ -192,7 +162,8 @@ def test_create_dashboard(data_config):
responses.add_callback( responses.add_callback(
method=responses.POST, 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) data = provision.create_dashboard(request, dashboard)
assert data == dashboard assert data == dashboard
...@@ -208,7 +179,8 @@ def test_create_dashboard_no_uid_error(data_config): ...@@ -208,7 +179,8 @@ def test_create_dashboard_no_uid_error(data_config):
responses.add_callback( responses.add_callback(
method=responses.GET, 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): def post_callback(request):
body = json.loads(request.body) body = json.loads(request.body)
...@@ -221,7 +193,8 @@ def test_create_dashboard_no_uid_error(data_config): ...@@ -221,7 +193,8 @@ def test_create_dashboard_no_uid_error(data_config):
responses.add_callback( responses.add_callback(
method=responses.POST, 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) data = provision.create_dashboard(request, dashboard)
assert data is None assert data is None
...@@ -30,13 +30,10 @@ def test_find_folder(data_config): ...@@ -30,13 +30,10 @@ def test_find_folder(data_config):
request = TokenRequest(**data_config, token='test') request = TokenRequest(**data_config, token='test')
def folder_get(request): responses.add(
return 200, {}, json.dumps([])
responses.add_callback(
method=responses.GET, method=responses.GET,
url=f"http://{data_config['hostname']}/api/folders", url=f"http://{data_config['hostname']}/api/folders",
callback=folder_get) json=[])
def folder_post(request): def folder_post(request):
data = json.loads(request.body) data = json.loads(request.body)
......
...@@ -110,15 +110,12 @@ TEST_DATA = [ ...@@ -110,15 +110,12 @@ TEST_DATA = [
@responses.activate @responses.activate
def test_gws(data_config, mocker, client): def test_gws(data_config, client):
def get_callback(request): responses.add(
return 200, {}, json.dumps(TEST_DATA)
responses.add_callback(
method=responses.GET, method=responses.GET,
url=f"{data_config['inventory_provider']}/poller/gws/direct", url=f"{data_config['inventory_provider']}/poller/gws/direct",
callback=get_callback) json=TEST_DATA)
gws_data = get_gws_direct(data_config['inventory_provider']) gws_data = get_gws_direct(data_config['inventory_provider'])
......
...@@ -76,15 +76,12 @@ TEST_DATA = [ ...@@ -76,15 +76,12 @@ TEST_DATA = [
@responses.activate @responses.activate
def test_gws(data_config, mocker, client): def test_gws(data_config, client):
def get_callback(request): responses.add(
return 200, {}, json.dumps(TEST_DATA)
responses.add_callback(
method=responses.GET, method=responses.GET,
url=f"{data_config['inventory_provider']}/poller/gws/indirect", url=f"{data_config['inventory_provider']}/poller/gws/indirect",
callback=get_callback) json=TEST_DATA)
gws_data = get_gws_indirect(data_config['inventory_provider']) gws_data = get_gws_indirect(data_config['inventory_provider'])
......
...@@ -544,34 +544,25 @@ def test_provision_folder(data_config, mocker): ...@@ -544,34 +544,25 @@ def test_provision_folder(data_config, mocker):
@responses.activate @responses.activate
def test_provision(data_config, mocker, client): def test_provision(data_config, mocker, client):
def get_callback(request): responses.add(
return 200, {}, json.dumps(NREN_INTERFACES)
responses.add_callback(
method=responses.GET, method=responses.GET,
url=f"{data_config['inventory_provider']}/poller/interfaces", url=f"{data_config['inventory_provider']}/poller/interfaces",
callback=get_callback) json=NREN_INTERFACES)
responses.add_callback( responses.add(
method=responses.GET, method=responses.GET,
url=f"{data_config['inventory_provider']}/data/interfaces", url=f"{data_config['inventory_provider']}/data/interfaces",
callback=get_callback) json=NREN_INTERFACES)
def folder_get(request):
return 200, {}, json.dumps([])
responses.add_callback( responses.add(
method=responses.GET, method=responses.GET,
url=f"http://{data_config['hostname']}/api/folders", url=f"http://{data_config['hostname']}/api/folders",
callback=folder_get) json=[])
def folder_delete(request):
return 200, {}, json.dumps({"message": "Deleted folder"})
responses.add_callback( responses.add(
method=responses.DELETE, method=responses.DELETE,
url=re.compile(f"http://{data_config['hostname']}/api/folders"), url=re.compile(f"http://{data_config['hostname']}/api/folders"),
callback=folder_delete, ) json={"message": "Deleted folder"} )
def folder_post(request): def folder_post(request):
data = json.loads(request.body) data = json.loads(request.body)
...@@ -582,13 +573,10 @@ def test_provision(data_config, mocker, client): ...@@ -582,13 +573,10 @@ def test_provision(data_config, mocker, client):
url=f"http://{data_config['hostname']}/api/folders", url=f"http://{data_config['hostname']}/api/folders",
callback=folder_post) callback=folder_post)
def home_dashboard(request): responses.add(
return 200, {}, json.dumps([])
responses.add_callback(
method=responses.GET, method=responses.GET,
url=f"http://{data_config['hostname']}/api/search?query=Home", url=f"http://{data_config['hostname']}/api/search?query=Home",
callback=home_dashboard) json=[])
TEST_DATASOURCE = [{ TEST_DATASOURCE = [{
"name": "brian-influx-datasource", "name": "brian-influx-datasource",
...@@ -601,29 +589,20 @@ def test_provision(data_config, mocker, client): ...@@ -601,29 +589,20 @@ def test_provision(data_config, mocker, client):
"readOnly": False "readOnly": False
}] }]
def datasources(request): responses.add(
return 200, {}, json.dumps(TEST_DATASOURCE)
responses.add_callback(
method=responses.GET, method=responses.GET,
url=f"http://{data_config['hostname']}/api/datasources", url=f"http://{data_config['hostname']}/api/datasources",
callback=datasources) json=TEST_DATASOURCE)
def createdashboard(request):
return 200, {}, json.dumps({'id': 666})
responses.add_callback( responses.add(
method=responses.POST, method=responses.POST,
url=f"http://{data_config['hostname']}/api/dashboards/db", url=f"http://{data_config['hostname']}/api/dashboards/db",
callback=createdashboard) json={'id': 666})
def preferences(request):
return 200, {}, json.dumps({'message': 'Preferences updated'})
responses.add_callback( responses.add(
method=responses.PUT, method=responses.PUT,
url=f"http://{data_config['hostname']}/api/org/preferences", url=f"http://{data_config['hostname']}/api/org/preferences",
callback=preferences) json={'message': 'Preferences updated'})
def homedashboard(request): def homedashboard(request):
return 404, {}, '' return 404, {}, ''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment