Skip to content

Commit

Permalink
FooterAPI: use organizations to test private versions
Browse files Browse the repository at this point in the history
This is to fix tests on .com

---------

Co-authored-by: Santos Gallegos <stsewd@proton.me>
  • Loading branch information
humitos and stsewd authored Sep 12, 2023
1 parent aee3f49 commit 53e21bb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions readthedocs/rtd_tests/tests/test_footer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import mock

import pytest
from django.contrib.auth.models import User
from django.contrib.sessions.backends.base import SessionBase
from django.http import HttpResponse
from django.test import TestCase, override_settings
Expand All @@ -12,6 +13,7 @@
from readthedocs.builds.constants import BRANCH, EXTERNAL, LATEST, TAG
from readthedocs.builds.models import Version
from readthedocs.core.middleware import ReadTheDocsSessionMiddleware
from readthedocs.organizations.models import Organization
from readthedocs.projects.constants import GITHUB_BRAND, GITLAB_BRAND, PRIVATE, PUBLIC
from readthedocs.projects.models import Project
from readthedocs.subscriptions.constants import TYPE_CNAME
Expand Down Expand Up @@ -335,7 +337,11 @@ def setUp(self):
self.pip = Project.objects.get(slug="pip")
self.pip.versions.update(built=True)
self.pip.show_version_warning = True
self.pip.privacy_level = PUBLIC
self.pip.save()
self.pip.versions.update(privacy_level=PUBLIC)

self.user = User.objects.get(username="eric")

def test_highest_version_from_stable(self):
base_version = self.pip.get_stable_version()
Expand Down Expand Up @@ -446,14 +452,17 @@ def test_highest_version_without_tags(self):
returned_data = get_version_compare_data(self.pip, base_version)
self.assertDictEqual(valid_data, returned_data)

@override_settings(
RTD_ALLOW_ORGANIZATIONS=True,
)
def test_private_highest_version(self):
get(Organization, projects=[self.pip], owners=[self.user])
self.pip.versions.update(privacy_level=PRIVATE)
owner = self.pip.users.first()
base_version = self.pip.versions.get(slug="0.8")
returned_data = get_version_compare_data(self.pip, base_version)
self.assertTrue(returned_data["is_highest"])

returned_data = get_version_compare_data(self.pip, base_version, user=owner)
returned_data = get_version_compare_data(self.pip, base_version, user=self.user)
valid_data = {
"project": "Version 0.8.1 of Pip (19)",
"url": "https://pip.readthedocs.io/en/0.8.1/",
Expand Down

0 comments on commit 53e21bb

Please sign in to comment.