diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-23 21:16:20 +0200 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-23 21:19:47 +0200 |
commit | 204782a117f77f367dee87aa2c70822587829147 (patch) | |
tree | b7d68fc7e4833139cc8c1d2360059b90ee43b3de /gitlab/tests/objects/conftest.py | |
parent | 76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7 (diff) | |
download | gitlab-refactor/split-unit-tests.tar.gz |
refactor: rewrite unit tests for objects with responsesrefactor/split-unit-tests
Diffstat (limited to 'gitlab/tests/objects/conftest.py')
-rw-r--r-- | gitlab/tests/objects/conftest.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gitlab/tests/objects/conftest.py b/gitlab/tests/objects/conftest.py new file mode 100644 index 0000000..76f76d1 --- /dev/null +++ b/gitlab/tests/objects/conftest.py @@ -0,0 +1,65 @@ +"""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 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 |