Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
itminedu
synnefo
Commits
d0226124
Commit
d0226124
authored
Apr 15, 2013
by
Ilias Tsitsimpis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
astakosclient: Resolve multiple commissions at once
Refs #3440
parent
1141b8cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
8 deletions
+76
-8
astakosclient/astakosclient/__init__.py
astakosclient/astakosclient/__init__.py
+32
-1
astakosclient/astakosclient/tests.py
astakosclient/astakosclient/tests.py
+44
-7
No files found.
astakosclient/astakosclient/__init__.py
View file @
d0226124
...
...
@@ -405,7 +405,7 @@ class AstakosClient():
return
self
.
_call_astakos
(
token
,
path
)
# ----------------------------------
# POST "astakos/api/commissions/<serial>/action"
# POST "
/
astakos/api/commissions/<serial>/action"
def
commission_action
(
self
,
token
,
serial
,
action
):
"""Perform a commission action
...
...
@@ -439,6 +439,37 @@ class AstakosClient():
"""Reject a commission (see commission_action)"""
self
.
commission_action
(
token
,
serial
,
"reject"
)
# ----------------------------------
# POST "/astakos/api/commissions/action"
def
resolve_commissions
(
self
,
token
,
accept_serials
,
reject_serials
):
"""Resolve multiple commissions at once
Keyword arguments:
token -- service's token (string)
accept_serials -- commissions to accept (list of ints)
reject_serials -- commissions to reject (list of ints)
In case of success return a dict of dicts describing which
commissions accepted, which rejected and which failed to
resolved.
"""
if
not
accept_serials
:
m
=
"accept_serials parameter not given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
if
not
reject_serials
:
m
=
"reject_serials parameter not given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
path
=
"/astakos/api/commissions/action"
req_headers
=
{
'content-type'
:
'application/json'
}
req_body
=
parse_request
({
"accept"
:
accept_serials
,
"reject"
:
reject_serials
},
self
.
logger
)
return
self
.
_call_astakos
(
token
,
path
,
req_headers
,
req_body
,
"POST"
)
# --------------------------------------------------------------------
# Private functions
...
...
astakosclient/astakosclient/tests.py
View file @
d0226124
...
...
@@ -243,13 +243,21 @@ def _req_commission(conn, method, url, **kwargs):
else
:
# Issue commission action
serial
=
url
.
split
(
'/'
)[
4
]
if
serial
!=
str
(
57
):
return
_request_status_404
(
conn
,
method
,
url
,
**
kwargs
)
if
len
(
body
)
!=
1
:
return
_request_status_400
(
conn
,
method
,
url
,
**
kwargs
)
if
"accept"
not
in
body
.
keys
()
and
"reject"
not
in
body
.
keys
():
return
_request_status_400
(
conn
,
method
,
url
,
**
kwargs
)
return
(
""
,
""
,
200
)
if
serial
==
"action"
:
# Resolve multiple actions
if
body
==
resolve_commissions_req
:
return
(
""
,
simplejson
.
dumps
(
resolve_commissions_rep
),
200
)
else
:
return
_request_status_400
(
conn
,
method
,
url
,
**
kwargs
)
else
:
# Issue action for one commission
if
serial
!=
str
(
57
):
return
_request_status_404
(
conn
,
method
,
url
,
**
kwargs
)
if
len
(
body
)
!=
1
:
return
_request_status_400
(
conn
,
method
,
url
,
**
kwargs
)
if
"accept"
not
in
body
.
keys
()
and
"reject"
not
in
body
.
keys
():
return
_request_status_400
(
conn
,
method
,
url
,
**
kwargs
)
return
(
""
,
""
,
200
)
elif
method
==
"GET"
:
if
url
==
"/astakos/api/commissions"
:
...
...
@@ -430,6 +438,23 @@ commission_description = {
"quantity"
:
536870912
}]}
resolve_commissions_req
=
{
"accept"
:
[
56
,
57
],
"reject"
:
[
56
,
58
,
59
]}
resolve_commissions_rep
=
{
"accepted"
:
[
57
],
"rejected"
:
[
59
],
"failed"
:
[
[
56
,
{
"badRequest"
:
{
"message"
:
"cannot both accept and reject serial 56"
,
"code"
:
400
}}],
[
58
,
{
"itemNotFound"
:
{
"message"
:
"serial 58 does not exist"
,
"code"
:
404
}}]]}
# --------------------------------------------------------------------
# The actual tests
...
...
@@ -1024,6 +1049,18 @@ class TestCommissions(unittest.TestCase):
else
:
self
.
fail
(
"Should have raised NotFound"
)
# ----------------------------------
def
test_resolve_commissions
(
self
):
"""Test function call of resolve_commissions"""
global
token_1
_mock_request
([
_request_ok
])
try
:
client
=
AstakosClient
(
"https://example.com"
)
result
=
client
.
resolve_commissions
(
token_1
,
[
56
,
57
],
[
56
,
58
,
59
])
except
Exception
as
err
:
self
.
fail
(
"Shouldn't raise Exception %s"
%
err
)
self
.
assertEqual
(
result
,
resolve_commissions_rep
)
# ----------------------------
# Run tests
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment