Skip to content

Commit 934069a

Browse files
authored
Merge pull request #343 from MarketSquare/fix/342-missing-warn-if-equal-symbol-in-url
fix #342 add warnings for = in url also in session less requests keywords
2 parents 6afd1ce + 684503b commit 934069a

File tree

5 files changed

+53
-22
lines changed

5 files changed

+53
-22
lines changed

atests/test_url_warning.robot

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ Suite Teardown Teardown Flask Http Server And Sessions
99

1010
*** Test Cases ***
1111

12-
Named URL with = symbol should not have warnings
12+
On Session Named URL with = symbol should not have warnings
1313
GET On Session ${GLOBAL_SESSION} url=/anything?a=a&b=b
1414

15-
Positional URL with = symbol
15+
On Session Positional URL with = symbol
1616
Run Keyword And Expect Error TypeError:* GET On Session ${GLOBAL_SESSION} /anything?a=a&b=b
1717

18-
Positional URL with '' should not have warnings
18+
On Session Positional URL with '' should not have warnings
1919
GET On Session ${GLOBAL_SESSION} ${Empty}
2020

21-
Positional URL with None should not have warnings
21+
On Session Positional URL with None should not have warnings
2222
GET On Session ${GLOBAL_SESSION} ${None}
2323

24+
Session Less Named URL with = symbol should not have warnings
25+
GET url=${HTTP_LOCAL_SERVER}/anything?a=a&b=b
26+
27+
Session Less Positional URL with = symbol
28+
Run Keyword And Expect Error TypeError:* GET ${HTTP_LOCAL_SERVER}/anything?a=a&b=b
29+
30+
Session Less Positional URL with '' should not have warnings
31+
GET ${HTTP_LOCAL_SERVER}/${Empty}
32+

src/RequestsLibrary/RequestsKeywords.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from robot.api.deco import keyword
44
from robot.libraries.BuiltIn import BuiltIn
55

6+
from RequestsLibrary import log
67
from RequestsLibrary.compat import urljoin
7-
from RequestsLibrary import utils, log
8-
from RequestsLibrary.utils import is_file_descriptor
8+
from RequestsLibrary.utils import is_file_descriptor, warn_if_equal_symbol_in_url_session_less
99

1010

