Skip to content

Commit d2d5e41

Browse files
committed
Ensure port setting works. Complete test coverage
1 parent 4ae77aa commit d2d5e41

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

amadeus/client/request.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,18 @@ def _encoded_params(self):
116116

117117
# Builds up the full URL based on the scheme, host, path, and params
118118
def __full_url(self):
119-
full_url = '{0}://{1}{2}'.format(self.scheme, self.host, self.path)
119+
full_url = '{0}://{1}'.format(self.scheme, self.host)
120+
if not self.__port_matches_scheme():
121+
full_url = '{0}:{1}'.format(full_url, self.port)
122+
full_url = '{0}{1}'.format(full_url, self.path)
120123
if (self.verb == 'GET'):
121124
full_url += '?{0}'.format(self._encoded_params())
122125
return full_url
123126

127+
def __port_matches_scheme(self):
128+
return ((self.ssl and self.port == 443) or
129+
(not self.ssl and self.port == 80))
130+
124131
# Adds an extra header if the verb is POST
125132
def __add_post_data_header(self):
126133
if (self.verb == 'POST'):

specs/client/request_spec.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,26 @@
8484
})
8585

8686
expect(self.request.http_request).to(be_a(HTTPRequest))
87+
expect(self.request.http_request.get_full_url()).to(equal(
88+
'https://example.com/foo/bar'))
8789
expect(self.request.http_request.data).to(equal(b'foo=bar'))
8890
expect(self.request.http_request.get_header('Content-Type')).to(
89-
equal('application/x-www-form-urlencoded')
90-
)
91+
equal('application/x-www-form-urlencoded'))
92+
93+
with it('should handle a custom scheme and port'):
94+
self.request = Request({
95+
'host': self.host,
96+
'verb': 'POST',
97+
'path': self.path,
98+
'params': self.params,
99+
'bearer_token': self.bearer_token,
100+
'client_version': self.client_version,
101+
'language_version': self.lang_version,
102+
'app_id': self.app_id,
103+
'app_version': self.app_version,
104+
'port': 8080,
105+
'ssl': False
106+
})
107+
108+
expect(self.request.http_request.get_full_url()).to(equal(
109+
'http://example.com:8080/foo/bar'))

specs/mixins/http_spec.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@
5050
)
5151
)
5252

53+
with it('should use the same access token when cashed'):
54+
self.response.result = {'access_token': '123', 'expires_in': 2000}
55+
self.client._unauthenticated_request = self.request_method
56+
self.client.request('POST', '/foo', foo='bar')
57+
58+
self.response.result = {'access_token': '234', 'expires_in': 2000}
59+
self.client._unauthenticated_request = self.request_method
60+
self.client.request('POST', '/foo', foo='bar')
61+
62+
expect(self.client._unauthenticated_request).not_to(
63+
have_been_called_with(
64+
'POST', '/foo', {'foo': 'bar'}, 'Bearer 234'
65+
)
66+
)
67+
5368
with context('Client._unauthenticated_request'):
5469
with it('should execute a full request'):
5570
with Stub() as http_response:

specs/mixins/pagination_spec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
with context('Client.last'):
7878
with it('should create a new request with the page and call it'):
79+
self.response.request.params = {'page': {'offset': '0'}}
7980
self.response.result = {
8081
'meta': {'links': {'last': 'http://f.co?page=1'}}
8182
}

0 commit comments

Comments
 (0)