Skip to content
This repository has been archived by the owner on Dec 15, 2019. It is now read-only.

Commit

Permalink
fuck yes
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl committed Jun 24, 2014
1 parent d0a96f9 commit f52ff9b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
10 changes: 6 additions & 4 deletions saratoga/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,22 @@ def _quickfail(fail):
try:
params = json.loads(requestContent)
except ValueError:
params = None
params = {}


if not params:
if not params and request.args is not None:
params = {}
for key, val in request.args.iteritems():
if len(val) == 1:
if type(val) in [list, tuple] and len(val) == 1:
params[key] = val[0]
else:
params[key] = val

userParams = {"params": params}
schema = processor.get("requestSchema", None)

if params is None:
params = {}

if schema:
v = Draft4Validator(schema)
errors = sorted(v.iter_errors(params), key=lambda e: e.path)
Expand Down
2 changes: 1 addition & 1 deletion saratoga/test/requestMock.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _cb(result, request):
if replaceEmptyWithEmptyDict and not params:
params = {}
req = requestMock(path, body=json.dumps(params), method=method,
headers=headers)
headers=headers)
else:
req = requestMock(path, args=params, method=method,
headers=headers)
Expand Down
25 changes: 25 additions & 0 deletions saratoga/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ def rendered(request):
return self.api.test("/v1/dictResponse",
params={"data": {"hi": "there"}}).addCallback(rendered)

def test_dictResponsePOSTArgs(self):
"""
Test that it allows a dict response.
"""
def rendered(request):
self.assertEqual(
json.loads(request.getWrittenData()),
{"status": "success", "data": {"hi": "there"}}
)

return self.api.test("/v1/dictResponse",
params={"data": {"hi": "there"}}, useBody=False).addCallback(rendered)


def test_listResponse(self):
"""
Expand All @@ -303,6 +316,18 @@ def rendered(request):
return self.api.test("/v1/listResponse",
params={"data": ["hi", "there"]}).addCallback(rendered)

def test_listResponsePOSTArgs(self):
"""
Test that it allows a list response.
"""
def rendered(request):
self.assertEqual(
json.loads(request.getWrittenData()),
{"status": "success", "data": ["hi", "there"]}
)

return self.api.test("/v1/listResponse",
params={"data": [["hi", "there"]]}, useBody=False).addCallback(rendered)

def test_dictResponseFailure(self):
"""
Expand Down
5 changes: 2 additions & 3 deletions saratoga/test/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ def test_checkForNoAuthBackend(self):

authenticator = auth.DefaultAuthenticator(None)

self.assertRaises(
AuthenticationFailed, authenticator.auth_usernameAndPassword,
"user", "pass")
f = authenticator.auth_usernameAndPassword("user", "pass")
self.assertIsInstance(self.failureResultOf(f).value, AuthenticationFailed)


def test_inMemoryStringSharedSecretSourcePassword(self):
Expand Down

0 comments on commit f52ff9b

Please sign in to comment.