Skip to content

Commit

Permalink
Merge pull request #27 from galaxy-genome-annotation/groups_tests
Browse files Browse the repository at this point in the history
Groups fix + tests
  • Loading branch information
abretaud authored Apr 23, 2020
2 parents 065c398 + c3deb21 commit 1aaad04
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ Or with the Arrow client:
History
-------

- 4.2.1
- Fix getting groups by name
- Add tests for group api
- 4.2
- Improve user update method
- Add tests for user api
Expand Down
11 changes: 8 additions & 3 deletions apollo/groups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ def get_groups(self, name=None):
:return: list of a dictionaries containing group information
"""
payload = {}
if name:
payload['name'] = name

res = self.post('loadGroups', payload)
return [_fix_group(group) for group in res]

groups = []
if name:
groups = [_fix_group(group) for group in res if group['name'] == name]
else:
groups = [_fix_group(group) for group in res]

return groups

def update_group(self, group_id, new_name):
"""
Expand Down
2 changes: 1 addition & 1 deletion arrow/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '4.2'
__version__ = '4.2.1'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name="apollo",
version='4.2',
version='4.2.1',
description="Apollo API library",
long_description=readme,
author="Helena Rasche;Anthony Bretaudeau",
Expand Down
29 changes: 29 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,32 @@ def waitUserCreated(self, user_id):
tries += 1

return user_info

def waitGroupDeleted(self, group_id):
"""
Wait for an group to be really deleted from Apollo
"""

group_info = wa.groups.get_groups(group_id)
tries = 1
while len(group_info) and tries < 10:
time.sleep(1)
group_info = wa.groups.get_groups(group_id)
tries += 1

return group_info

def waitGroupCreated(self, group_id):
"""
Wait for an group to be really created from Apollo
"""

time.sleep(1)
group_info = wa.groups.get_groups(group_id)
tries = 1
while len(group_info) < 1 and tries < 10:
time.sleep(1)
group_info = wa.groups.get_groups(group_id)
tries += 1

return group_info
241 changes: 241 additions & 0 deletions test/group_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
import time

from . import ApolloTestCase, wa


class GroupTest(ApolloTestCase):

def test_get_groups(self):

groups = wa.groups.get_groups()

# We at least have the 2 from bootstrap + the one from setup
assert len(groups) >= 3

first_group = groups[0]

assert 'public' in first_group
assert 'numberOfUsers' in first_group
assert 'name' in first_group
assert 'admin' in first_group
assert 'id' in first_group
assert 'organismPermissions' in first_group
assert 'users' in first_group

def test_show_group(self):

groups = wa.groups.get_groups()

group_id = groups[0]['id']

group_info = wa.groups.show_group(group_id)

assert group_info == groups[0]

def test_get_group_by_name(self):

all_groups = wa.groups.get_groups()

good_group = None
for g in all_groups:
if g['name'] == 'temp_group':
good_group = g

assert good_group is not None

group_by_name = wa.groups.get_groups(name='temp_group')

assert len(group_by_name) == 1
assert good_group == group_by_name[0]

def test_get_group_creator(self):

creator = wa.groups.get_group_creator('temp_group')

user_info = wa.users.show_user(creator)

assert user_info['username'] == "[email protected]"

def test_get_group_admin(self):

creator = wa.groups.get_group_admin('temp_group')

user_info = wa.users.show_user(creator)

assert user_info['username'] == "[email protected]"

def test_create_group(self):

res = wa.groups.create_group("trash_group")
self.waitGroupCreated('trash_group')

res = wa.groups.get_groups('trash_group')

assert len(res) == 1

assert res[0]['name'] == 'trash_group'
assert res[0]['admin'][0]['email'] == '[email protected]'

def test_delete_group(self):

res = wa.groups.create_group("trash_group")
self.waitGroupCreated('trash_group')

res = wa.groups.get_groups('trash_group')

assert len(res) == 1

wa.groups.delete_group('trash_group')
self.waitGroupDeleted('trash_group')

groups = wa.groups.get_groups()

for group in groups:
assert group['name'] != 'trash_group'

def test_update_group(self):

res = wa.groups.create_group("trash_group")
self.waitGroupCreated('trash_group')

res = wa.groups.get_groups('trash_group')

assert len(res) == 1

wa.groups.update_group(res[0]['id'], 'trash_group_updated')

