|
10 | 10 | from django.urls import reverse
|
11 | 11 |
|
12 | 12 | from readthedocs.builds.constants import LATEST
|
13 |
| -from readthedocs.builds.models import Build |
14 |
| -from readthedocs.projects.constants import PUBLIC |
15 |
| -from readthedocs.projects.models import Project |
| 13 | +from readthedocs.builds.models import Build, Version |
| 14 | +from readthedocs.projects.constants import PRIVATE, PUBLIC |
| 15 | +from readthedocs.projects.models import Feature, Project |
16 | 16 |
|
17 | 17 |
|
18 | 18 | @override_settings(
|
@@ -123,3 +123,306 @@ def test_get_config_unsupported_version(self):
|
123 | 123 | )
|
124 | 124 | assert r.status_code == 400
|
125 | 125 | assert r.json() == self._get_response_dict("v2")
|
| 126 | + |
| 127 | + def test_disabled_addons_via_feature_flags(self): |
| 128 | + fixture.get( |
| 129 | + Feature, |
| 130 | + projects=[self.project], |
| 131 | + feature_id=Feature.ADDONS_ANALYTICS_DISABLED, |
| 132 | + ) |
| 133 | + fixture.get( |
| 134 | + Feature, |
| 135 | + projects=[self.project], |
| 136 | + feature_id=Feature.ADDONS_EXTERNAL_VERSION_WARNING_DISABLED, |
| 137 | + ) |
| 138 | + fixture.get( |
| 139 | + Feature, |
| 140 | + projects=[self.project], |
| 141 | + feature_id=Feature.ADDONS_NON_LATEST_VERSION_WARNING_DISABLED, |
| 142 | + ) |
| 143 | + fixture.get( |
| 144 | + Feature, |
| 145 | + projects=[self.project], |
| 146 | + feature_id=Feature.ADDONS_DOC_DIFF_DISABLED, |
| 147 | + ) |
| 148 | + fixture.get( |
| 149 | + Feature, |
| 150 | + projects=[self.project], |
| 151 | + feature_id=Feature.ADDONS_FLYOUT_DISABLED, |
| 152 | + ) |
| 153 | + fixture.get( |
| 154 | + Feature, |
| 155 | + projects=[self.project], |
| 156 | + feature_id=Feature.ADDONS_SEARCH_DISABLED, |
| 157 | + ) |
| 158 | + fixture.get( |
| 159 | + Feature, |
| 160 | + projects=[self.project], |
| 161 | + feature_id=Feature.ADDONS_HOTKEYS_DISABLED, |
| 162 | + ) |
| 163 | + |
| 164 | + r = self.client.get( |
| 165 | + reverse("proxito_readthedocs_docs_addons"), |
| 166 | + { |
| 167 | + "url": "https://project.dev.readthedocs.io/en/latest/", |
| 168 | + "client-version": "0.6.0", |
| 169 | + "api-version": "0.1.0", |
| 170 | + }, |
| 171 | + secure=True, |
| 172 | + headers={ |
| 173 | + "host": "project.dev.readthedocs.io", |
| 174 | + }, |
| 175 | + ) |
| 176 | + assert r.status_code == 200 |
| 177 | + assert r.json()["addons"]["analytics"]["enabled"] is False |
| 178 | + assert r.json()["addons"]["external_version_warning"]["enabled"] is False |
| 179 | + assert r.json()["addons"]["non_latest_version_warning"]["enabled"] is False |
| 180 | + assert r.json()["addons"]["doc_diff"]["enabled"] is False |
| 181 | + assert r.json()["addons"]["flyout"]["enabled"] is False |
| 182 | + assert r.json()["addons"]["search"]["enabled"] is False |
| 183 | + assert r.json()["addons"]["hotkeys"]["enabled"] is False |
| 184 | + |
| 185 | + def test_non_latest_version_warning_versions(self): |
| 186 | + fixture.get( |
| 187 | + Version, |
| 188 | + project=self.project, |
| 189 | + privacy_level=PRIVATE, |
| 190 | + slug="private", |
| 191 | + verbose_name="private", |
| 192 | + built=True, |
| 193 | + active=True, |
| 194 | + ) |
| 195 | + fixture.get( |
| 196 | + Version, |
| 197 | + project=self.project, |
| 198 | + privacy_level=PUBLIC, |
| 199 | + slug="public-built", |
| 200 | + verbose_name="public-built", |
| 201 | + built=True, |
| 202 | + active=True, |
| 203 | + ) |
| 204 | + fixture.get( |
| 205 | + Version, |
| 206 | + project=self.project, |
| 207 | + privacy_level=PUBLIC, |
| 208 | + slug="public-not-built", |
| 209 | + verbose_name="public-not-built", |
| 210 | + built=False, |
| 211 | + active=True, |
| 212 | + ) |
| 213 | + |
| 214 | + r = self.client.get( |
| 215 | + reverse("proxito_readthedocs_docs_addons"), |
| 216 | + { |
| 217 | + "url": "https://project.dev.readthedocs.io/en/latest/", |
| 218 | + "client-version": "0.6.0", |
| 219 | + "api-version": "0.1.0", |
| 220 | + }, |
| 221 | + secure=True, |
| 222 | + headers={ |
| 223 | + "host": "project.dev.readthedocs.io", |
| 224 | + }, |
| 225 | + ) |
| 226 | + assert r.status_code == 200 |
| 227 | + |
| 228 | + expected = ["latest", "public-built"] |
| 229 | + assert r.json()["addons"]["non_latest_version_warning"]["versions"] == expected |
| 230 | + |
| 231 | + def test_flyout_versions(self): |
| 232 | + fixture.get( |
| 233 | + Version, |
| 234 | + project=self.project, |
| 235 | + privacy_level=PRIVATE, |
| 236 | + slug="private", |
| 237 | + verbose_name="private", |
| 238 | + built=True, |
| 239 | + active=True, |
| 240 | + ) |
| 241 | + fixture.get( |
| 242 | + Version, |
| 243 | + project=self.project, |
| 244 | + privacy_level=PUBLIC, |
| 245 | + slug="public-built", |
| 246 | + verbose_name="public-built", |
| 247 | + built=True, |
| 248 | + active=True, |
| 249 | + ) |
| 250 | + fixture.get( |
| 251 | + Version, |
| 252 | + project=self.project, |
| 253 | + privacy_level=PUBLIC, |
| 254 | + slug="public-not-built", |
| 255 | + verbose_name="public-not-built", |
| 256 | + built=False, |
| 257 | + active=True, |
| 258 | + ) |
| 259 | + fixture.get( |
| 260 | + Version, |
| 261 | + project=self.project, |
| 262 | + privacy_level=PUBLIC, |
| 263 | + slug="hidden", |
| 264 | + verbose_name="hidden", |
| 265 | + built=False, |
| 266 | + hidden=True, |
| 267 | + active=True, |
| 268 | + ) |
| 269 | + |
| 270 | + r = self.client.get( |
| 271 | + reverse("proxito_readthedocs_docs_addons"), |
| 272 | + { |
| 273 | + "url": "https://project.dev.readthedocs.io/en/latest/", |
| 274 | + "client-version": "0.6.0", |
| 275 | + "api-version": "0.1.0", |
| 276 | + }, |
| 277 | + secure=True, |
| 278 | + headers={ |
| 279 | + "host": "project.dev.readthedocs.io", |
| 280 | + }, |
| 281 | + ) |
| 282 | + assert r.status_code == 200 |
| 283 | + |
| 284 | + expected = [ |
| 285 | + {"slug": "latest", "url": "/en/latest/"}, |
| 286 | + {"slug": "public-built", "url": "/en/public-built/"}, |
| 287 | + ] |
| 288 | + assert r.json()["addons"]["flyout"]["versions"] == expected |
| 289 | + |
| 290 | + def test_flyout_translations(self): |
| 291 | + fixture.get( |
| 292 | + Project, |
| 293 | + slug="translation", |
| 294 | + main_language_project=self.project, |
| 295 | + language="ja", |
| 296 | + ) |
| 297 | + |
| 298 | + r = self.client.get( |
| 299 | + reverse("proxito_readthedocs_docs_addons"), |
| 300 | + { |
| 301 | + "url": "https://project.dev.readthedocs.io/en/latest/", |
| 302 | + "client-version": "0.6.0", |
| 303 | + "api-version": "0.1.0", |
| 304 | + }, |
| 305 | + secure=True, |
| 306 | + headers={ |
| 307 | + "host": "project.dev.readthedocs.io", |
| 308 | + }, |
| 309 | + ) |
| 310 | + assert r.status_code == 200 |
| 311 | + |
| 312 | + expected = [ |
| 313 | + {"slug": "ja", "url": "/ja/"}, |
| 314 | + ] |
| 315 | + assert r.json()["addons"]["flyout"]["translations"] == expected |
| 316 | + |
| 317 | + def test_flyout_downloads(self): |
| 318 | + fixture.get( |
| 319 | + Version, |
| 320 | + project=self.project, |
| 321 | + privacy_level=PUBLIC, |
| 322 | + slug="offline", |
| 323 | + verbose_name="offline", |
| 324 | + built=True, |
| 325 | + has_pdf=True, |
| 326 | + has_epub=True, |
| 327 | + has_htmlzip=True, |
| 328 | + active=True, |
| 329 | + ) |
| 330 | + |
| 331 | + r = self.client.get( |
| 332 | + reverse("proxito_readthedocs_docs_addons"), |
| 333 | + { |
| 334 | + "url": "https://project.dev.readthedocs.io/en/offline/", |
| 335 | + "client-version": "0.6.0", |
| 336 | + "api-version": "0.1.0", |
| 337 | + }, |
| 338 | + secure=True, |
| 339 | + headers={ |
| 340 | + "host": "project.dev.readthedocs.io", |
| 341 | + }, |
| 342 | + ) |
| 343 | + assert r.status_code == 200 |
| 344 | + |
| 345 | + expected = [ |
| 346 | + { |
| 347 | + "name": "PDF", |
| 348 | + "url": "//project.dev.readthedocs.io/_/downloads/en/offline/pdf/", |
| 349 | + }, |
| 350 | + { |
| 351 | + "name": "HTML", |
| 352 | + "url": "//project.dev.readthedocs.io/_/downloads/en/offline/htmlzip/", |
| 353 | + }, |
| 354 | + { |
| 355 | + "name": "Epub", |
| 356 | + "url": "//project.dev.readthedocs.io/_/downloads/en/offline/epub/", |
| 357 | + }, |
| 358 | + ] |
| 359 | + assert r.json()["addons"]["flyout"]["downloads"] == expected |
| 360 | + |
| 361 | + def test_flyout_single_version_project(self): |
| 362 | + self.version.has_pdf = True |
| 363 | + self.version.has_epub = True |
| 364 | + self.version.has_htmlzip = True |
| 365 | + self.version.save() |
| 366 | + |
| 367 | + self.project.single_version = True |
| 368 | + self.project.save() |
| 369 | + |
| 370 | + r = self.client.get( |
| 371 | + reverse("proxito_readthedocs_docs_addons"), |
| 372 | + { |
| 373 | + "url": "https://project.dev.readthedocs.io/", |
| 374 | + "client-version": "0.6.0", |
| 375 | + "api-version": "0.1.0", |
| 376 | + }, |
| 377 | + secure=True, |
| 378 | + headers={ |
| 379 | + "host": "project.dev.readthedocs.io", |
| 380 | + }, |
| 381 | + ) |
| 382 | + assert r.status_code == 200 |
| 383 | + |
| 384 | + expected = [] |
| 385 | + assert r.json()["addons"]["flyout"]["versions"] == expected |
| 386 | + |
| 387 | + expected = [ |
| 388 | + { |
| 389 | + "name": "PDF", |
| 390 | + "url": "//project.dev.readthedocs.io/_/downloads/en/latest/pdf/", |
| 391 | + }, |
| 392 | + { |
| 393 | + "name": "HTML", |
| 394 | + "url": "//project.dev.readthedocs.io/_/downloads/en/latest/htmlzip/", |
| 395 | + }, |
| 396 | + { |
| 397 | + "name": "Epub", |
| 398 | + "url": "//project.dev.readthedocs.io/_/downloads/en/latest/epub/", |
| 399 | + }, |
| 400 | + ] |
| 401 | + assert r.json()["addons"]["flyout"]["downloads"] == expected |
| 402 | + |
| 403 | + def test_project_subproject(self): |
| 404 | + subproject = fixture.get( |
| 405 | + Project, slug="subproject", repo="https://github.com/readthedocs/subproject" |
| 406 | + ) |
| 407 | + self.project.add_subproject(subproject) |
| 408 | + |
| 409 | + r = self.client.get( |
| 410 | + reverse("proxito_readthedocs_docs_addons"), |
| 411 | + { |
| 412 | + "url": "https://project.dev.readthedocs.io/projects/subproject/en/latest/", |
| 413 | + "client-version": "0.6.0", |
| 414 | + "api-version": "0.1.0", |
| 415 | + }, |
| 416 | + secure=True, |
| 417 | + headers={ |
| 418 | + "host": "project.dev.readthedocs.io", |
| 419 | + }, |
| 420 | + ) |
| 421 | + assert r.status_code == 200 |
| 422 | + |
| 423 | + assert r.json()["projects"]["current"]["id"] == subproject.pk |
| 424 | + assert r.json()["projects"]["current"]["slug"] == subproject.slug |
| 425 | + assert ( |
| 426 | + r.json()["projects"]["current"]["repository"]["url"] |
| 427 | + == "https://github.com/readthedocs/subproject" |
| 428 | + ) |
0 commit comments