Skip to content

Commit

Permalink
Split project tests in classes by topic
Browse files Browse the repository at this point in the history
All the translation tests manage different user permissions on each
different project, which is more complicated to test them from
Corporate. So, they are marked as `only_community`
  • Loading branch information
humitos committed Jun 6, 2018
1 parent 65a9ebb commit a8ca72b
Showing 1 changed file with 91 additions and 81 deletions.
172 changes: 91 additions & 81 deletions readthedocs/rtd_tests/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import datetime
import json
import pytest

from django.contrib.auth.models import User
from django.forms.models import model_to_dict
Expand All @@ -21,13 +22,16 @@
from readthedocs.rtd_tests.mocks.paths import fake_paths_by_regex


class TestProject(TestCase):
fixtures = ['eric', 'test_data']
class ProjectMixin(object):

def setUp(self):
self.client.login(username='eric', password='test')
self.pip = Project.objects.get(slug='pip')


class TestProject(ProjectMixin, TestCase):
fixtures = ['eric', 'test_data']

def test_valid_versions(self):
r = self.client.get('/api/v2/project/6/valid_versions/', {})
resp = json.loads(r.content)
Expand All @@ -41,6 +45,91 @@ def test_subprojects(self):
self.assertEqual(r.status_code, 200)
self.assertEqual(resp['subprojects'][0]['id'], 23)

def test_token(self):
r = self.client.get('/api/v2/project/6/token/', {})
resp = json.loads(r.content)
self.assertEqual(r.status_code, 200)
self.assertEqual(resp['token'], None)

def test_has_pdf(self):
# The project has a pdf if the PDF file exists on disk.
with fake_paths_by_regex('\.pdf$'):
self.assertTrue(self.pip.has_pdf(LATEST))

# The project has no pdf if there is no file on disk.
with fake_paths_by_regex('\.pdf$', exists=False):
self.assertFalse(self.pip.has_pdf(LATEST))

def test_has_pdf_with_pdf_build_disabled(self):
# The project has NO pdf if pdf builds are disabled
self.pip.enable_pdf_build = False
with fake_paths_by_regex('\.pdf$'):
self.assertFalse(self.pip.has_pdf(LATEST))

def test_has_epub(self):
# The project has a epub if the PDF file exists on disk.
with fake_paths_by_regex('\.epub$'):
self.assertTrue(self.pip.has_epub(LATEST))

# The project has no epub if there is no file on disk.
with fake_paths_by_regex('\.epub$', exists=False):
self.assertFalse(self.pip.has_epub(LATEST))

def test_has_epub_with_epub_build_disabled(self):
# The project has NO epub if epub builds are disabled
self.pip.enable_epub_build = False
with fake_paths_by_regex('\.epub$'):
self.assertFalse(self.pip.has_epub(LATEST))

@patch('readthedocs.projects.models.Project.find')
def test_conf_file_found(self, find_method):
find_method.return_value = [
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/src/conf.py',
]
self.assertEqual(
self.pip.conf_file(),
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/src/conf.py',
)

@patch('readthedocs.projects.models.Project.find')
def test_multiple_conf_file_one_doc_in_path(self, find_method):
find_method.return_value = [
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/src/conf.py',
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/docs/conf.py',
]
self.assertEqual(
self.pip.conf_file(),
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/docs/conf.py',
)

@patch('readthedocs.projects.models.Project.find')
@patch('readthedocs.projects.models.Project.full_find')
def test_conf_file_not_found(self, find_method, full_find_method):
find_method.return_value = []
full_find_method.return_value = []
with self.assertRaisesMessage(
ProjectConfigurationError,
ProjectConfigurationError.NOT_FOUND) as cm:
self.pip.conf_file()

@patch('readthedocs.projects.models.Project.find')
def test_multiple_conf_files(self, find_method):
find_method.return_value = [
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/multi-conf.py/src/conf.py',
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/multi-conf.py/src/sub/conf.py',
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/multi-conf.py/src/sub/src/conf.py',
]
with self.assertRaisesMessage(
ProjectConfigurationError,
ProjectConfigurationError.MULTIPLE_CONF_FILES) as cm:
self.pip.conf_file()


# Most of these tests don't handle Corporate permissions (Organizations, Teams,
# etc) in a proper way
@pytest.mark.only_community
class TestProjectTranslations(TestCase, ProjectMixin):

def test_translations(self):
main_project = get(Project)

Expand Down Expand Up @@ -323,85 +412,6 @@ def test_user_can_change_project_with_same_lang(self):
self.assertEqual(resp.status_code, 200)
self.assertNotContains(resp, 'There is already a')

def test_token(self):
r = self.client.get('/api/v2/project/6/token/', {})
resp = json.loads(r.content)
self.assertEqual(r.status_code, 200)
self.assertEqual(resp['token'], None)

def test_has_pdf(self):
# The project has a pdf if the PDF file exists on disk.
with fake_paths_by_regex('\.pdf$'):
self.assertTrue(self.pip.has_pdf(LATEST))

# The project has no pdf if there is no file on disk.
with fake_paths_by_regex('\.pdf$', exists=False):
self.assertFalse(self.pip.has_pdf(LATEST))

def test_has_pdf_with_pdf_build_disabled(self):
# The project has NO pdf if pdf builds are disabled
self.pip.enable_pdf_build = False
with fake_paths_by_regex('\.pdf$'):
self.assertFalse(self.pip.has_pdf(LATEST))

def test_has_epub(self):
# The project has a epub if the PDF file exists on disk.
with fake_paths_by_regex('\.epub$'):
self.assertTrue(self.pip.has_epub(LATEST))

# The project has no epub if there is no file on disk.
with fake_paths_by_regex('\.epub$', exists=False):
self.assertFalse(self.pip.has_epub(LATEST))

def test_has_epub_with_epub_build_disabled(self):
# The project has NO epub if epub builds are disabled
self.pip.enable_epub_build = False
with fake_paths_by_regex('\.epub$'):
self.assertFalse(self.pip.has_epub(LATEST))

@patch('readthedocs.projects.models.Project.find')
def test_conf_file_found(self, find_method):
find_method.return_value = [
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/src/conf.py',
]
self.assertEqual(
self.pip.conf_file(),
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/src/conf.py',
)

@patch('readthedocs.projects.models.Project.find')
def test_multiple_conf_file_one_doc_in_path(self, find_method):
find_method.return_value = [
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/src/conf.py',
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/docs/conf.py',
]
self.assertEqual(
self.pip.conf_file(),
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/latest/docs/conf.py',
)

@patch('readthedocs.projects.models.Project.find')
@patch('readthedocs.projects.models.Project.full_find')
def test_conf_file_not_found(self, find_method, full_find_method):
find_method.return_value = []
full_find_method.return_value = []
with self.assertRaisesMessage(
ProjectConfigurationError,
ProjectConfigurationError.NOT_FOUND) as cm:
self.pip.conf_file()

@patch('readthedocs.projects.models.Project.find')
def test_multiple_conf_files(self, find_method):
find_method.return_value = [
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/multi-conf.py/src/conf.py',
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/multi-conf.py/src/sub/conf.py',
'/home/docs/rtfd/code/readthedocs.org/user_builds/pip/checkouts/multi-conf.py/src/sub/src/conf.py',
]
with self.assertRaisesMessage(
ProjectConfigurationError,
ProjectConfigurationError.MULTIPLE_CONF_FILES) as cm:
self.pip.conf_file()


class TestFinishInactiveBuildsTask(TestCase):
fixtures = ['eric', 'test_data']
Expand Down

0 comments on commit a8ca72b

Please sign in to comment.