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 = [
@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)
......
......@@ -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
......@@ -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)
......
......@@ -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'])
......
......@@ -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'])
......
......@@ -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, {}, ''
......
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