1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
"""Common mocks for resources in gitlab.v4.objects"""
import re
import pytest
import responses
@pytest.fixture
def binary_content():
return b"binary content"
@pytest.fixture
def accepted_content():
return {"message": "202 Accepted"}
@pytest.fixture
def created_content():
return {"message": "201 Created"}
@pytest.fixture
def token_content():
return {
"user_id": 141,
"scopes": ["api"],
"name": "token",
"expires_at": "2021-01-31",
"id": 42,
"active": True,
"created_at": "2021-01-20T22:11:48.151Z",
"revoked": False,
"token": "s3cr3t",
}
@pytest.fixture
def resp_export(accepted_content, binary_content):
"""Common fixture for group and project exports."""
export_status_content = {
"id": 1,
"description": "Itaque perspiciatis minima aspernatur",
"name": "Gitlab Test",
"name_with_namespace": "Gitlab Org / Gitlab Test",
"path": "gitlab-test",
"path_with_namespace": "gitlab-org/gitlab-test",
"created_at": "2017-08-29T04:36:44.383Z",
"export_status": "finished",
"_links": {
"api_url": "https://gitlab.test/api/v4/projects/1/export/download",
"web_url": "https://gitlab.test/gitlab-test/download_export",
},
}
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
rsps.add(
method=responses.POST,
url=re.compile(r".*/api/v4/(groups|projects)/1/export"),
json=accepted_content,
content_type="application/json",
status=202,
)
rsps.add(
method=responses.GET,
url=re.compile(r".*/api/v4/(groups|projects)/1/export/download"),
body=binary_content,
content_type="application/octet-stream",
status=200,
)
# Currently only project export supports status checks
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/projects/1/export",
json=export_status_content,
content_type="application/json",
status=200,
)
yield rsps
|