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

moved old router list apis to /testing/*

parent c628bc19
No related branches found
No related tags found
No related merge requests found
from flask import Blueprint, Response
import json
from flask import Blueprint, Response, current_app, jsonify
from inventory_provider.routes import common
routes = Blueprint("inventory-data-testing-support-routes", __name__)
......@@ -8,3 +10,33 @@ routes = Blueprint("inventory-data-testing-support-routes", __name__)
def flushdb():
common.get_redis().flushdb()
return Response('OK')
@routes.route("/infinera-dna-addresses", methods=['GET', 'POST'])
@common.require_accepts_json
def infinera_addresses():
infinera_config = current_app.config[
"INVENTORY_PROVIDER_CONFIG"]["infinera-dna"]
return jsonify([dna['address'] for dna in infinera_config])
@routes.route("/coriant-tnms-addresses", methods=['GET', 'POST'])
@common.require_accepts_json
def coriant_addresses():
coriant_config = current_app.config[
"INVENTORY_PROVIDER_CONFIG"]["coriant-tnms"]
return jsonify([tnms['address'] for tnms in coriant_config])
@routes.route("/juniper-server-addresses", methods=['GET', 'POST'])
@common.require_accepts_json
def juniper_addresses():
# TODO: this route (and corant, infinera routes) can be removed
r = common.get_redis()
routers = []
for k in r.keys('junosspace:*'):
info = r.get(k.decode('utf-8'))
assert info # sanity: value shouldn't be empty
info = json.loads(info.decode('utf-8'))
routers.append(info['address'])
return jsonify(routers)
import json
import jsonschema
DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json",
"Accept": ["application/json"]
}
ROUTER_LIST_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {"type": "string"}
}
def test_flushdb(client):
rv = client.post("/testing/flushdb")
assert rv.status_code == 200
def test_infinera_addresses(client):
rv = client.post(
"/testing/infinera-dna-addresses",
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
jsonschema.validate(
json.loads(rv.data.decode("utf-8")),
ROUTER_LIST_SCHEMA)
def test_coriant_addresses(client):
rv = client.post(
"/testing/coriant-tnms-addresses",
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
jsonschema.validate(
json.loads(rv.data.decode("utf-8")),
ROUTER_LIST_SCHEMA)
def test_juniper_addresses(mocker, client):
rv = client.post(
"/testing/juniper-server-addresses",
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, ROUTER_LIST_SCHEMA)
assert len(response_data) > 0 # test data is not empty
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