res = wa.groups.get_groups('trash_group')

assert len(res) == 0

res = wa.groups.get_groups('trash_group_updated')

assert len(res) == 1

def test_update_group_admin(self):

res = wa.groups.create_group("trash_group")
self.waitGroupCreated('trash_group')

res = wa.groups.get_groups('trash_group')

assert len(res) == 1

wa.groups.update_group_admin(res[0]['id'], ['[email protected]'])

time.sleep(1)

res = wa.groups.get_groups('trash_group')

assert len(res) == 1
assert res[0]['admin'][0]['email'] == '[email protected]'

def test_update_membership_username(self):

res = wa.groups.create_group("trash_group")
self.waitGroupCreated('trash_group')

res = wa.groups.get_groups('trash_group')

assert len(res) == 1

wa.groups.update_membership(res[0]['id'], ['[email protected]'])

time.sleep(1)

res = wa.groups.get_groups('trash_group')

assert len(res) == 1

assert res[0]['users'][0]['email'] == '[email protected]'

def test_update_membership_dict(self):

res = wa.groups.create_group("trash_group")
self.waitGroupCreated('trash_group')

res = wa.groups.get_groups('trash_group')
assert len(res) == 1

wa.groups.update_membership(memberships=[{'groupId': res[0]['id'], 'users': ['[email protected]']}])

time.sleep(1)

res = wa.groups.get_groups('trash_group')

assert len(res) == 1

assert res[0]['users'][0]['email'] == '[email protected]'

def test_update_permissions(self):

res = wa.groups.create_group("trash_group")
self.waitGroupCreated('trash_group')

res = wa.groups.get_groups('trash_group')
assert len(res) == 1

res = wa.groups.get_organism_permissions('trash_group')

assert res == []

res = wa.groups.update_organism_permissions('trash_group', 'test_organism', True, False, True, False)

assert res['class'] == 'org.bbop.apollo.GroupOrganismPermission'
assert res['permissions'] == ['ADMINISTRATE', 'READ']

time.sleep(1)

res = wa.groups.get_organism_permissions('trash_group')

assert res[0]['class'] == 'org.bbop.apollo.GroupOrganismPermission'
assert res[0]['permissions'] == ['ADMINISTRATE', 'READ']

def setUp(self):
# Make sure the group is not already there
temp_group_info = wa.groups.get_groups('temp_group')
if temp_group_info and 'name' in temp_group_info[0]:
wa.groups.delete_group('temp_group')
self.waitGroupDeleted('temp_group')

temp_group_info = wa.groups.get_groups('trash_group')
if temp_group_info and 'name' in temp_group_info[0]:
wa.groups.delete_group('trash_group')
self.waitGroupDeleted('trash_group')

temp_group_info = wa.groups.get_groups('trash_group_updated')
if temp_group_info and 'name' in temp_group_info[0]:
wa.groups.delete_group('trash_group_updated')
self.waitGroupDeleted('trash_group_updated')

temp_user_info = wa.users.show_user('[email protected]')
if 'username' in temp_user_info:
wa.users.delete_user(temp_user_info['username'])
self.waitUserDeleted(temp_user_info['userId'])

wa.groups.create_group("temp_group")
self.waitGroupCreated('temp_group')

user_info = wa.users.create_user("[email protected]", 'Temp', 'orary', 'coolpassword', role="user")
self.waitUserCreated(user_info['userId'])

def tearDown(self):
temp_group_info = wa.groups.get_groups('temp_group')
if temp_group_info and 'name' in temp_group_info[0]:
wa.groups.delete_group('temp_group')
self.waitGroupDeleted('temp_group')

temp_group_info = wa.groups.get_groups('trash_group')
if temp_group_info and 'name' in temp_group_info[0]:
wa.groups.delete_group('trash_group')
self.waitGroupDeleted('trash_group')

temp_group_info = wa.groups.get_groups('trash_group_updated')
if temp_group_info and 'name' in temp_group_info[0]:
wa.groups.delete_group('trash_group_updated')
self.waitGroupDeleted('trash_group_updated')

temp_user_info = wa.users.show_user('[email protected]')
if 'username' in temp_user_info:
wa.users.delete_user(temp_user_info['username'])
self.waitUserDeleted(temp_user_info['userId'])

0 comments on commit 1aaad04

Please sign in to comment.