|
1 |
| -from .mixins import APIEndpointMixin |
| 1 | +import django_dynamic_fixture as fixture |
2 | 2 | from django.urls import reverse
|
| 3 | +from django_dynamic_fixture import get |
3 | 4 |
|
4 |
| -import django_dynamic_fixture as fixture |
5 | 5 | from readthedocs.projects.models import EnvironmentVariable
|
| 6 | +from readthedocs.projects.validators import MAX_SIZE_ENV_VARS_PER_PROJECT |
| 7 | + |
| 8 | +from .mixins import APIEndpointMixin |
6 | 9 |
|
7 | 10 |
|
8 | 11 | class EnvironmentVariablessEndpointTests(APIEndpointMixin):
|
@@ -154,3 +157,54 @@ def test_projects_environmentvariables_detail_delete(self):
|
154 | 157 | response = self.client.delete(url)
|
155 | 158 | self.assertEqual(response.status_code, 204)
|
156 | 159 | self.assertEqual(self.project.environmentvariable_set.count(), 0)
|
| 160 | + |
| 161 | + def test_create_large_environment_variable(self): |
| 162 | + url = reverse( |
| 163 | + "projects-environmentvariables-list", |
| 164 | + kwargs={ |
| 165 | + "parent_lookup_project__slug": self.project.slug, |
| 166 | + }, |
| 167 | + ) |
| 168 | + self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}") |
| 169 | + resp = self.client.post( |
| 170 | + url, |
| 171 | + data={"name": "NEWENVVAR", "value": "a" * (48000 + 1), "public": True}, |
| 172 | + ) |
| 173 | + assert resp.status_code == 400 |
| 174 | + assert resp.data == { |
| 175 | + "value": ["Ensure this field has no more than 48000 characters."] |
| 176 | + } |
| 177 | + |
| 178 | + def test_environment_variables_total_size_per_project(self): |
| 179 | + size = 2000 |
| 180 | + for i in range((MAX_SIZE_ENV_VARS_PER_PROJECT - size) // size): |
| 181 | + get( |
| 182 | + EnvironmentVariable, |
| 183 | + project=self.project, |
| 184 | + name=f"ENVVAR{i}", |
| 185 | + value="a" * size, |
| 186 | + public=False, |
| 187 | + ) |
| 188 | + |
| 189 | + url = reverse( |
| 190 | + "projects-environmentvariables-list", |
| 191 | + kwargs={ |
| 192 | + "parent_lookup_project__slug": self.project.slug, |
| 193 | + }, |
| 194 | + ) |
| 195 | + self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}") |
| 196 | + |
| 197 | + resp = self.client.post( |
| 198 | + url, |
| 199 | + data={"name": "A", "value": "a" * (size // 2), "public": True}, |
| 200 | + ) |
| 201 | + assert resp.status_code == 201 |
| 202 | + |
| 203 | + resp = self.client.post( |
| 204 | + url, |
| 205 | + data={"name": "B", "value": "a" * size, "public": True}, |
| 206 | + ) |
| 207 | + assert resp.status_code == 400 |
| 208 | + assert resp.json() == [ |
| 209 | + "The total size of all environment variables in the project cannot exceed 256 KB." |
| 210 | + ] |
0 commit comments