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
ca6ba0b4
Commit
ca6ba0b4
authored
Mar 01, 2013
by
Ilias Tsitsimpis
Committed by
Christos Stavrakakis
Mar 12, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement getUUIDs/getUUID methods
parent
e35a3608
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
8 deletions
+100
-8
snf-astakos-client/astakosclient/__init__.py
snf-astakos-client/astakosclient/__init__.py
+31
-0
snf-astakos-client/astakosclient/tests.py
snf-astakos-client/astakosclient/tests.py
+69
-8
No files found.
snf-astakos-client/astakosclient/__init__.py
View file @
ca6ba0b4
...
...
@@ -228,6 +228,37 @@ class AstakosClient():
# XXX: check if exists
return
uuid_dict
.
get
(
uuid
)
# ----------------------------------
def
getUUIDs
(
self
,
token
,
display_names
):
"""Return a displayname_catalog for the given names
Keyword arguments:
token -- user's token (string)
display_names -- list of user names (list of strings)
The returned displayname_catalog is a dictionary with
the names as keys and the corresponding uuids as values
"""
req_headers
=
{
'content-type'
:
'application/json'
}
req_body
=
simplejson
.
dumps
({
'displaynames'
:
display_names
})
req_path
=
"/user_catalogs"
data
=
self
.
_callAstakos
(
token
,
req_path
,
req_headers
,
req_body
,
"POST"
)
# XXX: check if exists
return
data
.
get
(
"displayname_catalog"
)
def
getUUID
(
self
,
token
,
display_name
):
"""Return the uuid of a name (see getUUIDs)"""
if
not
display_name
:
m
=
"No display_name was given"
self
.
logger
.
error
(
m
)
raise
ValueError
(
m
)
name_dict
=
self
.
getUUIDs
(
token
,
[
display_name
])
# XXX: check if exists
return
name_dict
.
get
(
display_name
)
# --------------------------------------------------------------------
# Private functions
...
...
snf-astakos-client/astakosclient/tests.py
View file @
ca6ba0b4
...
...
@@ -153,13 +153,26 @@ def _reqCatalogs(conn, method, url, **kwargs):
# Return
body
=
simplejson
.
loads
(
kwargs
[
'body'
])
uuids
=
body
[
'uuids'
]
catalogs
=
{}
if
user_1
[
'uuid'
]
in
uuids
:
catalogs
[
user_1
[
'uuid'
]]
=
user_1
[
'username'
]
if
user_2
[
'uuid'
]
in
uuids
:
catalogs
[
user_2
[
'uuid'
]]
=
user_2
[
'username'
]
return_catalog
=
{
"displayname_catalog"
:
{},
"uuid_catalog"
:
catalogs
}
if
'uuids'
in
body
:
# Return uuid_catalog
uuids
=
body
[
'uuids'
]
catalogs
=
{}
if
user_1
[
'uuid'
]
in
uuids
:
catalogs
[
user_1
[
'uuid'
]]
=
user_1
[
'username'
]
if
user_2
[
'uuid'
]
in
uuids
:
catalogs
[
user_2
[
'uuid'
]]
=
user_2
[
'username'
]
return_catalog
=
{
"displayname_catalog"
:
{},
"uuid_catalog"
:
catalogs
}
elif
'displaynames'
in
body
:
# Return displayname_catalog
names
=
body
[
'displaynames'
]
catalogs
=
{}
if
user_1
[
'username'
]
in
names
:
catalogs
[
user_1
[
'username'
]]
=
user_1
[
'uuid'
]
if
user_2
[
'username'
]
in
names
:
catalogs
[
user_2
[
'username'
]]
=
user_2
[
'uuid'
]
return_catalog
=
{
"displayname_catalog"
:
catalogs
,
"uuid_catalog"
:
{}}
else
:
return_catalog
=
{
"displayname_catalog"
:
{},
"uuid_catalog"
:
{}}
return
(
simplejson
.
dumps
(
return_catalog
),
200
)
...
...
@@ -527,7 +540,7 @@ class TestDisplayNames(unittest.TestCase):
# ----------------------------------
# Get Info for both users
def
test_DisplayNames
WithGet
(
self
):
def
test_DisplayNames
(
self
):
"""Test getDisplayNames with both users"""
global
token_1
,
user_1
,
user_2
_mockRequest
([
_requestOk
])
...
...
@@ -555,6 +568,54 @@ class TestDisplayNames(unittest.TestCase):
self
.
assertEqual
(
info
,
user_1
[
'username'
])
class
TestGetUUIDs
(
unittest
.
TestCase
):
"""Test cases for functions getUUIDs/getUUID"""
# ----------------------------------
# Test the response we get for invalid token
def
test_InvalidToken
(
self
):
"""Test the response we get for invalid token (using pool)"""
global
user_1
token
=
"skaksaFlBl+fasFdaf24sx=="
_mockRequest
([
_requestOk
])
try
:
client
=
AstakosClient
(
"https://example.com"
)
client
.
getUUIDs
(
token
,
[
user_1
[
'username'
]])
except
AstakosClientException
as
err
:
if
err
.
status
!=
401
:
self
.
fail
(
"Should have returned 401 (Invalid X-Auth-Token)"
)
else
:
self
.
fail
(
"Should have returned 401 (Invalid X-Auth-Token)"
)
# ----------------------------------
# Get info for both users
def
test_UUIDs
(
self
):
"""Test getUUIDs with both users"""
global
token_1
,
user_1
,
user_2
_mockRequest
([
_requestOk
])
try
:
client
=
AstakosClient
(
"https://example.com"
)
catalog
=
client
.
getUUIDs
(
token_1
,
[
user_1
[
'username'
],
user_2
[
'username'
]])
except
:
self
.
fail
(
"Shouldn't raise an Exception"
)
self
.
assertEqual
(
catalog
[
user_1
[
'username'
]],
user_1
[
'uuid'
])
self
.
assertEqual
(
catalog
[
user_2
[
'username'
]],
user_2
[
'uuid'
])
# ----------------------------------
# Get uuid for user 2
def
test_GetUUIDUserTwo
(
self
):
"""Test getUUID for User Two"""
global
token_1
,
user_2
_mockRequest
([
_requestOffline
,
_requestOk
])
try
:
client
=
AstakosClient
(
"https://example.com"
,
retry
=
1
)
info
=
client
.
getUUID
(
token_2
,
user_1
[
'username'
])
except
:
self
.
fail
(
"Shouldn't raise an Exception"
)
self
.
assertEqual
(
info
,
user_1
[
'uuid'
])
# ----------------------------
# Run tests
if
__name__
==
"__main__"
:
...
...
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