Skip to content

Commit

Permalink
Merge pull request #162 from ARGOeu/devel
Browse files Browse the repository at this point in the history
Prepare for v0.61
  • Loading branch information
themiszamani authored Feb 13, 2023
2 parents 8230a02 + 57718ce commit 477f3eb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.6.1] - 2023-02-06

### Added

* AM-314 Add projects:createUser functionality to ams library

## [0.6.0] - 2022-11-03

### Added
Expand Down
4 changes: 3 additions & 1 deletion argo-ams-library.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Name: argo-ams-library
Summary: %{sum}
Version: 0.6.0
Version: 0.6.1
Release: 1%{?dist}

Group: Development/Libraries
Expand Down Expand Up @@ -73,6 +73,8 @@ rm -rf %{buildroot}


%changelog
* Mon Feb 6 2023 agelostsal <[email protected]> - 0.6.1-1%{?dist}
- AM-314 Add projects:createUser functionality to ams library
* Thu Nov 3 2022 Daniel Vrcic <[email protected]>, agelostsal <[email protected]> - 0.6.0-1%{?dist}
- AM-143 Add support for requests ReadTimeOut exception
- AM-228 Add user management fuctionality to AMS-library
Expand Down
40 changes: 39 additions & 1 deletion pymod/ams.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .amsmsg import AmsMessage
from .amstopic import AmsTopic
from .amssubscription import AmsSubscription
from .amsuser import AmsUser, AmsUserPage
from .amsuser import AmsUser, AmsUserPage, AmsUserProject

try:
from collections import OrderedDict
Expand Down Expand Up @@ -82,6 +82,7 @@ def __init__(self, endpoint, authn_port, token="", cert="", key=""):
# project api calls
"project_add_member": ["post", "https://{0}/v1/projects/{1}/members/{2}:add"],
"project_get_member": ["get", "https://{0}/v1/projects/{1}/members/{2}"],
"project_create_member": ["post", "https://{0}/v1/projects/{1}/members/{2}"],
"project_remove_member": ["post", "https://{0}/v1/projects/{1}/members/{2}:remove"],
"project_create": ["post", "https://{0}/v1/projects/{1}"],
"project_update": ["put", "https://{0}/v1/projects/{1}"],
Expand Down Expand Up @@ -127,6 +128,7 @@ def __init__(self, endpoint, authn_port, token="", cert="", key=""):

"project_add_member": ["post", set([400, 401, 403, 404, 409])],
"project_get_member": ["get", set([400, 401, 403, 404])],
"project_create_member": ["post", set([400, 401, 403, 404, 409])],
"project_remove_member": ["get", set([401, 403, 404])],
"project_create": ["post", set([400, 401, 403, 409])],
"project_update": ["put", set([400, 401, 403, 404, 409])],
Expand Down Expand Up @@ -1341,6 +1343,42 @@ def add_project_member(self, username, project=None, roles=None, **reqkwargs):
except AmsException as e:
raise e

def create_project_member(self, username, project=None, roles=None, email=None, **reqkwargs):

"""
This function creates a new user with a POST request under the given project
:param (str) project: the name of the project.If no
project is supplied, the declared global project will be used instead
:param (str) username: the name of the user
:param (str) email: the email of the user
:param (str[]) roles: project roles for the user
:return: (AmsUser) the assigned user object
"""

if roles is None or not isinstance(roles, list):
roles = []

if project is None:
project = self.project

user = AmsUser(
projects=[AmsUserProject(project=project, roles=roles)]
)

if email is not None:
user.email = email

try:
route = self.routes["project_create_member"]
url = route[1].format(self.endpoint, project, username)
method = getattr(self, 'do_{0}'.format(route[0]))
r = method(url, user.to_json(), "project_create_member", **reqkwargs)
return AmsUser().load_from_dict(r)
except AmsException as e:
raise e

def get_project_member(self, username, project=None, **reqkwargs):
"""
Retrieves the respective project member using the provided username with a GET request
Expand Down
27 changes: 17 additions & 10 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def setUp(self):
path="/v1/projects/test-proj/members/test-member",
method='GET')

create_member_urlmatch = dict(netloc="localhost",
path="/v1/projects/test-proj/members/test-member",
method='POST')

remove_member_urlmatch = dict(netloc="localhost",
path="/v1/projects/test-proj/members/test-member:remove",
method='POST')
Expand Down Expand Up @@ -94,21 +98,24 @@ def add_member_mock(url, request):
self.assertEqual(self.default_user.projects[0].subscriptions, added_member.projects[0].subscriptions)
self.assertEqual(self.default_user.projects[0].topics, added_member.projects[0].topics)

def testGetMember(self):
@urlmatch(**self.get_member_urlmatch)
def get_member_mock(url, request):
def testCreateMember(self):
@urlmatch(**self.create_member_urlmatch)
def create_member_mock(url, request):
self.assertEqual("/v1/projects/test-proj/members/test-member", url.path)
self.assertEqual("GET", request.method)
self.assertEqual("POST", request.method)
return response(200, self.member_json, None, None, 5, request)

# Execute ams client with mocked response
with HTTMock(get_member_mock):
added_member = self.ams.get_project_member(project="test-proj", username="test-member")
with HTTMock(create_member_mock):
created_member = self.ams.create_project_member(project="test-proj",
username="test-member",
email="[email protected]")
# test case where the global service project is used
added_member_with_service_project = self.ams.get_project_member(username="test-member")
added_members = [added_member, added_member_with_service_project]
created_member_with_service_project = self.ams.create_project_member(username="test-member",
email="[email protected]")
created_members = [created_member, created_member_with_service_project]

for added_member in added_members:
for added_member in created_members:
self.assertEqual(self.default_user.name, added_member.name)
self.assertEqual(self.default_user.email, added_member.email)
self.assertEqual(self.default_user.uuid, added_member.uuid)
Expand Down Expand Up @@ -150,7 +157,7 @@ def create_project_mock(url, request):
r = self.ams.create_project(name="test-project", description="nice project")
self.assertEqual("test-project", r["project"])
self.assertEqual("nice project", r["description"])

def testUpdateProject(self):
@urlmatch(**self.update_project_urlmatch)
def update_project_mock(url, request):
Expand Down

0 comments on commit 477f3eb

Please sign in to comment.