Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests extensible from corporate site #4095

Merged
merged 28 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cd82565
Get the proper path for sample repo under corporate
humitos Jun 6, 2018
8eaf66d
Use files existing in community and corporate site for tests
humitos May 15, 2018
4623873
Use http for Community site and https for Corporate site on tests
humitos May 15, 2018
7ce8015
Mark some OAuth tests as "only_community"
humitos May 15, 2018
c58de84
Extend MiddlewareTests class to set the urlconf from outsite
humitos May 15, 2018
be48ae2
Mark TestAPI for domain as "only community"
humitos May 15, 2018
ec133fb
Restore the cwd by using a decorator helper
humitos Jun 6, 2018
d55a15e
Generalize tests naming
humitos May 15, 2018
9b06d61
Generalize names
humitos May 15, 2018
f17e79e
Force ALLOW_PRIVATE_REPOS=False for test case
humitos May 15, 2018
e6c879d
Split project tests in classes by topic
humitos Jun 6, 2018
02b3236
Rename pytest.mark only_community to community
humitos Jun 28, 2018
f98fb39
Use pytest option to create valid URL depending the environment
humitos Jun 28, 2018
d4222e5
Get 'readthedocs' module path in the right way
humitos Jun 28, 2018
821f3c9
Minor fix to URL base
humitos Jun 28, 2018
af4e010
Define the URL inside setUp because it fails when loading the test
humitos Jun 28, 2018
10fd674
Use setting for subdomain URL conf instead of hardcoded value
humitos Jun 28, 2018
e10e2d4
Mark test case as community only
humitos Jun 28, 2018
7e96031
Use fixed PRODUCTION_DOMAIN for tests
humitos Jun 28, 2018
ab39aef
Avoid overriding conftest settings when called from readthedocsinc
humitos Jun 28, 2018
33813b5
Use /dashboard/ instead of / to avoid redirects
humitos Jun 28, 2018
7c2ec2e
Extend pytest's `markexpr` conf in case it already exists
humitos Jun 28, 2018
638b740
Fix test fixture loading
humitos Jun 28, 2018
86e2844
Use reverse_lazy to avoid issues
humitos Jun 28, 2018
74c2094
Fix inheritance order
humitos Jun 28, 2018
7077050
Depend on reliable data from the db for these tests
humitos Jun 28, 2018
7317ee9
Mark building test as community only
humitos Jun 29, 2018
178f4ab
Remove all community marks from pytests
humitos Jul 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
import logging

# -*- coding: utf-8 -*-
import pytest

try:
# TODO: this file is read/executed even when called from ``readthedocsinc``,
# so it's overriding the options that we are defining in the ``conftest.py``
# from the corporate site. We need to find a better way to avoid this.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conftest.py is directory dependent. That's why we can't override these pytest's options here. I'd like to find a better way to do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to define these PYTEST_OPTIONS in the settings.py file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this would be a good addition. Alternatively, maybe something in setup.cfg instead? I'm not sure if the load order would allow us to use django settings, given pytest-django likely sets up the application later in the process. We can make an issue to track updating this pattern.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #4317 for this

import readthedocsinc
PYTEST_OPTIONS = ()
except ImportError:
PYTEST_OPTIONS = (
# Options to set test environment
('community', True),
('corporate', False),
('environment', 'readthedocs'),

('url_scheme', 'http'),
)


def pytest_addoption(parser):
parser.addoption('--including-search', action='store_true', dest="searchtests",
default=False, help="enable search tests")
parser.addoption(
'--including-search',
action='store_true',
dest='searchtests',
default=False, help='enable search tests',
)


def pytest_configure(config):
if not config.option.searchtests:
# Include `not search` to parameters so that search test do not perform
setattr(config.option, 'markexpr', 'not search')
# Include ``not search``` to parameters so search tests do not perform
markexpr = getattr(config.option, 'markexpr')
if markexpr:
markexpr += ' and not search'
else:
markexpr = 'not search'
setattr(config.option, 'markexpr', markexpr.strip())

for option, value in PYTEST_OPTIONS:
setattr(config.option, option, value)


@pytest.fixture(autouse=True)
Expand Down
8 changes: 3 additions & 5 deletions readthedocs/rtd_tests/tests/test_celery.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals

import os
import json
import shutil
from os.path import exists
from tempfile import mkdtemp
Expand All @@ -10,20 +10,18 @@
from django_dynamic_fixture import get
from mock import patch, MagicMock

from readthedocs.builds.constants import BUILD_STATE_INSTALLING, BUILD_STATE_FINISHED, LATEST
from readthedocs.builds.constants import LATEST
from readthedocs.projects.exceptions import RepositoryError
from readthedocs.builds.models import Build
from readthedocs.projects.models import Project
from readthedocs.projects import tasks

from readthedocs.rtd_tests.utils import (
create_git_branch, create_git_tag, delete_git_branch, delete_git_tag)
create_git_branch, create_git_tag, delete_git_branch)
from readthedocs.rtd_tests.utils import make_test_git
from readthedocs.rtd_tests.base import RTDTestCase
from readthedocs.rtd_tests.mocks.mock_api import mock_api

