Skip to content

Commit

Permalink
Merge pull request #6714 from stsewd/run-proxito-tests-with-proxito
Browse files Browse the repository at this point in the history
Run proxito tests with proxito
  • Loading branch information
stsewd authored Mar 10, 2020
2 parents 0e5b8ba + 7415eea commit 579f241
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 35 deletions.
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ addopts = --reuse-db --strict-markers
markers =
search
serve
proxito
python_files = tests.py test_*.py *_tests.py
filterwarnings =
# Ignore external dependencies warning deprecations
Expand Down
15 changes: 2 additions & 13 deletions readthedocs/proxito/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copied from .org


import pytest
import django_dynamic_fixture as fixture
from django.contrib.auth.models import User
from django.test import TestCase
Expand All @@ -10,19 +11,7 @@
from readthedocs.projects.models import Project


@override_settings(
PUBLIC_DOMAIN='dev.readthedocs.io',
ROOT_URLCONF='readthedocs.proxito.urls',
MIDDLEWARE=[
# Auth middleware is required since some views uses ``request.user``
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'readthedocs.proxito.middleware.ProxitoMiddleware',
],
USE_SUBDOMAIN=True,
RTD_BUILD_MEDIA_STORAGE='readthedocs.rtd_tests.storage.BuildMediaFileSystemStorageTest',
)
@pytest.mark.proxito
class BaseDocServing(TestCase):

def setUp(self):
Expand Down
1 change: 1 addition & 0 deletions readthedocs/proxito/tests/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def test_project_nginx_serving_unicode_filename(self):
@override_settings(
PYTHON_MEDIA=False,
PUBLIC_DOMAIN='readthedocs.io',
RTD_BUILD_MEDIA_STORAGE='readthedocs.rtd_tests.storage.BuildMediaFileSystemStorageTest',
)
class TestAdditionalDocViews(BaseDocServing):
# Test that robots.txt and sitemap.xml work
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/proxito/tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copied from test_middleware.py

import pytest
from django.test import TestCase
from django.test.utils import override_settings
from django_dynamic_fixture import get
Expand All @@ -10,8 +11,8 @@
from readthedocs.rtd_tests.utils import create_user


@override_settings(USE_SUBDOMAIN=True)
@override_settings(PUBLIC_DOMAIN='dev.readthedocs.io')
@pytest.mark.proxito
class MiddlewareTests(RequestFactoryTestMixin, TestCase):

def setUp(self):
Expand Down
8 changes: 3 additions & 5 deletions readthedocs/proxito/tests/test_old_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import django_dynamic_fixture as fixture
import pytest
from django.http import Http404
from django.urls import reverse
from django.test.utils import override_settings
from django.urls import reverse

from readthedocs.builds.models import Version
from readthedocs.redirects.models import Redirect
Expand All @@ -22,9 +22,7 @@
from .mixins import MockStorageMixin


@override_settings(
RTD_BUILD_MEDIA_STORAGE='readthedocs.proxito.tests.storage.BuildMediaStorageTest',
)
@override_settings(PUBLIC_DOMAIN='dev.readthedocs.io')
class InternalRedirectTests(BaseDocServing):

