Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
synnefo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
synnefo
Commits
5299cc4d
Commit
5299cc4d
authored
Apr 12, 2013
by
Ilias Tsitsimpis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
astakosclient: Add request for commission's info
Refs #3440
parent
149774a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
2 deletions
+91
-2
astakosclient/astakosclient/__init__.py
astakosclient/astakosclient/__init__.py
+21
-0
astakosclient/astakosclient/tests.py
astakosclient/astakosclient/tests.py
+70
-2
No files found.
astakosclient/astakosclient/__init__.py
View file @
5299cc4d
...
...
@@ -374,6 +374,27 @@ class AstakosClient():
"""
return
self
.
_call_astakos
(
token
,
"/astakos/api/commissions"
)
# ----------------------------------
# GET "/astakos/api/commissions/<serial>
def
get_commission_info
(
self
,
token
,
serial
):
"""Get Description of a Commission
Keyword arguments:
token -- user's token (string)
serial -- commission's id (int)
In case of success return a dict of dicts containing
informations (details) about the requests commission
"""
if
not
serial
:
m
=
"Commissions serial not given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
path
=
"/astakos/api/commissions/"
+
str
(
serial
)
return
self
.
_call_astakos
(
token
,
path
)
# --------------------------------------------------------------------
# Private functions
...
...
astakosclient/astakosclient/tests.py
View file @
5299cc4d
...
...
@@ -239,8 +239,16 @@ def _req_commission(conn, method, url, **kwargs):
else
:
return
(
""
,
simplejson
.
dumps
(
commission_successful_response
),
200
)
elif
method
==
"GET"
:
# Return pending commission
return
(
""
,
simplejson
.
dumps
(
pending_commissions
),
200
)
if
url
==
"/astakos/api/commissions"
:
# Return pending commission
return
(
""
,
simplejson
.
dumps
(
pending_commissions
),
200
)
else
:
# Return commissions's description
serial
=
url
[
25
:]
if
serial
==
str
(
57
):
return
(
""
,
simplejson
.
dumps
(
commission_description
),
200
)
else
:
return
_request_status_404
(
conn
,
method
,
url
,
**
kwargs
)
else
:
return
_request_status_400
(
conn
,
method
,
url
,
**
kwargs
)
...
...
@@ -392,6 +400,23 @@ commission_failure_response = {
pending_commissions
=
[
100
,
200
]
commission_description
=
{
"serial"
:
57
,
"issue_time"
:
"2013-04-08T10:19:15.0373"
,
"provisions"
:
[
{
"holder"
:
"c02f315b-7d84-45bc-a383-552a3f97d2ad"
,
"source"
:
"system"
,
"resource"
:
"cyclades.vm"
,
"quantity"
:
1
},
{
"holder"
:
"c02f315b-7d84-45bc-a383-552a3f97d2ad"
,
"source"
:
"system"
,
"resource"
:
"cyclades.ram"
,
"quantity"
:
536870912
}]}
# --------------------------------------------------------------------
# The actual tests
...
...
@@ -891,6 +916,49 @@ class TestCommissions(unittest.TestCase):
self
.
fail
(
"Shouldn't raise Exception %s"
%
err
)
self
.
assertEqual
(
response
,
pending_commissions
)
# ----------------------------------
def
test_get_commission_info
(
self
):
"""Test function call of get_commission_info"""
global
token_1
,
commission_description
_mock_request
([
_request_ok
])
try
:
client
=
\
AstakosClient
(
"https://example.com"
,
use_pool
=
True
,
pool_size
=
2
)
response
=
client
.
get_commission_info
(
token_1
,
57
)
except
Exception
as
err
:
self
.
fail
(
"Shouldn't raise Exception %s"
%
err
)
self
.
assertEqual
(
response
,
commission_description
)
# ----------------------------------
def
test_get_commission_info_not_found
(
self
):
"""Test function call of get_commission_info with invalid serial"""
global
token_1
_mock_request
([
_request_ok
])
try
:
client
=
AstakosClient
(
"https://example.com"
)
client
.
get_commission_info
(
token_1
,
"57lala"
)
except
NotFound
:
pass
except
Exception
as
err
:
self
.
fail
(
"Shouldn't raise Exception %s"
%
err
)
else
:
self
.
fail
(
"Should have raised NotFound"
)
# ----------------------------------
def
test_get_commission_info_without_serial
(
self
):
"""Test function call of get_commission_info without serial"""
global
token_1
_mock_request
([
_request_ok
])
try
:
client
=
AstakosClient
(
"https://example.com"
)
client
.
get_commission_info
(
token_1
,
None
)
except
BadValue
:
pass
except
Exception
as
err
:
self
.
fail
(
"Shouldn't raise Exception %s"
%
err
)
else
:
self
.
fail
(
"Should have raise BadValue"
)
# ----------------------------
# 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