from readthedocs.doc_builder.environments import BuildEnvironment


class TestCeleryBuilding(RTDTestCase):

Expand Down
4 changes: 2 additions & 2 deletions readthedocs/rtd_tests/tests/test_config_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_extra_requirements(self, load_config):
self.assertEqual(config.extra_requirements, [])

def test_conda(self, load_config):
to_find = 'urls.py'
to_find = '__init__.py'
load_config.side_effect = create_load({
'conda': {
'file': to_find
Expand All @@ -179,7 +179,7 @@ def test_conda(self, load_config):
self.assertEqual(config.conda_file, None)

def test_requirements_file(self, load_config):
requirements_file = 'wsgi.py'
requirements_file = '__init__.py'
load_config.side_effect = create_load({
'requirements_file': requirements_file
})
Expand Down
103 changes: 62 additions & 41 deletions readthedocs/rtd_tests/tests/test_core_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import mock
import pytest

from django.conf import settings
from django.test import TestCase
from django.test.utils import override_settings

Expand All @@ -9,11 +12,29 @@
from readthedocs.core.templatetags import core_tags


@override_settings(USE_SUBDOMAIN=False, PUBLIC_DOMAIN='readthedocs.org')
@override_settings(USE_SUBDOMAIN=False, PRODUCTION_DOMAIN='readthedocs.org')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was wrong. The test wants to use PRODUCTION_DOMAIN not PUBLIC_DOMAIN.

It's using USE_SUBDOMAIN=False, so the URL used for the documentation comes from PRODUCTION_DOMAIN. If you change the value override of PUBLIC_DOMAIN here to something different, all the tests keep passing which is wrong.

class CoreTagsTests(TestCase):
fixtures = ["eric", "test_data"]

def setUp(self):
url_base = '{scheme}://{domain}/docs/pip{{version}}'.format(
scheme=pytest.config.option.url_scheme,
domain=settings.PRODUCTION_DOMAIN,
)

self.pip_latest_url = url_base.format(version='/en/latest/')
self.pip_latest_fr_url = url_base.format(version='/fr/latest/')
self.pip_abc_url = url_base.format(version='/en/abc/')
self.pip_abc_fr_url = url_base.format(version='/fr/abc/')
self.pip_abc_xyz_page_url = url_base.format(version='/en/abc/xyz.html')
self.pip_abc_xyz_fr_page_url = url_base.format(version='/fr/abc/xyz.html')
self.pip_abc_xyz_dir_url = url_base.format(version='/en/abc/xyz/')
self.pip_abc_xyz_fr_dir_url = url_base.format(version='/fr/abc/xyz/')
self.pip_abc_xyz_document = url_base.format(version='/en/abc/index.html#document-xyz')
self.pip_abc_xyz_fr_document = url_base.format(version='/fr/abc/index.html#document-xyz')
self.pip_latest_document_url = url_base.format(version='/en/latest/document/')
self.pip_latest_document_page_url = url_base.format(version='/en/latest/document.html')

with mock.patch('readthedocs.projects.models.broadcast'):
self.client.login(username='eric', password='test')
self.pip = Project.objects.get(slug='pip')
Expand All @@ -22,164 +43,164 @@ def setUp(self):
def test_project_only(self):
proj = Project.objects.get(slug='pip')
url = core_tags.make_document_url(proj)
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/')
self.assertEqual(url, self.pip_latest_url)
url = core_tags.make_document_url(proj, '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/')
self.assertEqual(url, self.pip_latest_url)

def test_project_only_htmldir(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'sphinx_htmldir'
url = core_tags.make_document_url(proj)
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/')
self.assertEqual(url, self.pip_latest_url)
url = core_tags.make_document_url(proj, '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/')
self.assertEqual(url, self.pip_latest_url)

def test_project_only_singlehtml(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'sphinx_singlehtml'
url = core_tags.make_document_url(proj)
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/')
self.assertEqual(url, self.pip_latest_url)
url = core_tags.make_document_url(proj, '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/')
self.assertEqual(url, self.pip_latest_url)

def test_translation_project_only(self):
proj = Project.objects.get(slug='pip-fr')
url = core_tags.make_document_url(proj)
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/latest/')
self.assertEqual(url, self.pip_latest_fr_url)
url = core_tags.make_document_url(proj, '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/latest/')
self.assertEqual(url, self.pip_latest_fr_url)

def test_translation_project_only_htmldir(self):
proj = Project.objects.get(slug='pip-fr')
proj.documentation_type = 'sphinx_htmldir'
url = core_tags.make_document_url(proj)
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/latest/')
self.assertEqual(url, self.pip_latest_fr_url)
url = core_tags.make_document_url(proj, '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/latest/')
self.assertEqual(url, self.pip_latest_fr_url)

def test_translation_project_only_singlehtml(self):
proj = Project.objects.get(slug='pip-fr')
proj.documentation_type = 'sphinx_singlehtml'
url = core_tags.make_document_url(proj)
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/latest/')
self.assertEqual(url, self.pip_latest_fr_url)
url = core_tags.make_document_url(proj, '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/latest/')
self.assertEqual(url, self.pip_latest_fr_url)

def test_project_and_version(self):
proj = Project.objects.get(slug='pip')
url = core_tags.make_document_url(proj, 'abc')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)
url = core_tags.make_document_url(proj, 'abc', '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)

def test_project_and_version_htmldir(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'sphinx_htmldir'
url = core_tags.make_document_url(proj, 'abc')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)
url = core_tags.make_document_url(proj, 'abc', '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)

def test_project_and_version_singlehtml(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'sphinx_singlehtml'
url = core_tags.make_document_url(proj, 'abc')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)
url = core_tags.make_document_url(proj, 'abc', '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)

def test_translation_project_and_version(self):
proj = Project.objects.get(slug='pip-fr')
url = core_tags.make_document_url(proj, 'abc')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)
url = core_tags.make_document_url(proj, 'abc', '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)

def test_translation_project_and_version_htmldir(self):
proj = Project.objects.get(slug='pip-fr')
proj.documentation_type = 'sphinx_htmldir'
url = core_tags.make_document_url(proj, 'abc')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)
url = core_tags.make_document_url(proj, 'abc', '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)

def test_translation_project_and_version_singlehtml(self):
proj = Project.objects.get(slug='pip-fr')
proj.documentation_type = 'sphinx_singlehtml'
url = core_tags.make_document_url(proj, 'abc')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)
url = core_tags.make_document_url(proj, 'abc', '')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)

def test_project_and_version_and_page(self):
proj = Project.objects.get(slug='pip')
url = core_tags.make_document_url(proj, 'abc', 'xyz')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/xyz.html')
self.assertEqual(url, self.pip_abc_xyz_page_url)
url = core_tags.make_document_url(proj, 'abc', 'index')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)

def test_project_and_version_and_page_htmldir(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'sphinx_htmldir'
url = core_tags.make_document_url(proj, 'abc', 'xyz')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/xyz/')
self.assertEqual(url, self.pip_abc_xyz_dir_url)
url = core_tags.make_document_url(proj, 'abc', 'index')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)

def test_project_and_version_and_page_signlehtml(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'sphinx_singlehtml'
url = core_tags.make_document_url(proj, 'abc', 'xyz')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/index.html#document-xyz')
self.assertEqual(url, self.pip_abc_xyz_document)
url = core_tags.make_document_url(proj, 'abc', 'index')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/abc/')
self.assertEqual(url, self.pip_abc_url)

def test_translation_project_and_version_and_page(self):
proj = Project.objects.get(slug='pip-fr')
url = core_tags.make_document_url(proj, 'abc', 'xyz')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/xyz.html')
self.assertEqual(url, self.pip_abc_xyz_fr_page_url)
url = core_tags.make_document_url(proj, 'abc', 'index')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)

def test_translation_project_and_version_and_page_htmldir(self):
proj = Project.objects.get(slug='pip-fr')
proj.documentation_type = 'sphinx_htmldir'
url = core_tags.make_document_url(proj, 'abc', 'xyz')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/xyz/')
self.assertEqual(url, self.pip_abc_xyz_fr_dir_url)
url = core_tags.make_document_url(proj, 'abc', 'index')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)

def test_translation_project_and_version_and_page_singlehtml(self):
proj = Project.objects.get(slug='pip-fr')
proj.documentation_type = 'sphinx_singlehtml'
url = core_tags.make_document_url(proj, 'abc', 'xyz')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/index.html#document-xyz')
self.assertEqual(url, self.pip_abc_xyz_fr_document)
url = core_tags.make_document_url(proj, 'abc', 'index')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/fr/abc/')
self.assertEqual(url, self.pip_abc_fr_url)

def test_mkdocs(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'mkdocs'
url = core_tags.make_document_url(proj, LATEST, 'document')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/document/')
self.assertEqual(url, self.pip_latest_document_url)

def test_mkdocs_no_directory_urls(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'mkdocs'
url = core_tags.make_document_url(proj, LATEST, 'document.html')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/document.html')
self.assertEqual(url, self.pip_latest_document_page_url)

def test_mkdocs_index(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'mkdocs'
url = core_tags.make_document_url(proj, LATEST, 'index')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/')
self.assertEqual(url, self.pip_latest_url)

def test_mkdocs_index_no_directory_urls(self):
proj = Project.objects.get(slug='pip')
proj.documentation_type = 'mkdocs'
url = core_tags.make_document_url(proj, LATEST, 'index.html')
self.assertEqual(url, 'http://readthedocs.org/docs/pip/en/latest/')
self.assertEqual(url, self.pip_latest_url)

def test_restructured_text(self):
value = '*test*'
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/rtd_tests/tests/test_doc_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import yaml
import mock
from django.test import TestCase
from django.test.utils import override_settings
from django_dynamic_fixture import get
from mock import patch

Expand Down Expand Up @@ -115,6 +116,7 @@ def test_ignore_patterns(self):
self.assertTrue(os.path.exists(dest_other))


@override_settings(PRODUCTION_DOMAIN='readthedocs.org')
class MkdocsBuilderTest(TestCase):

def setUp(self):
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/rtd_tests/tests/test_domains.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import json

Expand Down
Loading