Skip to content

Commit 71332e5

Browse files
committed
Merge pull request #44 from SamHausmann/RCB-396
removed check version module and updated http headers to including bi…
2 parents 4faf5df + f0c319f commit 71332e5

File tree

3 files changed

+5
-70
lines changed

3 files changed

+5
-70
lines changed

rosette/api.py

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ def __init__(self, api, suburl):
346346
self.user_key = api.user_key
347347
self.logger = api.logger
348348
self.useMultipart = False
349-
self.checker = lambda: api.check_version()
350349
self.suburl = suburl
351350
self.debug = api.debug
352351
self.api = api
@@ -374,7 +373,7 @@ def info(self):
374373
@return: A dictionary telling server version and other
375374
identifying data."""
376375
url = self.service_url + "info"
377-
headers = {'Accept': 'application/json'}
376+
headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION}
378377
if self.debug:
379378
headers['X-RosetteAPI-Devel'] = 'true'
380379
self.logger.info('info: ' + url)
@@ -383,27 +382,14 @@ def info(self):
383382
r = self.api._get_http(url, headers=headers)
384383
return self.__finish_result(r, "info")
385384

386-
def checkVersion(self):
387-
"""Issues a special "info" request to the L{EndpointCaller}'s specific endpoint.
388-
@return: A dictionary containing server version as well as version check"""
389-
url = self.service_url + "info?clientVersion=" + _BINDING_VERSION
390-
headers = {'Accept': 'application/json'}
391-
if self.debug:
392-
headers["X-RosetteAPI-Devel"] = 'true'
393-
self.logger.info('info: ' + url)
394-
if self.user_key is not None:
395-
headers["X-RosetteAPI-Key"] = self.user_key
396-
r = self.api._post_http(url, None, headers)
397-
return self.__finish_result(r, "info")
398-
399385
def ping(self):
400386
"""Issues a "ping" request to the L{EndpointCaller}'s (server-wide) endpoint.
401387
@return: A dictionary if OK. If the server cannot be reached,
402388
or is not the right server or some other error occurs, it will be
403389
signalled."""
404390

405391
url = self.service_url + 'ping'
406-
headers = {'Accept': 'application/json'}
392+
headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION}
407393
if self.debug:
408394
headers['X-RosetteAPI-Devel'] = 'true'
409395
self.logger.info('Ping: ' + url)
@@ -443,14 +429,14 @@ def call(self, parameters):
443429
"Text-only input only works for DocumentParameter endpoints",
444430
self.suburl)
445431

446-
self.checker()
447-
448432
self.useMultipart = parameters.useMultipart
449433
url = self.service_url + self.suburl
450434
params_to_serialize = parameters.serialize()
451435
headers = {}
452436
if self.user_key is not None:
453437
headers["X-RosetteAPI-Key"] = self.user_key
438+
headers["X-RosetteAPI-Binding"] = "python"
439+
headers["X-RosetteAPI-Binding-Version"] = _BINDING_VERSION
454440
if self.useMultipart:
455441
params = dict(
456442
(key,
@@ -513,7 +499,6 @@ def __init__(
513499
self.logger = logging.getLogger('rosette.api')
514500
self.logger.info('Initialized on ' + self.service_url)
515501
self.debug = debug
516-
self.version_checked = False
517502

518503
if (retries < 1):
519504
retries = 1
@@ -629,23 +614,6 @@ def _post_http(self, url, data, headers):
629614

630615
return _ReturnObject(_my_loads(rdata, response_headers), status)
631616

632-
def check_version(self):
633-
"""
634-
Info call to check binding version against the current Rosette API
635-
"""
636-
if self.version_checked:
637-
return True
638-
op = EndpointCaller(self, None)
639-
result = op.checkVersion()
640-
if 'versionChecked' not in result or result['versionChecked'] is False:
641-
raise RosetteException(
642-
"incompatibleVersion",
643-
"The server version is not compatible with binding version " +
644-
_BINDING_VERSION,
645-
'')
646-
self.version_checked = True
647-
return True
648-
649617
def ping(self):
650618
"""
651619
Create a ping L{EndpointCaller} for the server and ping it.

tests/mock-data/response/info.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
"buildNumber": "6bafb29d",
33
"buildTime": "2015.05.08_12:31:26",
44
"name": "Rosette API",
5-
"version": "0.5.0",
6-
"versionChecked": true
5+
"version": "0.5.0"
76
}

tests/test_rosette_api.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,6 @@ def test_info(api, json_response):
8888

8989
result = api.info()
9090
assert result["name"] == "Rosette API"
91-
assert result["versionChecked"] is True
92-
httpretty.disable()
93-
httpretty.reset()
94-
95-
# Test check version - fail
96-
97-
98-
def test_check_version_fails(api, doc_params):
99-
httpretty.enable()
100-
body = json.dumps({'name': 'Rosette API'})
101-
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
102-
body=body, status=200, content_type="application/json")
103-
with pytest.raises(RosetteException) as e_rosette:
104-
result = api.categories(doc_params)
105-
106-
assert e_rosette.value.status == "incompatibleVersion"
107-
httpretty.disable()
108-
httpretty.reset()
109-
110-
# Test check version - pass
111-
112-
113-
def test_check_version_pass(api, json_response, doc_params):
114-
httpretty.enable()
115-
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
116-
body=json_response, status=200, content_type="application/json")
117-
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/categories",
118-
body=json_response, status=200, content_type="application/json")
119-
120-
result = api.categories(doc_params)
121-
122-
assert result["versionChecked"] is True
12391
httpretty.disable()
12492
httpretty.reset()
12593

0 commit comments

Comments
 (0)