Skip to content

Commit

Permalink
Added test for invalid arguments. And merged if checks in set client
Browse files Browse the repository at this point in the history
auth keyword.
  • Loading branch information
Octavian Toader authored and Octavian Toader committed May 28, 2021
1 parent b9b825c commit 8b1c950
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 11 additions & 0 deletions atest/auth.robot
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,14 @@ GET Digest Auth
Run Keyword And Expect Error KeyError: 'content-type'
... GET ${url}
Integer response status 401

Set Auth Invalid Args
${error} Set Variable TypeError: Argument "auth_type" must be \${NONE}, basic, digest or proxy.
Run Keyword And Expect Error ${error}
... Set Client Authentication none ${user} ${password}

Run Keyword And Expect Error ${error}
... Set Client Authentication doge ${user} ${password}

Run Keyword And Expect Error ${error}
... Set Client Authentication ${1} ${user} ${password}
12 changes: 7 additions & 5 deletions src/REST/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,21 @@ def set_client_authentication(self, auth_type, user=None, password=None):
| `Set Client Authentication` | ${NONE} | | |
"""
error_auth = "Argument \"auth_type\" must be ${NONE}, basic, digest or proxy."
if auth_type != None and not isinstance(auth_type, str):
raise TypeError(error_auth)

if auth_type != None:
if not isinstance(auth_type, str):
raise TypeError(error_auth)

auth_type = auth_type.lower()

if not auth_type in ["basic", "digest","proxy"] :
raise TypeError(error_auth)

if auth_type == "basic" :
auth_type = HTTPBasicAuth
elif auth_type == "digest" :
auth_type = HTTPDigestAuth
elif auth_type == "proxy" :
auth_type = HTTPProxyAuth
else :
raise Exception(error_auth)

return self._setauth(auth_type, user, password)

Expand Down

0 comments on commit 8b1c950

Please sign in to comment.