Skip to content

Commit

Permalink
Merge pull request #4095 from rtfd/humitos/corporate/tests
Browse files Browse the repository at this point in the history
Make tests extensible from corporate site
  • Loading branch information
humitos authored Jul 2, 2018
2 parents df1100d + 178f4ab commit f895af5
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 162 deletions.
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.
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')
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

0 comments on commit f895af5

Please sign in to comment.