gitlab: implement project export
This commit is contained in:
parent
c3bcdbebf9
commit
23f3969e75
|
@ -101,6 +101,27 @@ class GitLab(object):
|
|||
else:
|
||||
return info
|
||||
|
||||
def project_export(self, namespace, project, filename):
|
||||
url = f'{self.s.api}/projects/{namespace}%2F{project}/export'
|
||||
r = self.s.post(url)
|
||||
assert r.status_code == 202, f'{r.status_code} {r.text}'
|
||||
|
||||
while True:
|
||||
r = self.s.get(url)
|
||||
r.raise_for_status()
|
||||
status = r.json()["export_status"]
|
||||
logger.info(f"waiting {namespace}/{project} export: status is {status}")
|
||||
if status == "finished":
|
||||
break
|
||||
time.sleep(1)
|
||||
logger.info(f"download {namespace}/{project} into {filename}")
|
||||
with self.s.get(f'{url}/download', stream=True) as r:
|
||||
r.raise_for_status()
|
||||
with open(filename, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
return True
|
||||
|
||||
def create_api_application(self, domain):
|
||||
callbacks = [
|
||||
f'https://api.{domain}/accounts/gitlab/login/callback/',
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import os
|
||||
import pytest
|
||||
import gzip
|
||||
|
||||
from fedeproxy.common.gitlab import GitLab
|
||||
|
||||
|
||||
@pytest.mark.gitlab
|
||||
def test_create_project(tmpdir):
|
||||
def test_project_create():
|
||||
ip = os.environ.get('FEDEPROXY_IP', '0.0.0.0')
|
||||
gitlab = GitLab(f'http://{ip}:8181')
|
||||
gitlab.login('root', 'Wrobyak4')
|
||||
|
@ -13,3 +14,15 @@ def test_create_project(tmpdir):
|
|||
assert gitlab.project_get('root', 'testproject') is None
|
||||
p = gitlab.project_create('root', 'testproject')
|
||||
assert p['id'] == gitlab.project_create('root', 'testproject')['id']
|
||||
|
||||
|
||||
@pytest.mark.gitlab
|
||||
def test_project_export(tmpdir):
|
||||
ip = os.environ.get('FEDEPROXY_IP', '0.0.0.0')
|
||||
gitlab = GitLab(f'http://{ip}:8181')
|
||||
gitlab.login('root', 'Wrobyak4')
|
||||
gitlab.project_delete('root', 'testproject')
|
||||
gitlab.project_create('root', 'testproject')
|
||||
exported = f'{tmpdir}/testproject.zip'
|
||||
gitlab.project_export('root', 'testproject', exported)
|
||||
assert gzip.open(exported)
|
||||
|
|
Loading…
Reference in New Issue