Skip to content

Commit

Permalink
[SWR] rename auth to user_auth for permissions (#421)
Browse files Browse the repository at this point in the history
[SWR] rename auth to user_auth for permissions

auth is reserved field in ansible-collections

Reviewed-by: Vladimir Vshivkov
Reviewed-by: Artem Lifshits
  • Loading branch information
anton-sidelnikov authored Mar 18, 2024
1 parent a725981 commit 51d3bf4
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/swr/create_organization_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{
"user_id": "5a23ecb3999b458d92d51d524bb7fb4c",
"user_name": "test",
"auth": 1
"user_auth": 1
}
],
}
Expand Down
2 changes: 1 addition & 1 deletion examples/swr/update_organization_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{
"user_id": "5a23ecb3999b458d92d51d524bb7fb4c",
"user_name": "test",
"auth": 3
"user_auth": 3
}
],
}
Expand Down
10 changes: 10 additions & 0 deletions otcextensions/sdk/swr/v2/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
from otcextensions.sdk.swr.v2 import domain as _domain


def update_permissions_attrs(attrs):
for permission in attrs.get('permissions', []):
permission['auth'] = permission.pop('user_auth', None)
return attrs


class Proxy(proxy.Proxy):
skip_discovery = True

Expand Down Expand Up @@ -112,6 +118,7 @@ def create_organization_permissions(self, **attrs):
:returns: The results of organization creation
:rtype: :class:`~otcextensions.sdk.swr.v2.organization.Permission`
"""
attrs = update_permissions_attrs(attrs)
return self._create(_organization.Permission, **attrs)

def organization_permissions(self, namespace, **query):
Expand Down Expand Up @@ -153,6 +160,7 @@ def update_organization_permissions(self, **attrs):
:rtype: :class:`~otcextensions.sdk.swr.v2.organization.Permission`
"""
attrs = update_permissions_attrs(attrs)
return self._update(_organization.Permission, **attrs)

def create_repository(self, **attrs):
Expand Down Expand Up @@ -235,6 +243,7 @@ def create_repository_permissions(self, **attrs):
:returns: The results of repository permission creation
:rtype: :class:`~otcextensions.sdk.swr.v2.repository.Permission`
"""
attrs = update_permissions_attrs(attrs)
return self._create(_repository.Permission, **attrs)

def repository_permissions(self, namespace, repository, **query):
Expand Down Expand Up @@ -281,6 +290,7 @@ def update_repository_permissions(self, **attrs):
:rtype: :class:`~otcextensions.sdk.swr.v2.repository.Permission`
"""
attrs = update_permissions_attrs(attrs)
return self._update(_repository.Permission, **attrs)

def create_domain(self, **attrs):
Expand Down
4 changes: 2 additions & 2 deletions otcextensions/sdk/swr/v2/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Organization(resource.Resource):
#: 3: Write
#: 1: Read
#: *Type:int*
auth = resource.Body('auth', type=int)
user_auth = resource.Body('auth', type=int)


class Auth(resource.Resource):
Expand All @@ -55,7 +55,7 @@ class Auth(resource.Resource):
#: 7: Manage
#: 3: Write
#: 1: Read
auth = resource.Body('auth', type=int)
user_auth = resource.Body('auth', type=int)


class Permission(_base.Resource):
Expand Down
10 changes: 5 additions & 5 deletions otcextensions/tests/functional/sdk/swr/v2/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):
{
"user_id": "5a23ecb3999b458d92d51d524bb7fb4b",
"user_name": "pgubina",
"auth": 1
"user_auth": 1
}
]
self.org_perm = self.client.create_organization_permissions(
Expand All @@ -47,12 +47,12 @@ def test_list_organizations(self):
def test_get_organization(self):
o = self.client.get_organization(self.org.namespace)
self.assertEqual(self.org.namespace, o.name)
self.assertEqual(7, o.auth)
self.assertEqual(7, o.user_auth)

def test_find_organization(self):
o = self.client.find_organization(self.org_name)
self.assertEqual(self.org.namespace, o.name)
self.assertEqual(7, o.auth)
self.assertEqual(7, o.user_auth)

def test_organization_permissions(self):
o = list(self.client.organization_permissions(self.org.namespace))
Expand All @@ -65,11 +65,11 @@ def test_update_organization_permissions(self):
{
"user_id": "5a23ecb3999b458d92d51d524bb7fb4b",
"user_name": "pgubina",
"auth": 3
"user_auth": 3
}
]
)
self.assertEqual(3, o.permissions[0].auth)
self.assertEqual(3, o.permissions[0].user_auth)