"""
Expand Down Expand Up @@ -162,8 +160,8 @@ def test_root_redirect_with_query_params(self):
# 404 directly and avoid using PYTHON_MEDIA.
@override_settings(
PYTHON_MEDIA=True,
PUBLIC_DOMAIN='dev.readthedocs.io',
ROOT_URLCONF='readthedocs.proxito.tests.handler_404_urls',
RTD_BUILD_MEDIA_STORAGE='readthedocs.proxito.tests.storage.BuildMediaStorageTest',
)
class UserRedirectTests(MockStorageMixin, BaseDocServing):

Expand Down
5 changes: 1 addition & 4 deletions readthedocs/proxito/tests/test_proxied_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
from readthedocs.rtd_tests.tests.test_footer import BaseTestFooterHTML


@override_settings(
PUBLIC_DOMAIN='readthedocs.io',
ROOT_URLCONF='readthedocs.proxito.urls',
)
@override_settings(PUBLIC_DOMAIN='readthedocs.io')
class TestProxiedFooterHTML(BaseTestFooterHTML, TestCase):

def setUp(self):
Expand Down
5 changes: 4 additions & 1 deletion readthedocs/proxito/tests/test_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from .base import BaseDocServing


@override_settings(PUBLIC_DOMAIN_USES_HTTPS=True)
@override_settings(
PUBLIC_DOMAIN='dev.readthedocs.io',
PUBLIC_DOMAIN_USES_HTTPS=True,
)
class RedirectTests(BaseDocServing):

def test_root_url(self):
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/proxito/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copied from .com codebase

# -*- coding: utf-8 -*-
"""Test URL config."""

from django.urls import resolve
import pytest
from django.test import TestCase, override_settings
from django.urls import resolve


@override_settings(ROOT_URLCONF='readthedocs.proxito.urls')
@pytest.mark.proxito
class TestSingleVersionURLs(TestCase):

def test_root(self):
Expand Down
6 changes: 5 additions & 1 deletion readthedocs/search/tests/test_proxied_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
from readthedocs.search.tests.test_api import BaseTestDocumentSearch


@pytest.mark.urls('readthedocs.proxito.urls')
@pytest.mark.proxito
@pytest.mark.search
class TestProxiedSearchAPI(BaseTestDocumentSearch):

host = 'pip.readthedocs.io'

@pytest.fixture(autouse=True)
def setup_settings(self, settings):
settings.PUBLIC_DOMAIN = 'readthedocs.io'

def get_search(self, api_client, search_params):
return api_client.get(self.url, search_params, HTTP_HOST=self.host)
10 changes: 8 additions & 2 deletions readthedocs/search/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
@pytest.mark.django_db
@pytest.mark.search
class TestProjectSearch:
url = reverse('search')

@pytest.fixture(autouse=True)
def setup(self):
self.url = reverse('search')

def _get_search_result(self, url, client, search_params):
resp = client.get(url, search_params)
Expand Down Expand Up @@ -84,7 +87,10 @@ def test_search_project_filter_language(self, client, project):
@pytest.mark.django_db
@pytest.mark.search
class TestPageSearch:
url = reverse('search')

@pytest.fixture(autouse=True)
def setup(self):
self.url = reverse('search')

def _get_search_result(self, url, client, search_params):
resp = client.get(url, search_params)
Expand Down
8 changes: 4 additions & 4 deletions readthedocs/settings/proxito/test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from ..test import CommunityTestSettings
from .base import ProxitoSettingsMixin
from .base import CommunityProxitoSettingsMixin


class CommunityProxitoTestSettings(
ProxitoSettingsMixin,
CommunityProxitoSettingsMixin,
CommunityTestSettings
):

pass

PUBLIC_DOMAIN = 'dev.readthedocs.io'
RTD_BUILD_MEDIA_STORAGE = 'readthedocs.proxito.tests.storage.BuildMediaStorageTest'

CommunityProxitoTestSettings.load_settings(__name__)
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ passenv = CI TRAVIS TRAVIS_*
deps = -r{toxinidir}/requirements/testing.txt
changedir = {toxinidir}/readthedocs
commands =
pytest --cov-report= --cov-config {toxinidir}/.coveragerc --cov=. --suppress-no-test-exit-code {posargs:{env:TOX_POSARGS:-m 'not search'}}
/bin/sh -c '\
export DJANGO_SETTINGS_MODULE=readthedocs.settings.test; \
pytest --cov-report= --cov-config {toxinidir}/.coveragerc --cov=. --suppress-no-test-exit-code -m "not proxito" {posargs:{env:TOX_POSARGS:-m "not search and not proxito"}}'

/bin/sh -c '\
export DJANGO_SETTINGS_MODULE=readthedocs.settings.proxito.test; \
pytest --cov-report= --cov-config {toxinidir}/.coveragerc --cov=. --cov-append -m proxito --suppress-no-test-exit-code {posargs}'


[testenv:docs]
description = build readthedocs documentation
Expand Down

0 comments on commit 579f241

Please sign in to comment.