diff options
author | John L. Villalovos <john@sodarock.com> | 2021-05-25 17:35:17 -0700 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2021-05-26 06:42:19 -0700 |
commit | 502715d99e02105c39b2c5cf0e7457b3256eba0d (patch) | |
tree | e9064cda7c903159d8025def351475c10a707118 /tests/functional/api/test_snippets.py | |
parent | 9beff0d484b5fe86e2cd31f20cf00a309e09cf75 (diff) | |
download | gitlab-502715d99e02105c39b2c5cf0e7457b3256eba0d.tar.gz |
chore: rename 'tools/functional/' to 'tests/functional/'
Rename the 'tools/functional/' directory to 'tests/functional/'
This makes more sense as these are functional tests and not tools.
This was dicussed in:
https://github.com/python-gitlab/python-gitlab/discussions/1468
Diffstat (limited to 'tests/functional/api/test_snippets.py')
-rw-r--r-- | tests/functional/api/test_snippets.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/functional/api/test_snippets.py b/tests/functional/api/test_snippets.py new file mode 100644 index 0000000..936fbfb --- /dev/null +++ b/tests/functional/api/test_snippets.py @@ -0,0 +1,74 @@ +import gitlab + + +def test_snippets(gl): + snippets = gl.snippets.list(all=True) + assert len(snippets) == 0 + + snippet = gl.snippets.create( + {"title": "snippet1", "file_name": "snippet1.py", "content": "import gitlab"} + ) + snippet = gl.snippets.get(snippet.id) + snippet.title = "updated_title" + snippet.save() + + snippet = gl.snippets.get(snippet.id) + assert snippet.title == "updated_title" + + content = snippet.content() + assert content.decode() == "import gitlab" + assert snippet.user_agent_detail()["user_agent"] + + snippet.delete() + snippets = gl.snippets.list(all=True) + assert len(snippets) == 0 + + +def test_project_snippets(project): + project.snippets_enabled = True + project.save() + + snippet = project.snippets.create( + { + "title": "snip1", + "file_name": "foo.py", + "content": "initial content", + "visibility": gitlab.v4.objects.VISIBILITY_PRIVATE, + } + ) + + assert snippet.user_agent_detail()["user_agent"] + + +def test_project_snippet_discussion(project): + snippet = project.snippets.list()[0] + size = len(snippet.discussions.list()) + + discussion = snippet.discussions.create({"body": "Discussion body"}) + assert len(snippet.discussions.list()) == size + 1 + + note = discussion.notes.create({"body": "first note"}) + note_from_get = discussion.notes.get(note.id) + note_from_get.body = "updated body" + note_from_get.save() + + discussion = snippet.discussions.get(discussion.id) + assert discussion.attributes["notes"][-1]["body"] == "updated body" + + note_from_get.delete() + discussion = snippet.discussions.get(discussion.id) + assert len(discussion.attributes["notes"]) == 1 + + +def test_project_snippet_file(project): + snippet = project.snippets.list()[0] + snippet.file_name = "bar.py" + snippet.save() + + snippet = project.snippets.get(snippet.id) + assert snippet.content().decode() == "initial content" + assert snippet.file_name == "bar.py" + + size = len(project.snippets.list()) + snippet.delete() + assert len(project.snippets.list()) == (size - 1) |