-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_rtd.py
208 lines (177 loc) · 6.31 KB
/
test_rtd.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# SPDX-License-Identifier: EPL-1.0
##############################################################################
# Copyright (c) 2018 The Linux Foundation and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
##############################################################################
"""Test rtd command."""
import json
import os
import pytest
import responses
import lftools.api.endpoints.readthedocs as client
creds = {"authtype": "token", "endpoint": "https://readthedocs.org/api/v3/", "token": "xyz"}
rtd = client.ReadTheDocs(creds=creds)
FIXTURE_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"fixtures",
)
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, "rtd"),
)
@responses.activate
def test_project_list(datafiles):
os.chdir(str(datafiles))
json_file = open("project_list.json", "r")
json_data = json.loads(json_file.read())
responses.add(responses.GET, url="https://readthedocs.org/api/v3/projects/", json=json_data, status=200)
assert "TestProject1" in rtd.project_list()
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, "rtd"),
)
@responses.activate
def test_project_details(datafiles):
os.chdir(str(datafiles))
json_file = open("project_details.json", "r")
json_data = json.loads(json_file.read())
responses.add(
responses.GET, url="https://readthedocs.org/api/v3/projects/TestProject1/", json=json_data, status=200
)
assert "slug" in rtd.project_details("TestProject1")
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, "rtd"),
)
@responses.activate
def test_project_version_list(datafiles):
os.chdir(str(datafiles))
json_file = open("project_version_list.json", "r")
json_data = json.loads(json_file.read())
responses.add(
responses.GET,
url="https://readthedocs.org/api/v3/projects/TestProject1/versions/?active=True", # noqa
json=json_data,
status=200,
match_querystring=True,
)
assert "test-trigger6" in rtd.project_version_list("TestProject1")
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, "rtd"),
)
@responses.activate
def test_project_version_details(datafiles):
os.chdir(str(datafiles))
json_file = open("project_version_details.json", "r")
json_data = json.loads(json_file.read())
responses.add(
responses.GET,
url="https://readthedocs.org/api/v3/projects/TestProject1/versions/latest/", # noqa
json=json_data,
status=200,
)
assert "slug" in rtd.project_version_details("TestProject1", "latest")
@responses.activate
def test_project_version_update():
data = {"active": True}
responses.add(
responses.PATCH,
url="https://readthedocs.org/api/v3/projects/TestProject1/versions/latest/", # noqa
json=data,
status=204,
)
assert rtd.project_version_update("TestProject1", "latest", "True")
@responses.activate
def test_project_create():
data = {
"name": "TestProject1",
"repository": {"url": "https://repository_url", "type": "my_repo_type"},
"homepage": "https://homepageurl",
"programming_language": "py",
"language": "en",
}
responses.add(responses.POST, url="https://readthedocs.org/api/v3/projects/", json=data, status=201)
assert rtd.project_create(
"TestProject1", "https://repository_url", "my_repo_type", "https://homepageurl", "py", "en"
)
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, "rtd"),
)
@responses.activate
def test_project_build_list(datafiles):
os.chdir(str(datafiles))
json_file = open("project_build_list.json", "r")
json_data = json.loads(json_file.read())
responses.add(
responses.GET,
url="https://readthedocs.org/api/v3/projects/testproject1/builds/?running=True", # noqa
json=json_data,
status=200,
match_querystring=True,
)
assert "success" in rtd.project_build_list("testproject1")
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, "rtd"),
)
@responses.activate
def test_project_build_details(datafiles):
os.chdir(str(datafiles))
json_file = open("project_build_details.json", "r")
json_data = json.loads(json_file.read())
responses.add(
responses.GET,
url="https://readthedocs.org/api/v3/projects/testproject1/builds/9584913/", # noqa
json=json_data,
status=200,
)
assert "id" in rtd.project_build_details("testproject1", 9584913)
@responses.activate
def test_project_build_trigger():
data = {"project": "testproject1", "version": "latest"}
responses.add(
responses.POST,
url="https://readthedocs.org/api/v3/projects/testproject1/versions/latest/builds/", # noqa
json=data,
status=201,
)
assert rtd.project_build_trigger("testproject1", "latest")
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, "rtd"),
)
@responses.activate
def test_subproject_list(datafiles):
os.chdir(str(datafiles))
json_file = open("subproject_list.json", "r")
json_data = json.loads(json_file.read())
responses.add(
responses.GET,
url="https://readthedocs.org/api/v3/projects/TestProject1/subprojects/?limit=999", # noqa
json=json_data,
status=200,
match_querystring=True,
)
assert "testproject2" in rtd.subproject_list("TestProject1")
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, "rtd"),
)
@responses.activate
def test_subproject_details(datafiles):
os.chdir(str(datafiles))
json_file = open("subproject_details.json", "r")
json_data = json.loads(json_file.read())
responses.add(
responses.GET,
url="https://readthedocs.org/api/v3/projects/TestProject1/subprojects/testproject2/", # NOQA
json=json_data,
status=200,
)
assert "child" in rtd.subproject_details("TestProject1", "testproject2")
@responses.activate
def test_subproject_create():
responses.add(
responses.POST, url="https://readthedocs.org/api/v3/projects/TestProject1/subprojects/", status=201 # NOQA
)
assert rtd.subproject_create("TestProject1", "testproject2")
def test_subproject_delete():
assert "untested because responses doesn't have DELETE support"