1
0
mirror of https://lab.enough.community/fedeproxy/server synced 2025-01-15 18:32:47 +01:00

gitlab: create/get/delete user

This commit is contained in:
Loic Dachary 2021-01-28 21:07:07 +01:00
parent 651e6e7af3
commit 9a855645e4
No known key found for this signature in database
GPG Key ID: 992D23B392F9E4F2
2 changed files with 51 additions and 0 deletions

View File

@ -59,6 +59,41 @@ class GitLab(object):
user = r.json()
return self.is_member_of_group(group, user['username'])
def user_delete(self, user):
info = self.user_get(user)
if info is None:
return False
while True:
r = self.s.delete(f'{self.s.api}/users/{info["id"]}')
if r.status_code == 404:
break
r.raise_for_status()
return True
def user_get(self, user):
r = self.s.get(f'{self.s.api}/users?username={user}')
r.raise_for_status()
found = r.json()
if found:
return found[0]
else:
return None
def user_create(self, user, email):
info = self.user_get(user)
if info is None:
r = self.s.post(f'{self.s.api}/users', data={
"name": user,
"username": user,
"email": email,
"password": "something",
"force_random_password": True,
})
logger.debug(r.text)
r.raise_for_status()
info = r.json()
return info
def project_delete(self, namespace, project):
info = self.project_get(namespace, project)
if info is None:

View File

@ -14,6 +14,22 @@ def test_project_create():
assert gitlab.project_get('root', 'testproject') is None
p = gitlab.project_create('root', 'testproject')
assert p['id'] == gitlab.project_create('root', 'testproject')['id']
assert gitlab.project_delete('root', 'testproject') is True
assert gitlab.project_delete('root', 'testproject') is False
@pytest.mark.gitlab
def test_user_create():
ip = os.environ.get('FEDEPROXY_IP', '0.0.0.0')
gitlab = GitLab(f'http://{ip}:8181')
gitlab.login('root', 'Wrobyak4')
user = 'testuser1'
email = 'testuser1@example.com'
gitlab.user_delete(user)
u = gitlab.user_create(user, email)
assert u['id'] == gitlab.user_create(user, email)['id']
assert gitlab.user_delete(user) is True
assert gitlab.user_delete(user) is False
@pytest.mark.gitlab