Skip to content

Commit 37f6936

Browse files
committed
fixing up tests
1 parent e9b1c03 commit 37f6936

File tree

15 files changed

+100
-99
lines changed

15 files changed

+100
-99
lines changed

readthedocs/projects/models.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.contrib.auth.models import User
1414
from django.core.urlresolvers import NoReverseMatch, reverse
1515
from django.db import models
16+
from django.utils.lru_cache import lru_cache
1617
from django.utils.encoding import python_2_unicode_compatible
1718
from django.utils.functional import cached_property
1819
from django.utils.translation import ugettext_lazy as _
@@ -939,11 +940,14 @@ def json_file_path(self):
939940
file_path = os.path.join(full_json_path, file_path)
940941
return file_path
941942

942-
@cached_property
943-
def processed_json(self):
943+
def get_processed_json(self):
944944
file_path = self.json_file_path
945945
return process_file(file_path)
946946

947+
@cached_property
948+
def processed_json(self):
949+
return self.get_processed_json()
950+
947951

948952
class Notification(models.Model):
949953
project = models.ForeignKey(Project,

readthedocs/search/documents.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
from django.db import models
1+
from django.conf import settings
22
from django_elasticsearch_dsl import DocType, Index, fields
33

44
from readthedocs.projects.models import Project, HTMLFile
55
from .conf import SEARCH_EXCLUDED_FILE
66

77
from readthedocs.search.faceted_search import ProjectSearch, FileSearch
88

9-
project_index = Index('project')
9+
project_conf = settings.ES_INDEXES['project']
10+
project_index = Index(project_conf['name'])
11+
project_index.settings(**project_conf['settings'])
1012

11-
project_index.settings(
12-
number_of_shards=1,
13-
number_of_replicas=0
14-
)
13+
page_conf = settings.ES_INDEXES['page']
14+
page_index = Index(page_conf['name'])
15+
page_index.settings(**page_conf['settings'])
1516

1617

1718
@project_index.doc_type
@@ -44,14 +45,6 @@ def faceted_search(cls, query, language=None, using=None, index=None):
4445
return ProjectSearch(**kwargs)
4546

4647

47-
page_index = Index('page')
48-
49-
page_index.settings(
50-
number_of_shards=1,
51-
number_of_replicas=0
52-
)
53-
54-
5548
@page_index.doc_type
5649
class PageDocument(DocType):
5750

readthedocs/search/tests/conftest.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import random
2-
import string
1+
import json
2+
import os
33
from random import shuffle
44

55
import pytest
66
from django.core.management import call_command
77
from django_dynamic_fixture import G
88

9-
from readthedocs.projects.models import Project
10-
from readthedocs.search.indexes import Index, ProjectIndex, PageIndex, SectionIndex
11-
from .dummy_data import DUMMY_PAGE_JSON, ALL_PROJECTS
12-
13-
14-
@pytest.fixture(autouse=True)
15-
def mock_elastic_index(mocker):
16-
index_name = ''.join([random.choice(string.ascii_letters) for _ in range(5)])
17-
mocker.patch.object(Index, '_index', index_name.lower())
9+
from readthedocs.projects.models import Project, HTMLFile
10+
from .dummy_data import ALL_PROJECTS, PROJECT_DATA_FILES
1811

1912

2013
@pytest.fixture()
@@ -26,11 +19,23 @@ def es_index():
2619
call_command('search_index', '--delete', '-f')
2720

2821

29-
@pytest.fixture
30-
def all_projects(es_index):
31-
projects = [G(Project, slug=project_slug, name=project_slug) for project_slug in ALL_PROJECTS]
32-
shuffle(projects)
33-
return projects
22+
@pytest.fixture(autouse=True)
23+
def all_projects(es_index, mock_processed_json):
24+
projects_list = []
25+
for project_slug in ALL_PROJECTS:
26+
project = G(Project, slug=project_slug, name=project_slug)
27+
28+
for file_basename in PROJECT_DATA_FILES[project.slug]:
29+
# file_basename in config are without extension so add html extension
30+
file_name = file_basename + '.html'
31+
version = project.versions.all()[0]
32+
f = G(HTMLFile, project=project, version=version, name=file_name)
33+
f.save()
34+
35+
projects_list.append(project)
36+
37+
shuffle(projects_list)
38+
return projects_list
3439

3540

3641
@pytest.fixture
@@ -39,16 +44,23 @@ def project(all_projects):
3944
return all_projects[0]
4045

4146

42-
def get_dummy_page_json(version, *args, **kwargs):
43-
dummy_page_json = DUMMY_PAGE_JSON
44-
project_name = version.project.name
45-
return dummy_page_json.get(project_name)
47+
def get_dummy_processed_json(instance):
48+
project_slug = instance.project.slug
49+
basename = os.path.splitext(instance.name)[0]
50+
file_name = basename + '.json'
51+
current_path = os.path.abspath(os.path.dirname(__file__))
52+
file_path = os.path.join(current_path, "data", project_slug, file_name)
53+
54+
if os.path.exists(file_path):
55+
with open(file_path) as f:
56+
return json.load(f)
4657

4758

4859
@pytest.fixture(autouse=True)
49-
def mock_parse_json(mocker):
60+
def mock_processed_json(mocker):
5061

5162
# patch the function from `projects.tasks` because it has been point to there
5263
# http://www.voidspace.org.uk/python/mock/patch.html#where-to-patch
53-
mocked_function = mocker.patch('readthedocs.projects.tasks.process_all_json_files')
54-
mocked_function.side_effect = get_dummy_page_json
64+
mocked_function = mocker.patch.object(HTMLFile, 'get_processed_json', autospec=True)
65+
mocked_function.side_effect = get_dummy_processed_json
66+

readthedocs/search/tests/data/docs/story.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"content": "Philosophy\nRead the Docs is Open Source software. We have licensed the code base as MIT, which provides almost no restrictions on the use of the code.\nHowever, as a project there are things that we care about more than others. We built Read the Docs to support in the Open Source community. The code is open for people to contribute to, so that they may build features into https://readthedocs.org that they want. We also believe sharing the code openly is a valuable learning tool, especially for demonsrating how to collaborate and maintain an enormous website.\nOfficial Support\nThe time of the core developers of Read the Docs is limited. We provide official support for the following things:\nLocal development on the Python code base\nUsage of https://readthedocs.org for Open Source projects\nBug fixes in the code base, as it applies to running it on https://readthedocs.org\nUnsupported\nThere are use cases that we don\u2019t support, because it doesn\u2019t further our goal of promoting in the Open Source Community.\nWe do not support:\nSpecific usage of Sphinx and Mkdocs, that don\u2019t affect our hosting\nCustom s of Read the Docs at your company\n of Read the Docs on other platforms\nAny issues outside of the Read the Docs Python Code\nRationale\nRead the Docs was founded to improve in the Open Source Community. We fully recognize and allow the code to be used for internal installs at companies, but we will not spend our time supporting it. Our time is limited, and we want to spend it on the mission that we set out to originally support.\nIf you feel strongly about installing Read the Docs internal to a company, we will happily link to third party resources on this topic. Please open an issue with a proposal if you want to take on this task.",
2+
"content": "ReadtheDocsPhilosophy\nRead the Docs is Open Source software. We have licensed the code base as MIT, which provides almost no restrictions on the use of the code.\nHowever, as a project there are things that we care about more than others. We built Read the Docs to support in the Open Source community. The code is open for people to contribute to, so that they may build features into https://readthedocs.org that they want. We also believe sharing the code openly is a valuable learning tool, especially for demonsrating how to collaborate and maintain an enormous website.\nOfficial Support\nThe time of the core developers of Read the Docs is limited. We provide official support for the following things:\nLocal development on the Python code base\nUsage of https://readthedocs.org for Open Source projects\nBug fixes in the code base, as it applies to running it on https://readthedocs.org\nUnsupported\nThere are use cases that we don\u2019t support, because it doesn\u2019t further our goal of promoting in the Open Source Community.\nWe do not support:\nSpecific usage of Sphinx and Mkdocs, that don\u2019t affect our hosting\nCustom s of Read the Docs at your company\n of Read the Docs on other platforms\nAny issues outside of the Read the Docs Python Code\nRationale\nRead the Docs was founded to improve in the Open Source Community. We fully recognize and allow the code to be used for internal installs at companies, but we will not spend our time supporting it. Our time is limited, and we want to spend it on the mission that we set out to originally support.\nIf you feel strongly about installing Read the Docs internal to a company, we will happily link to third party resources on this topic. Please open an issue with a proposal if you want to take on this task.",
33
"headers": [
44
"Official Support",
55
"Unsupported",

readthedocs/search/tests/data/docs/wiping.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"content": "Wiping a Build Environment\nSometimes it happen that your Builds start failing because the build environment where the is created is stale or broken. This could happen for a couple of different reasons like pip not upgrading a package properly or a corrupted cached Python package.\nIn any of these cases (and many others), the solution could be just wiping out the existing build environment files and allow Read the Docs to create a new fresh one.\nFollow these steps to wipe the build environment:\nGo to Versions\nClick on the Edit button of the version you want to wipe on the right side of the page\nGo to the bottom of the page and click the wipe link, next to the \u201cSave\u201d button\nNote\nBy wiping the build environment, all the rst, md, and code files associated with it will be removed but not the already built (HTML and PDF files). Your will still online after wiping the build environment.\nNow you can re-build the version with a fresh build environment!",
2+
"content": "ReadtheDocsWiping a Build Environment\nSometimes it happen that your Builds start failing because the build environment where the is created is stale or broken. This could happen for a couple of different reasons like pip not upgrading a package properly or a corrupted cached Python package.\nIn any of these cases (and many others), the solution could be just wiping out the existing build environment files and allow Read the Docs to create a new fresh one.\nFollow these steps to wipe the build environment:\nGo to Versions\nClick on the Edit button of the version you want to wipe on the right side of the page\nGo to the bottom of the page and click the wipe link, next to the \u201cSave\u201d button\nNote\nBy wiping the build environment, all the rst, md, and code files associated with it will be removed but not the already built (HTML and PDF files). Your will still online after wiping the build environment.\nNow you can re-build the version with a fresh build environment!",
33
"headers": [
44
"Wiping a Build Environment"
55
],

readthedocs/search/tests/data/kuma/docker.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"content": "kuma-Docker Docker is used for development and (soon) for deployment.\nDocker Images\nDocker images are used in development, usually with the local working files mounted in the images to set behaviour.\nImages are built by Jenkins, after tests pass, and are published to quay.io. We try to store the configuration in the environment, so that the published images can be used in deployments by setting environment variables to deployment-specific values.\nHere are some of the images used in the Kuma project:\nkuma\nThe kuma Docker image builds on the kuma_base image, installing a kuma branch and building the assets needed for running as a webservice. The environment can be customized for different deployments.\nThe image can be recreated locally with make build-kuma.\nThe image tagged latest is used by default for development. It can be created locally with make build-kuma VERSION=latest. The latest image is created from the master branch in Jenkins and published to quay.io.\nkuma_base\nThe kuma_base Docker image contains the OS and libraries (C, Python, and Node.js) that support the kuma project. The kuma image extends this by installing the kuma source and building assets needed for production.\nThe image can be recreated locally with make build-base.\nThe image tagged latest is used by default for development. It can be created localled with make build-base VERSION=latest. The latest image is created from the master branch in Jenkins and published to quay.io\nkumascript\nThe kumascript Docker image contains the kumascript rendering engine and support files. The environment can be customized for different deployments.\nThe image can be recreated locally with make build-kumascript.\nThe image tagged latest is used by default for development. It can be created locally with make build-kumascript KS_VERSION=latest. The latest image is created from the master branch in Jenkins and published to quay.io.\nintegration-tests\nThe integration-tests Docker image contains browser-based integration tests that check the functionality of a running Kuma deployment.\nThe image can be recreated locally with docker build -f docker/images/integration-tests/ ., but this is only necessary for image development. Most developer will follow the Client-side testing to develop and run these integration tests.\nThe image is built and used in Jenkins in the stage-integration-tests and prod-integration-tests pipelines, configured by scripts in the Jenkinsfiles folder. It is not published to quay.io.",
2+
"content": "kumadocker Docker is used for development and (soon) for deployment.\nDocker Images\nDocker images are used in development, usually with the local working files mounted in the images to set behaviour.\nImages are built by Jenkins, after tests pass, and are published to quay.io. We try to store the configuration in the environment, so that the published images can be used in deployments by setting environment variables to deployment-specific values.\nHere are some of the images used in the Kuma project:\nkuma\nThe kuma Docker image builds on the kuma_base image, installing a kuma branch and building the assets needed for running as a webservice. The environment can be customized for different deployments.\nThe image can be recreated locally with make build-kuma.\nThe image tagged latest is used by default for development. It can be created locally with make build-kuma VERSION=latest. The latest image is created from the master branch in Jenkins and published to quay.io.\nkuma_base\nThe kuma_base Docker image contains the OS and libraries (C, Python, and Node.js) that support the kuma project. The kuma image extends this by installing the kuma source and building assets needed for production.\nThe image can be recreated locally with make build-base.\nThe image tagged latest is used by default for development. It can be created localled with make build-base VERSION=latest. The latest image is created from the master branch in Jenkins and published to quay.io\nkumascript\nThe kumascript Docker image contains the kumascript rendering engine and support files. The environment can be customized for different deployments.\nThe image can be recreated locally with make build-kumascript.\nThe image tagged latest is used by default for development. It can be created locally with make build-kumascript KS_VERSION=latest. The latest image is created from the master branch in Jenkins and published to quay.io.\nintegration-tests\nThe integration-tests Docker image contains browser-based integration tests that check the functionality of a running Kuma deployment.\nThe image can be recreated locally with docker build -f docker/images/integration-tests/ ., but this is only necessary for image development. Most developer will follow the Client-side testing to develop and run these integration tests.\nThe image is built and used in Jenkins in the stage-integration-tests and prod-integration-tests pipelines, configured by scripts in the Jenkinsfiles folder. It is not published to quay.io.",
33
"headers": [
44
"Docker",
55
"Docker Images",

readthedocs/search/tests/data/kuma/documentation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"content": "kuma-Documentation This documentation is generated and published at Read the Docs whenever the master branch is updated. GitHub can render our .rst documents as ReStructuredText, which is close enough to Sphinx for most code reviews, without features like links between documents.\nIt is occasionally necessary to generate the documentation locally. It is easiest to do this with a virtualenv on the host system, using only to regenerate the MDN Sphinx template. If you are not comfortable with that style of development, it can be done entirely in using -compose.\nGenerating documentation\nSphinx uses a Makefile in the docs subfolder to build documentation in several formats. MDN only uses the HTML format, and the generated document index is at docs/_build/html/index.html.\nTo generate the documentation in a virtualenv on the host machine, first install the requirements:\npip install -r requirements/docs.txt\nThen switch to the docs folder to use the Makefile:\ncd docs make html python -m webbrowser file://${PWD}/_build/html/index.html\nTo generate the documentation with :\n-compose run --rm --user $(id -u) web sh -c \"\\ virtualenv /tmp/.venvs/docs && \\ . /tmp/.venvs/docs/bin/activate && \\ pip install -r /app/requirements/docs.txt && \\ cd /app/docs && \\ make html\" python -m webbrowser file://${PWD}/docs/_build/html/index.html\nA virtualenv is required, to avoid a pip bug when changing the version of a system-installed package.",
2+
"content": "kumadocumentation This documentation is generated and published at Read the Docs whenever the master branch is updated. GitHub can render our .rst documents as ReStructuredText, which is close enough to Sphinx for most code reviews, without features like links between documents.\nIt is occasionally necessary to generate the documentation locally. It is easiest to do this with a virtualenv on the host system, using only to regenerate the MDN Sphinx template. If you are not comfortable with that style of development, it can be done entirely in using -compose.\nGenerating documentation\nSphinx uses a Makefile in the docs subfolder to build documentation in several formats. MDN only uses the HTML format, and the generated document index is at docs/_build/html/index.html.\nTo generate the documentation in a virtualenv on the host machine, first install the requirements:\npip install -r requirements/docs.txt\nThen switch to the docs folder to use the Makefile:\ncd docs make html python -m webbrowser file://${PWD}/_build/html/index.html\nTo generate the documentation with :\n-compose run --rm --user $(id -u) web sh -c \"\\ virtualenv /tmp/.venvs/docs && \\ . /tmp/.venvs/docs/bin/activate && \\ pip install -r /app/requirements/docs.txt && \\ cd /app/docs && \\ make html\" python -m webbrowser file://${PWD}/docs/_build/html/index.html\nA virtualenv is required, to avoid a pip bug when changing the version of a system-installed package.",
33
"headers": [
44
"Documentation",
55
"Generating documentation"

0 commit comments

Comments
 (0)