1111
class RequestsKeywords(object):
@@ -54,7 +54,6 @@ def _common_request(
5454

5555
return resp
5656

57-
5857
@staticmethod
5958
def _merge_url(session, uri):
6059
"""
@@ -152,6 +151,7 @@ def get_file_for_streaming_upload(path):
152151
return open(path, 'rb')
153152

154153
@keyword('GET')
154+
@warn_if_equal_symbol_in_url_session_less
155155
def session_less_get(self, url, params=None,
156156
expected_status=None, msg=None, **kwargs):
157157
"""
@@ -193,6 +193,7 @@ def session_less_get(self, url, params=None,
193193
return response
194194

195195
@keyword('POST')
196+
@warn_if_equal_symbol_in_url_session_less
196197
def session_less_post(self, url, data=None, json=None,
197198
expected_status=None, msg=None, **kwargs):
198199
"""
@@ -219,6 +220,7 @@ def session_less_post(self, url, data=None, json=None,
219220
return response
220221

221222
@keyword('PUT')
223+
@warn_if_equal_symbol_in_url_session_less
222224
def session_less_put(self, url, data=None, json=None,
223225
expected_status=None, msg=None, **kwargs):
224226
"""
@@ -246,6 +248,7 @@ def session_less_put(self, url, data=None, json=None,
246248
return response
247249

248250
@keyword('HEAD')
251+
@warn_if_equal_symbol_in_url_session_less
249252
def session_less_head(self, url,
250253
expected_status=None, msg=None, **kwargs):
251254
"""
@@ -270,6 +273,7 @@ def session_less_head(self, url,
270273
return response
271274

272275
@keyword('PATCH')
276+
@warn_if_equal_symbol_in_url_session_less
273277
def session_less_patch(self, url, data=None, json=None,
274278
expected_status=None, msg=None, **kwargs):
275279
"""
@@ -296,6 +300,7 @@ def session_less_patch(self, url, data=None, json=None,
296300
return response
297301

298302
@keyword('DELETE')
303+
@warn_if_equal_symbol_in_url_session_less
299304
def session_less_delete(self, url,
300305
expected_status=None, msg=None, **kwargs):
301306
"""
@@ -317,6 +322,7 @@ def session_less_delete(self, url,
317322
return response
318323

319324
@keyword('OPTIONS')
325+
@warn_if_equal_symbol_in_url_session_less
320326
def session_less_options(self, url,
321327
expected_status=None, msg=None, **kwargs):
322328
"""

src/RequestsLibrary/RequestsOnSessionKeywords.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from robot.api.deco import keyword
22

3-
from RequestsLibrary.utils import warn_if_equal_symbol_in_url
3+
from RequestsLibrary.utils import warn_if_equal_symbol_in_url_on_session
44
from .SessionKeywords import SessionKeywords
55

66

77
class RequestsOnSessionKeywords(SessionKeywords):
88

9-
@warn_if_equal_symbol_in_url
109
@keyword("GET On Session")
10+
@warn_if_equal_symbol_in_url_on_session
1111
def get_on_session(self, alias, url, params=None,
1212
expected_status=None, msg=None, **kwargs):
1313
"""
@@ -33,8 +33,8 @@ def get_on_session(self, alias, url, params=None,
3333
self._check_status(expected_status, response, msg)
3434
return response
3535

36-
@warn_if_equal_symbol_in_url
3736
@keyword("POST On Session")
37+
@warn_if_equal_symbol_in_url_on_session
3838
def post_on_session(self, alias, url, data=None, json=None,
3939
expected_status=None, msg=None, **kwargs):
4040
"""
@@ -62,8 +62,8 @@ def post_on_session(self, alias, url, data=None, json=None,
6262
self._check_status(expected_status, response, msg)
6363
return response
6464

65-
@warn_if_equal_symbol_in_url
6665
@keyword("PATCH On Session")
66+
@warn_if_equal_symbol_in_url_on_session
6767
def patch_on_session(self, alias, url, data=None, json=None,
6868
expected_status=None, msg=None, **kwargs):
6969
"""
@@ -91,8 +91,8 @@ def patch_on_session(self, alias, url, data=None, json=None,
9191
self._check_status(expected_status, response, msg)
9292
return response
9393

94-
@warn_if_equal_symbol_in_url
9594
@keyword("PUT On Session")
95+
@warn_if_equal_symbol_in_url_on_session
9696
def put_on_session(self, alias, url, data=None, json=None,
9797
expected_status=None, msg=None, **kwargs):
9898
"""
@@ -120,8 +120,8 @@ def put_on_session(self, alias, url, data=None, json=None,
120120
self._check_status(expected_status, response, msg)
121121
return response
122122

123-
@warn_if_equal_symbol_in_url
124123
@keyword('DELETE On Session')
124+
@warn_if_equal_symbol_in_url_on_session
125125
def delete_on_session(self, alias, url,
126126
expected_status=None, msg=None, **kwargs):
127127
"""
@@ -144,8 +144,8 @@ def delete_on_session(self, alias, url,
144144
self._check_status(expected_status, response, msg)
145145
return response
146146

147-
@warn_if_equal_symbol_in_url
148147
@keyword("HEAD On Session")
148+
@warn_if_equal_symbol_in_url_on_session
149149
def head_on_session(self, alias, url,
150150
expected_status=None, msg=None, **kwargs):
151151
"""
@@ -171,8 +171,8 @@ def head_on_session(self, alias, url,
171171
self._check_status(expected_status, response, msg)
172172
return response
173173

174-
@warn_if_equal_symbol_in_url
175174
@keyword("OPTIONS On Session")
175+
@warn_if_equal_symbol_in_url_on_session
176176
def options_on_session(self, alias, url,
177177
expected_status=None, msg=None, **kwargs):
178178
"""

src/RequestsLibrary/utils.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,32 @@ def format_data_according_to_header(session, data, headers):
125125
return data
126126

127127

128-
def warn_if_equal_symbol_in_url(func):
128+
def _log_url_warning_if_url_not_in_kwargs(kwargs):
129+
if 'url' not in kwargs:
130+
logger.warn("You might have an = symbol in url."
131+
" You better place 'url=' before, example: 'url=/your-url/foo?param=a'"
132+
" or use '/your-url/foo params=param=a' or escape it")
133+
134+
135+
def warn_if_equal_symbol_in_url_session_less(func):
129136
def decorator(*args, **kwargs):
130137
try:
131-
args[2]
138+
args[1]
132139
except IndexError:
133-
if 'url' not in kwargs:
134-
logger.warn("You might have an = symbol in url."
135-
" You better place 'url=' before, example: 'url=/your-url/foo?param=a'"
136-
" or use '/your-url/foo params=param=a' or escape it")
140+
_log_url_warning_if_url_not_in_kwargs(kwargs)
141+
return func(*args, **kwargs)
137142

143+
decorator.__name__ = func.__name__
144+
decorator.__doc__ = func.__doc__
145+
return decorator
146+
147+
148+
def warn_if_equal_symbol_in_url_on_session(func):
149+
def decorator(*args, **kwargs):
150+
try:
151+
args[2]
152+
except IndexError:
153+
_log_url_warning_if_url_not_in_kwargs(kwargs)
138154
return func(*args, **kwargs)
139155
decorator.__name__ = func.__name__
140156
decorator.__doc__ = func.__doc__

src/RequestsLibrary/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '0.9.1'
1+
VERSION = '0.9.2'

0 commit comments

Comments
 (0)