diff options
| author | Oleksii Shkurupii <Oleksii.Shkurupii@playtech.com> | 2020-08-27 18:07:54 +0300 |
|---|---|---|
| committer | Oleksii Shkurupii <Oleksii.Shkurupii@playtech.com> | 2020-08-27 18:07:54 +0300 |
| commit | fa899d7a6e76acbe392f3debb5fd61d71bd88ed2 (patch) | |
| tree | af915190af31ded29c6545c67ac7c9cda294e195 /gitlab/tests/objects/test_snippets.py | |
| parent | 88f8cc78f97156d5888a9600bdb8721720563120 (diff) | |
| parent | a038e9567fd16259e3ed360ab0defd779e9c3901 (diff) | |
| download | gitlab-fa899d7a6e76acbe392f3debb5fd61d71bd88ed2.tar.gz | |
Merge branch 'master' into issue-1154
Diffstat (limited to 'gitlab/tests/objects/test_snippets.py')
| -rw-r--r-- | gitlab/tests/objects/test_snippets.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_snippets.py b/gitlab/tests/objects/test_snippets.py new file mode 100644 index 0000000..7e8afc2 --- /dev/null +++ b/gitlab/tests/objects/test_snippets.py @@ -0,0 +1,90 @@ +""" +GitLab API: https://docs.gitlab.com/ce/api/project_snippets.html + https://docs.gitlab.com/ee/api/snippets.html (todo) +""" + +import pytest +import responses + + +title = "Example Snippet Title" +visibility = "private" +new_title = "new-title" + + +@pytest.fixture +def resp_snippet(): + content = { + "title": title, + "description": "More verbose snippet description", + "file_name": "example.txt", + "content": "source code with multiple lines", + "visibility": visibility, + } + + with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/snippets", + json=[content], + content_type="application/json", + status=200, + ) + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/snippets/1", + json=content, + content_type="application/json", + status=200, + ) + rsps.add( + method=responses.POST, + url="http://localhost/api/v4/projects/1/snippets", + json=content, + content_type="application/json", + status=200, + ) + + updated_content = dict(content) + updated_content["title"] = new_title + updated_content["visibility"] = visibility + + rsps.add( + method=responses.PUT, + url="http://localhost/api/v4/projects/1/snippets", + json=updated_content, + content_type="application/json", + status=200, + ) + yield rsps + + +def test_list_project_snippets(project, resp_snippet): + snippets = project.snippets.list() + assert len(snippets) == 1 + assert snippets[0].title == title + assert snippets[0].visibility == visibility + + +def test_get_project_snippet(project, resp_snippet): + snippet = project.snippets.get(1) + assert snippet.title == title + assert snippet.visibility == visibility + + +def test_create_update_project_snippets(project, resp_snippet): + snippet = project.snippets.create( + { + "title": title, + "file_name": title, + "content": title, + "visibility": visibility, + } + ) + assert snippet.title == title + assert snippet.visibility == visibility + + snippet.title = new_title + snippet.save() + assert snippet.title == new_title + assert snippet.visibility == visibility |
