From c6c54f429feebc43d50eea146e12bbf98de2cf54 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Fri, 12 Apr 2019 11:22:24 +0200
Subject: [PATCH] pep8

---
 inventory_provider/db/opsdb.py    | 48 +++++++++++--------------------
 inventory_provider/routes/data.py |  4 ---
 inventory_provider/routes/jobs.py |  2 +-
 test/test_general_data_routes.py  |  3 --
 test/test_opsdb_queries.py        |  8 ++----
 5 files changed, 21 insertions(+), 44 deletions(-)

diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py
index b39e51e7..00ce299b 100644
--- a/inventory_provider/db/opsdb.py
+++ b/inventory_provider/db/opsdb.py
@@ -1,8 +1,5 @@
 from inventory_provider.db import db
 
-
-
-
 geant_lambda_sql = """SELECT
                       absid AS id,
                       name,
@@ -297,6 +294,21 @@ SELECT
 
     def _fields2rsp(row):
 
+        def _pop(r, suffix):
+            return {
+                'name': r['equipment_name' + suffix],
+                'card id': r['card_id' + suffix],
+                'port number': r['port' + suffix],
+                'pop': {
+                    'absid': r['pop_absid' + suffix],
+                    'name': r['pop_name' + suffix],
+                    'city': r['pop_city' + suffix],
+                    'country': r['pop_country' + suffix],
+                    'abbreviation': r['pop_abbreviation' + suffix],
+                    'longitude': r['pop_longitude' + suffix],
+                    'latitude': r['pop_latitude' + suffix]
+                }
+            }
 
         return {
             'absid': row['absid'],
@@ -306,34 +318,8 @@ SELECT
             'peering_type': row['peering_type'],
             'status': row['status'],
             'name': row['name'],
-            'a': {
-                'name': row['equipment_name_a'],
-                'card id': row['card_id_a'],
-                'port number': row['port_a'],
-                'pop': {
-                    'absid': row['pop_absid_a'],
-                    'name': row['pop_name_a'],
-                    'city': row['pop_city_a'],
-                    'country': row['pop_country_a'],
-                    'abbreviation': row['pop_abbreviation_a'],
-                    'longitude': row['pop_longitude_a'],
-                    'latitude': row['pop_latitude_a']
-                }
-            },
-            'b': {
-                'name': row['equipment_name_b'],
-                'card id': row['card_id_b'],
-                'port number': row['port_b'],
-                'pop': {
-                    'absid': row['pop_absid_b'],
-                    'name': row['pop_name_b'],
-                    'city': row['pop_city_b'],
-                    'country': row['pop_country_b'],
-                    'abbreviation': row['pop_abbreviation_b'],
-                    'longitude': row['pop_longitude_b'],
-                    'latitude': row['pop_latitude_b']
-                }
-            }
+            'a': _pop(row, '_a'),
+            'b': _pop(row, '_b'),
         }
 
     circuit_query = base_query + """
diff --git a/inventory_provider/routes/data.py b/inventory_provider/routes/data.py
index 6eef23b8..258f05ea 100644
--- a/inventory_provider/routes/data.py
+++ b/inventory_provider/routes/data.py
@@ -56,7 +56,3 @@ def equipment_location(equipment_name):
             mimetype="text/html")
 
     return jsonify(result)
-
-
-
-
diff --git a/inventory_provider/routes/jobs.py b/inventory_provider/routes/jobs.py
index 9fd9d3f2..a02ddea1 100644
--- a/inventory_provider/routes/jobs.py
+++ b/inventory_provider/routes/jobs.py
@@ -1,4 +1,4 @@
-from flask import Blueprint, Response, current_app, jsonify
+from flask import Blueprint, current_app, jsonify
 from inventory_provider.tasks import worker
 from inventory_provider.routes import common
 
diff --git a/test/test_general_data_routes.py b/test/test_general_data_routes.py
index b11771ef..fa8c385a 100644
--- a/test/test_general_data_routes.py
+++ b/test/test_general_data_routes.py
@@ -1,9 +1,6 @@
 import contextlib
 import json
 import jsonschema
-import pytest
-
-from inventory_provider.db import db
 
 DEFAULT_REQUEST_HEADERS = {
     "Content-type": "application/json",
diff --git a/test/test_opsdb_queries.py b/test/test_opsdb_queries.py
index 0584ed3e..e44e9597 100644
--- a/test/test_opsdb_queries.py
+++ b/test/test_opsdb_queries.py
@@ -39,7 +39,6 @@ def connection(db_params):
 
 EQUIPMENT_LOCATION_METADATA = {
     "$schema": "http://json-schema.org/draft-07/schema#",
-    "type": "object",
 
     "definitions": {
         "pop-info": {
@@ -85,7 +84,6 @@ EQUIPMENT_LOCATION_METADATA = {
 
 CORIANT_PATH_METADATA = {
     "$schema": "http://json-schema.org/draft-07/schema#",
-    "type": "object",
 
     "definitions": {
         "pop-info": {
@@ -149,9 +147,9 @@ CORIANT_PATH_METADATA = {
 
 
 @pytest.mark.parametrize('equipment', [
-'mx1.cbg.uk.geant.net',
-'grv3.lon.uk.geant.net',
-'mx1.gen.ch.geant.net'
+    'mx1.cbg.uk.geant.net',
+    'grv3.lon.uk.geant.net',
+    'mx1.gen.ch.geant.net'
 ])
 def test_equipment_location(connection, equipment):
     circuit = opsdb.lookup_pop_info(connection, equipment)
-- 
GitLab