def test_delete_organization_permissions(self):
if os.getenv("OS_SWR_PERMISSIONS_RUN"):
Expand Down
6 changes: 3 additions & 3 deletions otcextensions/tests/functional/sdk/swr/v2/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setUp(self):
{
"user_id": "5a23ecb3999b458d92d51d524bb7fb4b",
"user_name": "pgubina",
"auth": 1
"user_auth": 1
}
]
self.repo_perm = self.client.create_repository_permissions(
Expand Down Expand Up @@ -102,8 +102,8 @@ def test_update_repository_permissions(self):
{
"user_id": "5a23ecb3999b458d92d51d524bb7fb4b",
"user_name": "pgubina",
"auth": 3
"user_auth": 3
}
]
)
self.assertEqual(3, o.permissions[0].auth)
self.assertEqual(3, o.permissions[0].user_auth)
10 changes: 5 additions & 5 deletions otcextensions/tests/unit/sdk/swr/v2/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"namespace": "test_create_org_v2",
"id": 21,
"creator_name": "anton",
"auth": 7,
"user_auth": 7,
}

EXAMPLE_PERMISSION = {
"permissions": [
{
"user_id": "5a23ecb3999b458d92d51d524bb7fb4b",
"user_name": "test",
"auth": 1
"user_auth": 1
}
],
"namespace": "test_create_org_v2"
Expand All @@ -50,7 +50,7 @@ def test_make_it(self):
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['namespace'], sot.namespace)
self.assertEqual(EXAMPLE['creator_name'], sot.creator_name)
self.assertEqual(EXAMPLE['auth'], sot.auth)
self.assertEqual(EXAMPLE['user_auth'], sot.user_auth)


class TestOrganizationPermissions(base.TestCase):
Expand All @@ -73,8 +73,8 @@ def test_make_it(self):
sot.permissions[0].user_id
)
self.assertEqual(
EXAMPLE_PERMISSION['permissions'][0]["auth"],
sot.permissions[0].auth
EXAMPLE_PERMISSION['permissions'][0]["user_auth"],
sot.permissions[0].user_auth
)
self.assertEqual(
EXAMPLE_PERMISSION['permissions'][0]["user_name"],
Expand Down
6 changes: 3 additions & 3 deletions otcextensions/tests/unit/sdk/swr/v2/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_organization_permission_update(self):
{
'user_id': '123',
'user_name': 'test',
'auth': 1
'user_auth': 1
}
],
},
Expand Down Expand Up @@ -147,7 +147,7 @@ def test_repository_permission_create(self):
{
'user_id': '123',
'user_name': 'test',
'auth': 1
'user_auth': 1
}
],
},
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_repository_permission_update(self):
{
'user_id': '123',
'user_name': 'test',
'auth': 1
'user_auth': 1
}
],
},
Expand Down
6 changes: 3 additions & 3 deletions otcextensions/tests/unit/sdk/swr/v2/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
'user_id': '5a23ecb3999b458d92d51d524bb7fb4b',
'user_name': 'test',
'auth': 1
'user_auth': 1
}
],
'namespace': 'test_create_org_v2',
Expand Down Expand Up @@ -75,8 +75,8 @@ def test_make_it(self):
sot.permissions[0].user_id
)
self.assertEqual(
EXAMPLE_PERMISSION['permissions'][0]['auth'],
sot.permissions[0].auth
EXAMPLE_PERMISSION['permissions'][0]['user_auth'],
sot.permissions[0].user_auth
)
self.assertEqual(
EXAMPLE_PERMISSION['permissions'][0]['user_name'],
Expand Down

0 comments on commit 51d3bf4

Please sign in to comment.