Skip to content

Commit 33596f9

Browse files
authored
Document ability to set public on EnvironmentVariable API v3 (#12169)
I believe this was already possible -- just adding docs for it.
1 parent 6432e3a commit 33596f9

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

docs/user/api/v3.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,8 @@ Environment variable create
15081508

15091509
{
15101510
"name": "MYVAR",
1511-
"value": "My secret value"
1511+
"value": "My secret value",
1512+
"public": true
15121513
}
15131514

15141515
**Example response**:
@@ -1517,6 +1518,9 @@ Environment variable create
15171518

15181519
:statuscode 201: Environment variable created successfully
15191520

1521+
.. note::
1522+
1523+
- The `public` field is optional. If set to `true`, the environment variable will be exposed in PR builds. Defaults to `false`.
15201524

15211525
Environment variable delete
15221526
+++++++++++++++++++++++++++

readthedocs/api/v3/tests/test_environmentvariables.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,52 @@ def test_environment_variables_total_size_per_project(self):
208208
assert resp.json() == [
209209
"The total size of all environment variables in the project cannot exceed 256 KB."
210210
]
211+
212+
def test_create_environment_variable_with_public_flag(self):
213+
self.assertEqual(self.project.environmentvariable_set.count(), 1)
214+
data = {
215+
"name": "TEST_ENV_VAR",
216+
"value": "test_value",
217+
"public": True,
218+
}
219+
220+
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}")
221+
response = self.client.post(
222+
reverse(
223+
"projects-environmentvariables-list",
224+
kwargs={
225+
"parent_lookup_project__slug": self.project.slug,
226+
},
227+
),
228+
data,
229+
)
230+
self.assertEqual(response.status_code, 201)
231+
self.assertEqual(self.project.environmentvariable_set.count(), 2)
232+
233+
env_var = self.project.environmentvariable_set.get(name="TEST_ENV_VAR")
234+
self.assertEqual(env_var.value, "test_value")
235+
self.assertTrue(env_var.public)
236+
237+
def test_create_environment_variable_without_public_flag(self):
238+
self.assertEqual(self.project.environmentvariable_set.count(), 1)
239+
data = {
240+
"name": "TEST_ENV_VAR",
241+
"value": "test_value",
242+
}
243+
244+
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}")
245+
response = self.client.post(
246+
reverse(
247+
"projects-environmentvariables-list",
248+
kwargs={
249+
"parent_lookup_project__slug": self.project.slug,
250+
},
251+
),
252+
data,
253+
)
254+
self.assertEqual(response.status_code, 201)
255+
self.assertEqual(self.project.environmentvariable_set.count(), 2)
256+
257+
env_var = self.project.environmentvariable_set.get(name="TEST_ENV_VAR")
258+
self.assertEqual(env_var.value, "test_value")
259+
self.assertFalse(env_var.public)

0 commit comments

Comments
 (0)