forked from python-gitlab/python-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_projects.py
More file actions
107 lines (97 loc) · 3.48 KB
/
Copy pathtest_projects.py
File metadata and controls
107 lines (97 loc) · 3.48 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import pytest
import respx
from gitlab import AsyncGitlab
from httpx import codes
class TestProjectSnippets:
@respx.mock
@pytest.mark.asyncio
async def test_list_project_snippets(self, gl, gl_get_value):
title = "Example Snippet Title"
visibility = "private"
request = respx.get(
"http://localhost/api/v4/projects/1/snippets",
content=[
{
"title": title,
"description": "More verbose snippet description",
"file_name": "example.txt",
"content": "source code with multiple lines",
"visibility": visibility,
}
],
status_code=codes.OK,
)
project = gl.projects.get(1, lazy=True)
snippets = project.snippets.list()
snippets = await gl_get_value(snippets)
assert len(snippets) == 1
assert snippets[0].title == title
assert snippets[0].visibility == visibility
@respx.mock
@pytest.mark.asyncio
async def test_get_project_snippet(self, gl, gl_get_value):
title = "Example Snippet Title"
visibility = "private"
request = respx.get(
"http://localhost/api/v4/projects/1/snippets/1",
content={
"title": title,
"description": "More verbose snippet description",
"file_name": "example.txt",
"content": "source code with multiple lines",
"visibility": visibility,
},
status_code=codes.OK,
)
project = gl.projects.get(1, lazy=True)
snippet = project.snippets.get(1)
snippet = await gl_get_value(snippet)
assert snippet.title == title
assert snippet.visibility == visibility
@respx.mock
@pytest.mark.asyncio
async def test_create_update_project_snippets(self, gl, gl_get_value, is_gl_sync):
title = "Example Snippet Title"
new_title = "new-title"
visibility = "private"
request_update = respx.put(
"http://localhost/api/v4/projects/1/snippets",
content={
"title": new_title,
"description": "More verbose snippet description",
"file_name": "example.txt",
"content": "source code with multiple lines",
"visibility": visibility,
},
status_code=codes.OK,
)
request_create = respx.post(
"http://localhost/api/v4/projects/1/snippets",
content={
"title": title,
"description": "More verbose snippet description",
"file_name": "example.txt",
"content": "source code with multiple lines",
"visibility": visibility,
},
status_code=codes.OK,
)
project = gl.projects.get(1, lazy=True)
snippet = project.snippets.create(
{
"title": title,
"file_name": title,
"content": title,
"visibility": visibility,
}
)
snippet = await gl_get_value(snippet)
assert snippet.title == title
assert snippet.visibility == visibility
snippet.title = new_title
if is_gl_sync:
snippet.save()
else:
await snippet.save()
assert snippet.title == new_title
assert snippet.visibility == visibility