diff --git a/test/test_grafana_datasource.py b/test/test_grafana_datasource.py index af30debf7fee7a8aff2504248498e660eeecbe8c..488b7023c3a577082c5c37da0b7698e28de186b6 100644 --- a/test/test_grafana_datasource.py +++ b/test/test_grafana_datasource.py @@ -32,7 +32,7 @@ def test_get_missing_datasource_definitions(data_config): dir = '/tmp/dirthatreallyshouldnotexistsousealonganduniquestring' # it returns a generator, so iterate :) - for data in provision.get_missing_datasource_definitions(request, dir): + for data in datasource.get_missing_datasource_definitions(request, dir): pass diff --git a/test/test_update.py b/test/test_update.py index 5854c9bdd708b69e81b08d6f06f774aa1c19f479..607d02d1b0ee512efef191ef04b4979679459b5b 100644 --- a/test/test_update.py +++ b/test/test_update.py @@ -7,9 +7,172 @@ DEFAULT_REQUEST_HEADERS = { } +TEST_INTERFACES = [ + { + "router": "mx1.ath2.gr.geant.net", + "name": "xe-1/0/1", + "bundle": [], + "bundle-parents": [], + "snmp-index": 569, + "description": "PHY RESERVED | New OTEGLOBE ATH2-VIE 10Gb LS", + "circuits": [] + }, + { + "router": "mx1.ath2.gr.geant.net", + "name": "ge-1/3/7", + "bundle": [], + "bundle-parents": [], + "snmp-index": 543, + "description": "PHY SPARE", + "circuits": [] + }, + { + "router": "mx1.ham.de.geant.net", + "name": "xe-2/2/0.13", + "bundle": [], + "bundle-parents": [], + "snmp-index": 721, + "description": "SRV_L2CIRCUIT CUSTOMER WP6T3 WP6T3 #ham_lon2-WP6-GTS_20063 |", # noqa: E501 + "circuits": [ + { + "id": 52382, + "name": "ham_lon2-WP6-GTS_20063_L2c", + "type": "", + "status": "operational" + } + ] + }, + { + "router": "mx1.fra.de.geant.net", + "name": "ae27", + "bundle": [], + "bundle-parents": [ + "xe-10/0/2", + "xe-10/3/2", + "xe-10/3/3" + ], + "snmp-index": 760, + "description": "LAG CUSTOMER ULAKBIM SRF9940983 |", + "circuits": [ + { + "id": 40983, + "name": "ULAKBIM AP2 LAG", + "type": "", + "status": "operational" + } + ] + }, + { + "router": "mx2.zag.hr.geant.net", + "name": "xe-2/1/0", + "bundle": [], + "bundle-parents": [], + "snmp-index": 739, + "description": "PHY SPARE", + "circuits": [] + }, + { + "router": "rt1.rig.lv.geant.net", + "name": "xe-0/1/5", + "bundle": [], + "bundle-parents": [], + "snmp-index": 539, + "description": "PHY SPARE", + "circuits": [] + }, + { + "router": "srx1.ch.office.geant.net", + "name": "ge-0/0/0", + "bundle": [], + "bundle-parents": [], + "snmp-index": 513, + "description": "Reserved for GEANT OC to test Virgin Media link", + "circuits": [] + }, + { + "router": "mx1.par.fr.geant.net", + "name": "xe-4/1/4.1", + "bundle": [], + "bundle-parents": [], + "snmp-index": 1516, + "description": "SRV_L2CIRCUIT INFRASTRUCTURE JRA1 JRA1 | #SDX-L2_PILOT-Br52 OF-P3_par ", # noqa: E501 + "circuits": [] + }, + { + "router": "mx1.lon.uk.geant.net", + "name": "lt-1/3/0.61", + "bundle": [], + "bundle-parents": [], + "snmp-index": 1229, + "description": "SRV_IAS INFRASTRUCTURE ACCESS GLOBAL #LON-IAS-RE-Peering | BGP Peering - IAS Side", # noqa: E501 + "circuits": [] + }, + { + "router": "mx1.sof.bg.geant.net", + "name": "xe-2/0/5", + "bundle": [], + "bundle-parents": [], + "snmp-index": 694, + "description": "PHY RESERVED | Prime Telecom Sofia-Bucharest 3_4", + "circuits": [] + } +] + + +def generate_folder(data): + return { + "id": 555, + "uid": data['uid'], + "title": data['title'], + "url": f"/dashboards/f/{data['uid']}/{data['title'].lower()}", + "hasAcl": False, + "canSave": True, + "canEdit": True, + "canAdmin": True, + "createdBy": "Anonymous", + "created": "2021-02-23T15:33:46Z", + "updatedBy": "Anonymous", + "updated": "2021-02-23T15:33:46Z", + "version": 1 + } + + @responses.activate def test_provision(data_config, mocker, client): + def get_callback(request): + return 200, {}, json.dumps(TEST_INTERFACES) + + responses.add_callback( + method=responses.GET, + url=f"http://{data_config['inventory_provider']}/poller/interfaces", + callback=get_callback) + + def folder_get(request): + return 200, {}, json.dumps([]) + + responses.add_callback( + method=responses.GET, + url=f"http://{data_config['hostname']}/api/folders", + callback=folder_get) + + def folder_post(request): + data = json.loads(request.body) + return 200, {}, json.dumps(generate_folder(data)) + + responses.add_callback( + method=responses.POST, + url=f"http://{data_config['hostname']}/api/folders", + callback=folder_post) + + def home_dashboard(request): + return 200, {}, json.dumps([]) + + responses.add_callback( + method=responses.GET, + url=f"http://{data_config['hostname']}/api/search?query=Home", + callback=home_dashboard) + TEST_DATASOURCE = [{ "name": "brian-influx-datasource", "type": "influxdb", @@ -21,12 +184,20 @@ def test_provision(data_config, mocker, client): "readOnly": False }] + def datasources(request): + return 200, {}, json.dumps(TEST_DATASOURCE) + + responses.add_callback( + method=responses.GET, + url=f"http://{data_config['hostname']}/api/datasources", + callback=datasources) + PROVISIONED_ORGANIZATION = { 'name': data_config['organizations'][0], 'id': 0 } - EXISTING_ORGS = [{'name': org, 'id': i + 1} + EXISTING_ORGS = [{**org, 'id': i + 1} for i, org in enumerate(data_config['organizations'][1:])] _mocked_get_organizations = mocker.patch( @@ -50,11 +221,6 @@ def test_provision(data_config, mocker, client): _mocked_create_api_token.return_value = { 'key': 'testtoken', 'id': 0} # api token - _mocked_get_missing_ds_defs = mocker.patch( - 'brian_dashboard_manager.grafana.provision.' + - 'get_missing_datasource_definitions') - _mocked_get_missing_ds_defs.return_value = TEST_DATASOURCE - _mocked_create_datasource = mocker.patch( 'brian_dashboard_manager.grafana.provision.create_datasource') # we dont care about this, just mark it created