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/test_deployments.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/test_deployments.py')
-rw-r--r-- | gitlab/tests/objects/test_deployments.py | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/gitlab/tests/objects/test_deployments.py b/gitlab/tests/objects/test_deployments.py index 098251a..3cde8fe 100644 --- a/gitlab/tests/objects/test_deployments.py +++ b/gitlab/tests/objects/test_deployments.py @@ -1,39 +1,37 @@ """ GitLab API: https://docs.gitlab.com/ce/api/deployments.html """ +import pytest +import responses -import json -from httmock import response, urlmatch, with_httmock +@pytest.fixture +def resp_deployment(): + content = {"id": 42, "status": "success", "ref": "master"} -from .mocks import headers + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.POST, + url="http://localhost/api/v4/projects/1/deployments", + json=content, + content_type="application/json", + status=200, + ) -content = '{"id": 42, "status": "success", "ref": "master"}' -json_content = json.loads(content) + updated_content = dict(content) + updated_content["status"] = "failed" + rsps.add( + method=responses.PUT, + url="http://localhost/api/v4/projects/1/deployments/42", + json=updated_content, + content_type="application/json", + status=200, + ) + yield rsps -@urlmatch( - scheme="http", - netloc="localhost", - path="/api/v4/projects/1/deployments", - method="post", -) -def resp_deployment_create(url, request): - return response(200, json_content, headers, None, 5, request) - -@urlmatch( - scheme="http", - netloc="localhost", - path="/api/v4/projects/1/deployments/42", - method="put", -) -def resp_deployment_update(url, request): - return response(200, json_content, headers, None, 5, request) - - -@with_httmock(resp_deployment_create, resp_deployment_update) -def test_deployment(project): +def test_deployment(project, resp_deployment): deployment = project.deployments.create( { "environment": "Test", @@ -47,7 +45,6 @@ def test_deployment(project): assert deployment.status == "success" assert deployment.ref == "master" - json_content["status"] = "failed" deployment.status = "failed" deployment.save() assert deployment.status == "failed" |