jenkins-bot has submitted this change and it was merged.

Change subject: Properly support 'basePath'
......................................................................


Properly support 'basePath'

According to <http://swagger.io/specification/>, the option is
camelCased as 'basePath'. Check for that value and prepend it to the
endpoint if present.

Updated tests to support that functionality.

Change-Id: I2e7ae113c43252081496f8b4d4ca1cadaefe6abe
---
M servicechecker/swagger.py
M servicechecker/tests/fixtures/test.json
M servicechecker/tests/fixtures/test_error_spec.json
M servicechecker/tests/unit/test_swagger.py
4 files changed, 12 insertions(+), 10 deletions(-)

Approvals:
  Mobrovac: Looks good to me, but someone else must approve
  Giuseppe Lavagetto: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/servicechecker/swagger.py b/servicechecker/swagger.py
index f431a9d..ccc29fe 100755
--- a/servicechecker/swagger.py
+++ b/servicechecker/swagger.py
@@ -89,9 +89,11 @@
             raise ValueError("No valid spec found")
 
         TemplateUrl.default = r.get('x-default-params', {})
+        base_path = r.get('basePath', '')
         for endpoint, data in r['paths'].items():
             if not endpoint:
                 continue
+            endpoint = base_path + endpoint
             for key in self._supported_methods:
                 try:
                     d = data[key]
diff --git a/servicechecker/tests/fixtures/test.json 
b/servicechecker/tests/fixtures/test.json
index edb8394..ec0cae6 100644
--- a/servicechecker/tests/fixtures/test.json
+++ b/servicechecker/tests/fixtures/test.json
@@ -1,5 +1,5 @@
 {
-  "basepath": "/api",
+  "basePath": "/api",
   "x-default-params": {"who": "joe"},
   "paths": {
     "/simple": { "get": {} },
diff --git a/servicechecker/tests/fixtures/test_error_spec.json 
b/servicechecker/tests/fixtures/test_error_spec.json
index 8d11544..2cf2ef1 100644
--- a/servicechecker/tests/fixtures/test_error_spec.json
+++ b/servicechecker/tests/fixtures/test_error_spec.json
@@ -1,5 +1,5 @@
 {
-  "basepath": "/api",
+  "basePath": "/api",
   "x-default-params": {"who": "joe"},
   "paths": {
     "/simple": {},
diff --git a/servicechecker/tests/unit/test_swagger.py 
b/servicechecker/tests/unit/test_swagger.py
index 3be614a..d955588 100644
--- a/servicechecker/tests/unit/test_swagger.py
+++ b/servicechecker/tests/unit/test_swagger.py
@@ -210,7 +210,7 @@
         swagger.fetch_url = mock.MagicMock(side_effect=self.router)
 
     def setUp(self):
-        self.cs = swagger.CheckService('127.0.0.1', 'http://example.org/api')
+        self.cs = swagger.CheckService('127.0.0.1', 'http://example.org')
         fn = os.path.join(os.path.dirname(__file__), '../fixtures/test.json')
         with open(fn, 'rb') as f:
             data = f.read().decode('utf-8')
@@ -225,7 +225,7 @@
         self.assertEquals(self.cs._timeout, 5)
         self.assertEquals(self.cs.port, '80')
         self.assertEquals(self.cs.http_host, 'example.org')
-        self.assertEquals(self.cs._url, 'http://127.0.0.1:80/api')
+        self.assertEquals(self.cs._url, 'http://127.0.0.1:80')
 
     def test_get_endpoints(self):
         """
@@ -234,7 +234,7 @@
         self.mock_routes()
         l = [el for el, data in self.cs.get_endpoints()]
         l.sort()
-        self.assertListEqual(l, [u'/simple', u'/{who}/{verb}'])
+        self.assertListEqual(l, [u'/api/simple', u'/api/{who}/{verb}'])
 
     def test_get_ep_invalid_spec(self):
         """
@@ -247,15 +247,15 @@
             '/?spec', {'status': 200, 'body': json.loads(data)})
         self.mock_routes()
         l = [el for el, _ in self.cs.get_endpoints()]
-        self.assertEquals(l, [u'/{who}/{verb}'])
+        self.assertEquals(l, [u'/api/{who}/{verb}'])
 
     def test_run(self):
         """
         Test a successful run
         """
-        self.add_mock_response('/simple', {'status': 200, 'body': 'hi'})
+        self.add_mock_response('/api/simple', {'status': 200, 'body': 'hi'})
         self.add_mock_response(
-            '/joe/rulez', {'status': 200, 'body': 'For sure!'})
+            '/api/joe/rulez', {'status': 200, 'body': 'For sure!'})
         self.mock_routes()
         with self.assertRaises(SystemExit) as e:
             self.cs.run()
@@ -276,9 +276,9 @@
         """
         Test a warning exit
         """
-        self.add_mock_response('/simple', {'status': 200, 'body': 'hi'})
+        self.add_mock_response('/api/simple', {'status': 200, 'body': 'hi'})
         self.add_mock_response(
-            '/joe/rulez', {'status': 200, 'body': 'For sure?'})
+            '/api/joe/rulez', {'status': 200, 'body': 'For sure?'})
         self.mock_routes()
         with self.assertRaises(SystemExit) as e:
             self.cs.run()

-- 
To view, visit https://gerrit.wikimedia.org/r/307910
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2e7ae113c43252081496f8b4d4ca1cadaefe6abe
Gerrit-PatchSet: 1
Gerrit-Project: operations/software/service-checker
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to