def test_dont_localmedia_build_pdf_epub_search_in_mkdocs(self, load_config):
        load_config.side_effect = create_load()
        project = get(
            Project,
            slug='project-1',
            documentation_type='mkdocs',
            enable_pdf_build=True,
            enable_epub_build=True,
            versions=[fixture()],
        )
        version = project.versions.all().first()

        build_env = LocalBuildEnvironment(
            project=project,
            version=version,
            build={},
        )
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(
            build_env=build_env, project=project, python_env=python_env,
            version=version, config=config,
        )

        task.build_docs()

        # Only html for mkdocs was built
        self.mocks.html_build_mkdocs.assert_called_once()
        self.mocks.html_build.assert_not_called()
        self.mocks.localmedia_build.assert_not_called()
        self.mocks.pdf_build.assert_not_called()
        self.mocks.epub_build.assert_not_called()
Beispiel #2
0
    def test_dont_localmedia_build_pdf_epub_search_in_mkdocs(
            self, load_config):
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='mkdocs',
                      enable_pdf_build=True,
                      enable_epub_build=True,
                      versions=[fixture()])
        version = project.versions.all().first()

        build_env = LocalBuildEnvironment(project=project,
                                          version=version,
                                          build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env,
                                  project=project,
                                  python_env=python_env,
                                  version=version,
                                  config=config)

        task.build_docs()

        # Only html for mkdocs was built
        self.mocks.html_build_mkdocs.assert_called_once()
        self.mocks.html_build.assert_not_called()
        self.mocks.localmedia_build.assert_not_called()
        self.mocks.pdf_build.assert_not_called()
        self.mocks.epub_build.assert_not_called()
 def setUp(self):
     self.project = get(Project,
                        slug='project-1',
                        documentation_type='sphinx',
                        conf_py_file='test_conf.py',
                        versions=[fixture()])
     self.version = self.project.versions.all()[0]
Beispiel #4
0
    def test_nodes_with_same_hash_oddness(self):

        node_hash = "AcommonHASH"
        page = "somepage"
        commit = "somecommit"
        project = get(Project, versions=[fixture()])

        project.add_node(
            node_hash=node_hash,
            page=page,
            version=project.versions.all()[0].slug,
            commit=commit,
        )

        # A new commit with a second instance of the exact same content.
        project.add_node(
            node_hash=node_hash,
            page=page,
            version=project.versions.all()[0].slug,
            commit="ANEWCOMMIT",
        )
        try:
            project.nodes.from_hash(project.versions.all()[0].slug, page,
                                    node_hash, project.slug)
        except NotImplementedError:
            self.fail("We don't have indexing yet.")
Beispiel #5
0
    def test_add_comment_view_without_existing_hash(self):

        comment_text = "Here's a comment added to a new hash."
        version = get(Version, project=fixture())
        node = create_node(project=version.project, version=version)
        user = create_user(username='******', password='******')

        number_of_nodes = DocumentNode.objects.count()

        post_data = {
            'node': random.getrandbits(128),
            'commit': random.getrandbits(128),
            'project': node.project.slug,
            'version': node.version.slug,
            'document_page': node.page,
            'text': comment_text
        }

        self.client.login(username="******", password="******")

        response = self.client.post('/api/v2/comments/', post_data)
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['text'], comment_text)
        self.assertEqual(DocumentNode.objects.count(),
                         number_of_nodes + 1)  # We created a new node.
    def test_build_respects_pdf_flag(self, load_config):
        '''Build output format control'''
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]

        build_env = LocalBuildEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env, project=project, python_env=python_env,
                              version=version, search=False, localmedia=False, config=config)

        task.build_docs()

        # The HTML and the Epub format were built.
        self.mocks.html_build.assert_called_once_with()
        self.mocks.pdf_build.assert_called_once_with()
        # PDF however was disabled and therefore not built.
        self.assertFalse(self.mocks.epub_build.called)
    def test_build(self, load_config):
        '''Test full build'''
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      versions=[fixture()])
        version = project.versions.all()[0]
        self.mocks.configure_mock('api_versions', {'return_value': [version]})
        self.mocks.configure_mock('api', {
            'get.return_value': {'downloads': "no_url_here"}
        })
        self.mocks.patches['html_build'].stop()

        build_env = LocalBuildEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env, project=project, python_env=python_env,
                              version=version, search=False, localmedia=False, config=config)
        task.build_docs()

        # Get command and check first part of command list is a call to sphinx
        self.assertEqual(self.mocks.popen.call_count, 3)
        cmd = self.mocks.popen.call_args_list[2][0]
        self.assertRegexpMatches(cmd[0][0], r'python')
        self.assertRegexpMatches(cmd[0][1], r'sphinx-build')
Beispiel #8
0
    def test_build_respects_epub_flag(self):
        '''Test build with epub enabled'''
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=False,
                      enable_epub_build=True,
                      versions=[fixture()])
        version = project.versions.all()[0]

        build_env = LocalEnvironment(project=project,
                                     version=version,
                                     build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        yaml_config = get_build_config({})
        config = ConfigWrapper(version=version, yaml_config=yaml_config)
        task = UpdateDocsTask(build_env=build_env,
                              project=project,
                              python_env=python_env,
                              version=version,
                              search=False,
                              localmedia=False,
                              config=config)
        task.build_docs()

        # The HTML and the Epub format were built.
        self.mocks.html_build.assert_called_once_with()
        self.mocks.epub_build.assert_called_once_with()
        # PDF however was disabled and therefore not built.
        self.assertFalse(self.mocks.pdf_build.called)
Beispiel #9
0
    def test_build(self):
        '''Test full build'''
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      versions=[fixture()])
        version = project.versions.all()[0]
        self.mocks.configure_mock('api_versions', {'return_value': [version]})
        self.mocks.configure_mock(
            'api', {'get.return_value': {
                'downloads': "no_url_here"
            }})
        self.mocks.patches['html_build'].stop()

        build_env = LocalEnvironment(project=project,
                                     version=version,
                                     build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        yaml_config = get_build_config({})
        config = ConfigWrapper(version=version, yaml_config=yaml_config)
        task = UpdateDocsTask(build_env=build_env,
                              project=project,
                              python_env=python_env,
                              version=version,
                              search=False,
                              localmedia=False,
                              config=config)
        task.build_docs()

        # Get command and check first part of command list is a call to sphinx
        self.assertEqual(self.mocks.popen.call_count, 1)
        cmd = self.mocks.popen.call_args_list[0][0]
        self.assertRegexpMatches(cmd[0][0], r'python')
        self.assertRegexpMatches(cmd[0][1], r'sphinx-build')
 def setUp(self):
     self.project = get(Project,
                        slug='project-1',
                        documentation_type='sphinx',
                        conf_py_file='test_conf.py',
                        versions=[fixture()])
     self.version = self.project.versions.all()[0]
Beispiel #11
0
    def test_build(self, load_config):
        '''Test full build'''
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      versions=[fixture()])
        version = project.versions.all()[0]
        self.mocks.configure_mock('api_versions', {'return_value': [version]})
        self.mocks.configure_mock(
            'api', {'get.return_value': {
                'downloads': "no_url_here"
            }})
        self.mocks.patches['html_build'].stop()

        build_env = LocalBuildEnvironment(project=project,
                                          version=version,
                                          build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env,
                                  project=project,
                                  python_env=python_env,
                                  version=version,
                                  config=config)
        task.build_docs()

        # Get command and check first part of command list is a call to sphinx
        self.assertEqual(self.mocks.popen.call_count, 3)
        cmd = self.mocks.popen.call_args_list[2][0]
        self.assertRegex(cmd[0][0], r'python')
        self.assertRegex(cmd[0][1], r'sphinx-build')
Beispiel #12
0
    def test_build_respects_pdf_flag(self, load_config):
        '''Build output format control'''
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]

        build_env = LocalBuildEnvironment(project=project,
                                          version=version,
                                          build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env,
                                  project=project,
                                  python_env=python_env,
                                  version=version,
                                  config=config)

        task.build_docs()

        # The HTML and the Epub format were built.
        self.mocks.html_build.assert_called_once_with()
        self.mocks.pdf_build.assert_called_once_with()
        # PDF however was disabled and therefore not built.
        self.assertFalse(self.mocks.epub_build.called)
Beispiel #13
0
    def test_build_respects_pdf_flag(self):
        '''Build output format control'''
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]

        build_env = LocalEnvironment(project=project,
                                     version=version,
                                     build={})
        task = UpdateDocsTask(build_env=build_env,
                              version=version,
                              project=project,
                              search=False,
                              localmedia=False)
        built_docs = task.build_docs()

        # The HTML and the Epub format were built.
        self.mocks.html_build.assert_called_once_with()
        self.mocks.pdf_build.assert_called_once_with()
        # PDF however was disabled and therefore not built.
        self.assertFalse(self.mocks.epub_build.called)
Beispiel #14
0
    def test_build_respects_yaml(self):
        '''Test YAML build options'''
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=False,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]

        build_env = LocalEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = ConfigWrapper(version=version, yaml_config=create_load({
            'formats': ['epub']
        })()[0])
        task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
                              version=version, search=False, localmedia=False, config=config)
        task.build_docs()

        # The HTML and the Epub format were built.
        self.mocks.html_build.assert_called_once_with()
        self.mocks.epub_build.assert_called_once_with()
        # PDF however was disabled and therefore not built.
        self.assertFalse(self.mocks.pdf_build.called)
Beispiel #15
0
    def setUp(self):
        self.user = create_user(username='******', password='******')

        self.project = get(Project, slug='test', users=[fixture(), self.user])

        self.golduser = get(GoldUser, user=self.user, level=LEVEL_CHOICES[0][0])

        self.client.login(username='******', password='******')
    def setUp(self):
        self.user = create_user(username='******', password='******')

        self.project = get(Project, slug='test', users=[fixture(), self.user])

        self.golduser = get(GoldUser, user=self.user, level=LEVEL_CHOICES[0][0])

        self.client.login(username='******', password='******')
Beispiel #17
0
    def test_builder_no_comments(self):

        # Normal build
        project = get(Project,
                      documentation_type='sphinx',
                      allow_comments=False,
                      versions=[fixture()])
        version = project.versions.all()[0]
        builder_class = get_builder_class(project.documentation_type)
        builder = builder_class(version)
        self.assertEqual(builder.sphinx_builder, 'readthedocs')
Beispiel #18
0
    def test_builder_comments(self):

        # Normal build
        project = get(Project,
                      documentation_type='sphinx',
                      allow_comments=True,
                      versions=[fixture()])
        version = project.versions.all()[0]
        builder_class = get_builder_class(project.documentation_type)
        builder = builder_class(version)
        self.assertEqual(builder.sphinx_builder, 'readthedocs-comments')
 def test_builder_comments(self):
     '''Normal build with comments'''
     project = get(Project,
                   documentation_type='sphinx',
                   allow_comments=True,
                   versions=[fixture()])
     version = project.versions.all()[0]
     build_env = LocalEnvironment(version=version, project=project, build={})
     builder_class = get_builder_class(project.documentation_type)
     builder = builder_class(build_env)
     self.assertEqual(builder.sphinx_builder, 'readthedocs-comments')
Beispiel #20
0
 def test_builder_comments(self):
     '''Normal build with comments'''
     project = get(Project,
                   documentation_type='sphinx',
                   allow_comments=True,
                   versions=[fixture()])
     version = project.versions.all()[0]
     build_env = LocalEnvironment(version=version, project=project, build={})
     python_env = Virtualenv(version=version, build_env=build_env)
     builder_class = get_builder_class(project.documentation_type)
     builder = builder_class(build_env, python_env)
     self.assertEqual(builder.sphinx_builder, 'readthedocs-comments')
Beispiel #21
0
 def test_builder_no_comments(self):
     '''Test builder without comments'''
     project = get(Project,
                   documentation_type='sphinx',
                   allow_comments=False,
                   versions=[fixture()])
     version = project.versions.all()[0]
     build_env = LocalEnvironment(version=version, project=project, build={})
     python_env = Virtualenv(version=version, build_env=build_env)
     builder_class = get_builder_class(project.documentation_type)
     builder = builder_class(build_env, python_env)
     self.assertEqual(builder.sphinx_builder, 'readthedocs')
Beispiel #22
0
    def test_build_pdf_latex_not_failure(self, load_config):
        """Test pass during PDF builds and bad latex failure status code."""

        load_config.side_effect = create_load()
        self.mocks.patches['html_build'].stop()
        self.mocks.patches['pdf_build'].stop()

        project = get(
            Project,
            slug='project-2',
            documentation_type='sphinx',
            conf_py_file='test_conf.py',
            enable_pdf_build=True,
            enable_epub_build=False,
            versions=[fixture()],
        )
        version = project.versions.all()[0]
        assert project.conf_dir() == '/tmp/rtd'

        build_env = LocalBuildEnvironment(project=project,
                                          version=version,
                                          build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(
            build_env=build_env,
            project=project,
            python_env=python_env,
            version=version,
            config=config,
        )

        # Mock out the separate calls to Popen using an iterable side_effect
        returns = [
            ((b'', b''), 0),  # sphinx-build html
            ((b'', b''), 0),  # sphinx-build pdf
            ((b'', b''), 1),  # sphinx version check
            ((b'Output written on foo.pdf', b''), 1),  # latex
            ((b'', b''), 0),  # makeindex
            ((b'', b''), 0),  # latex
        ]
        mock_obj = mock.Mock()
        mock_obj.communicate.side_effect = [
            output for (output, status) in returns
        ]
        type(mock_obj).returncode = mock.PropertyMock(
            side_effect=[status for (output, status) in returns], )
        self.mocks.popen.return_value = mock_obj

        with build_env:
            task.build_docs()
        self.assertEqual(self.mocks.popen.call_count, 6)
        self.assertTrue(build_env.successful)
Beispiel #23
0
    def setUp(self):
        self.user = create_user(username='******', password='******')

        self.project = get(Project, slug='test', users=[fixture(), self.user])

        self.golduser = get(
            GoldUser,
            user=self.user,
            level=LEVEL_CHOICES[0][0],
            pub_date=GoldUser.SPONSOR_PROJECT_CUTOFF - timedelta(days=1),
        )

        self.client.login(username='******', password='******')
Beispiel #24
0
 def test_builder_no_comments(self):
     '''Test builder without comments'''
     project = get(Project,
                   documentation_type='sphinx',
                   allow_comments=False,
                   versions=[fixture()])
     version = project.versions.all()[0]
     build_env = LocalEnvironment(version=version,
                                  project=project,
                                  build={})
     builder_class = get_builder_class(project.documentation_type)
     builder = builder_class(build_env)
     self.assertEqual(builder.sphinx_builder, 'readthedocs')
Beispiel #25
0
    def setUp(self):
        self.user = create_user(username='******', password='******')

        self.project = get(Project, slug='test', users=[fixture(), self.user])

        self.golduser = get(
            GoldUser,
            user=self.user,
            level=LEVEL_CHOICES[0][0],
            pub_date=GoldUser.SPONSOR_PROJECT_CUTOFF - timedelta(days=1),
        )

        self.client.login(username='******', password='******')
    def test_build_pdf_latex_not_failure(self, load_config):
        """Test pass during PDF builds and bad latex failure status code."""

        load_config.side_effect = create_load()
        self.mocks.patches['html_build'].stop()
        self.mocks.patches['pdf_build'].stop()

        project = get(
            Project,
            slug='project-2',
            documentation_type='sphinx',
            conf_py_file='test_conf.py',
            enable_pdf_build=True,
            enable_epub_build=False,
            versions=[fixture()],
        )
        version = project.versions.all()[0]
        assert project.conf_dir() == '/tmp/rtd'

        build_env = LocalBuildEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(
            build_env=build_env, project=project, python_env=python_env,
            version=version, config=config,
        )

        # Mock out the separate calls to Popen using an iterable side_effect
        returns = [
            ((b'', b''), 0),  # sphinx-build html
            ((b'', b''), 0),  # sphinx-build pdf
            ((b'Output written on foo.pdf', b''), 1),  # latex
            ((b'', b''), 0),  # makeindex
            ((b'', b''), 0),  # latex
        ]
        mock_obj = mock.Mock()
        mock_obj.communicate.side_effect = [
            output for (output, status)
            in returns
        ]
        type(mock_obj).returncode = mock.PropertyMock(
            side_effect=[status for (output, status) in returns],
        )
        self.mocks.popen.return_value = mock_obj

        with build_env:
            task.build_docs()
        self.assertEqual(self.mocks.popen.call_count, 7)
        self.assertTrue(build_env.successful)
Beispiel #27
0
    def test_build_pdf_latex_failures(self):
        '''Build failure if latex fails'''
        self.mocks.patches['html_build'].stop()
        self.mocks.patches['pdf_build'].stop()

        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]
        assert project.conf_dir() == '/tmp/rtd'

        build_env = LocalEnvironment(project=project,
                                     version=version,
                                     build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        yaml_config = get_build_config({})
        config = ConfigWrapper(version=version, yaml_config=yaml_config)
        task = UpdateDocsTask(build_env=build_env,
                              project=project,
                              python_env=python_env,
                              version=version,
                              search=False,
                              localmedia=False,
                              config=config)

        # Mock out the separate calls to Popen using an iterable side_effect
        returns = [
            (('', ''), 0),  # sphinx-build html
            (('', ''), 0),  # sphinx-build pdf
            (('', ''), 1),  # latex
            (('', ''), 0),  # makeindex
            (('', ''), 0),  # latex
        ]
        mock_obj = mock.Mock()
        mock_obj.communicate.side_effect = [
            output for (output, status) in returns
        ]
        type(mock_obj).returncode = mock.PropertyMock(
            side_effect=[status for (output, status) in returns])
        self.mocks.popen.return_value = mock_obj

        with build_env:
            task.build_docs()
        self.assertEqual(self.mocks.popen.call_count, 5)
        self.assertTrue(build_env.failed)
Beispiel #28
0
    def test_node_cannot_be_created_without_commit_and_hash(self):
        project = get(Project, versions=[fixture()])
        some_version = project.versions.all()[0]

        self.assertRaises(TypeError,
                          DocumentNode.objects.create,
                          project=project,
                          version=some_version,
                          hash=random.getrandbits(128))

        self.assertRaises(TypeError,
                          DocumentNode.objects.create,
                          project=project,
                          version=some_version,
                          commit=random.getrandbits(128))
Beispiel #29
0
    def test_node_cannot_be_created_without_commit_and_hash(self):
        project = get(Project, versions=[fixture()])
        some_version = project.versions.all()[0]

        self.assertRaises(TypeError,
                          DocumentNode.objects.create,
                          project=project,
                          version=some_version,
                          hash=random.getrandbits(128)
                          )

        self.assertRaises(TypeError,
                          DocumentNode.objects.create,
                          project=project,
                          version=some_version,
                          commit=random.getrandbits(128)
                          )
    def test_build_pdf_latex_not_failure(self):
        '''Test pass during PDF builds and bad latex failure status code'''
        if six.PY3:
            import pytest
            pytest.xfail(
                "test_build_pdf_latex_not_failure is known to fail on 3.6")

        self.mocks.patches['html_build'].stop()
        self.mocks.patches['pdf_build'].stop()

        project = get(Project,
                      slug='project-2',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]
        assert project.conf_dir() == '/tmp/rtd'

        build_env = LocalEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = ConfigWrapper(version=version, yaml_config=create_load()()[0])
        task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
                              version=version, search=False, localmedia=False, config=config)

        # Mock out the separate calls to Popen using an iterable side_effect
        returns = [
            (('', ''), 0),  # sphinx-build html
            (('', ''), 0),  # sphinx-build pdf
            (('Output written on foo.pdf', ''), 1),  # latex
            (('', ''), 0),  # makeindex
            (('', ''), 0),  # latex
        ]
        mock_obj = mock.Mock()
        mock_obj.communicate.side_effect = [output for (output, status)
                                            in returns]
        type(mock_obj).returncode = mock.PropertyMock(
            side_effect=[status for (output, status) in returns])
        self.mocks.popen.return_value = mock_obj

        with build_env:
            task.build_docs()
        self.assertEqual(self.mocks.popen.call_count, 7)
        self.assertTrue(build_env.successful)
    def test_build_pdf_latex_failures(self):
        '''Build failure if latex fails'''
        if six.PY3:
            import pytest
            pytest.xfail(
                "test_build_pdf_latex_failures is known to fail on 3.6")

        self.mocks.patches['html_build'].stop()
        self.mocks.patches['pdf_build'].stop()

        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]
        assert project.conf_dir() == '/tmp/rtd'

        build_env = LocalEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = ConfigWrapper(version=version, yaml_config=create_load()()[0])
        task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
                              version=version, search=False, localmedia=False, config=config)

        # Mock out the separate calls to Popen using an iterable side_effect
        returns = [
            (('', ''), 0),  # sphinx-build html
            (('', ''), 0),  # sphinx-build pdf
            (('', ''), 1),  # latex
            (('', ''), 0),  # makeindex
            (('', ''), 0),  # latex
        ]
        mock_obj = mock.Mock()
        mock_obj.communicate.side_effect = [output for (output, status)
                                            in returns]
        type(mock_obj).returncode = mock.PropertyMock(
            side_effect=[status for (output, status) in returns])
        self.mocks.popen.return_value = mock_obj

        with build_env:
            task.build_docs()
        self.assertEqual(self.mocks.popen.call_count, 7)
        self.assertTrue(build_env.failed)
Beispiel #32
0
    def test_build(self,
                   mock_Popen,
                   mock_NonBlockingLock_enter,
                   mock_api_versions,
                   mock_chdir,
                   mock_apiv2_downloads):

        # subprocess mock logic

        mock_process = mock.Mock()
        process_return_dict = {'communicate.return_value': ('SOMEGITHASH', '')}
        mock_process.configure_mock(**process_return_dict)
        mock_Popen.return_value = mock_process
        mock_Popen.side_effect = build_subprocess_side_effect

        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      versions=[fixture()])

        version = project.versions.all()[0]
        mock_api_versions.return_value = [version]

        mock_apiv2_downloads.get.return_value = {'downloads': "no_url_here"}

        conf_path = os.path.join(
            project.checkout_path(version.slug),
            project.conf_py_file)

        # Mock open to simulate existing conf.py file
        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with fake_paths_lookup({conf_path: True}):
                built_docs = build_docs(version,
                                        False,
                                        False,
                                        False,
                                        )

        builder_class = get_builder_class(project.documentation_type)
        builder = builder_class(version)
        self.assertIn(builder.sphinx_builder,
                      str(mock_Popen.call_args_list[1])
                      )
Beispiel #33
0
    def test_moderate_comment_by_approving(self):
        user = create_user(username='******', password='******')

        project = get(Project, versions=[fixture()])
        project.users.add(user)
        node = create_node(project=project)

        comment = get(DocumentComment, node=node)

        post_data = {
            'decision': 1,
        }

        self.assertFalse(comment.has_been_approved_since_most_recent_node_change())

        self.client.login(username="******", password="******")
        response = self.client.put('/api/v2/comments/%s/moderate/' % comment.id, post_data)
        self.assertEqual(response.data['decision'], 1)
        self.assertTrue(comment.has_been_approved_since_most_recent_node_change())
Beispiel #34
0
    def test_build_respects_epub_flag(self,
                                      EpubBuilder_build,
                                      PdfBuilder_build,
                                      HtmlBuilder_build,
                                      mock_NonBlockingLock_enter,
                                      mock_Popen,
                                      mock_chdir,
                                      mock_apiv2_downloads):

        # subprocess mock logic

        mock_process = mock.Mock()
        process_return_dict = {'communicate.return_value': ('SOMEGITHASH', '')}
        mock_process.configure_mock(**process_return_dict)
        mock_Popen.return_value = mock_process
        mock_Popen.side_effect = build_subprocess_side_effect

        project = get(Project,
                      slug='project-2',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=False,
                      enable_epub_build=True,
                      versions=[fixture()])
        version = project.versions.all()[0]

        conf_path = os.path.join(project.checkout_path(version.slug), project.conf_py_file)

        # Mock open to simulate existing conf.py file
        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with fake_paths_lookup({conf_path: True}):
                built_docs = build_docs(version,
                                        False,
                                        False,
                                        False,
                                        )

        # The HTML and the Epub format were built.
        self.assertEqual(HtmlBuilder_build.call_count, 1)
        self.assertEqual(EpubBuilder_build.call_count, 1)
        # PDF however was disabled and therefore not built.
        self.assertEqual(PdfBuilder_build.call_count, 0)
    def test_build_respects_epub_flag(self):
        '''Test build with epub enabled'''
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=False,
                      enable_epub_build=True,
                      versions=[fixture()])
        version = project.versions.all()[0]

        build_env = LocalEnvironment(project=project, version=version, build={})
        task = UpdateDocsTask(build_env=build_env, project=project,
                              version=version, search=False, localmedia=False)
        built_docs = task.build_docs()

        # The HTML and the Epub format were built.
        self.mocks.html_build.assert_called_once_with()
        self.mocks.epub_build.assert_called_once_with()
        # PDF however was disabled and therefore not built.
        self.assertFalse(self.mocks.pdf_build.called)
Beispiel #36
0
    def test_build_respects_epub_flag(self, EpubBuilder_build,
                                      PdfBuilder_build, HtmlBuilder_build,
                                      mock_NonBlockingLock_enter, mock_Popen,
                                      mock_chdir, mock_apiv2_downloads):

        # subprocess mock logic

        mock_process = mock.Mock()
        process_return_dict = {'communicate.return_value': ('SOMEGITHASH', '')}
        mock_process.configure_mock(**process_return_dict)
        mock_Popen.return_value = mock_process
        mock_Popen.side_effect = build_subprocess_side_effect

        project = get(Project,
                      slug='project-2',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=False,
                      enable_epub_build=True,
                      versions=[fixture()])
        version = project.versions.all()[0]

        conf_path = os.path.join(project.checkout_path(version.slug),
                                 project.conf_py_file)

        # Mock open to simulate existing conf.py file
        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with fake_paths_lookup({conf_path: True}):
                built_docs = build_docs(
                    version,
                    False,
                    False,
                    False,
                )

        # The HTML and the Epub format were built.
        self.assertEqual(HtmlBuilder_build.call_count, 1)
        self.assertEqual(EpubBuilder_build.call_count, 1)
        # PDF however was disabled and therefore not built.
        self.assertEqual(PdfBuilder_build.call_count, 0)
Beispiel #37
0
    def test_moderate_comment_by_approving(self):
        user = create_user(username='******', password='******')

        project = get(Project, versions=[fixture()])
        project.users.add(user)
        node = create_node(project=project)

        comment = get(DocumentComment, node=node)

        post_data = {
            'decision': 1,
        }

        self.assertFalse(
            comment.has_been_approved_since_most_recent_node_change())

        self.client.login(username="******", password="******")
        response = self.client.put(
            '/api/v2/comments/%s/moderate/' % comment.id, post_data)
        self.assertEqual(response.data['decision'], 1)
        self.assertTrue(
            comment.has_been_approved_since_most_recent_node_change())
Beispiel #38
0
    def test_build(self, mock_Popen, mock_NonBlockingLock_enter,
                   mock_api_versions, mock_chdir, mock_apiv2_downloads):

        # subprocess mock logic

        mock_process = mock.Mock()
        process_return_dict = {'communicate.return_value': ('SOMEGITHASH', '')}
        mock_process.configure_mock(**process_return_dict)
        mock_Popen.return_value = mock_process
        mock_Popen.side_effect = build_subprocess_side_effect

        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      versions=[fixture()])

        version = project.versions.all()[0]
        mock_api_versions.return_value = [version]

        mock_apiv2_downloads.get.return_value = {'downloads': "no_url_here"}

        conf_path = os.path.join(project.checkout_path(version.slug),
                                 project.conf_py_file)

        # Mock open to simulate existing conf.py file
        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with fake_paths_lookup({conf_path: True}):
                built_docs = build_docs(
                    version,
                    False,
                    False,
                    False,
                )

        builder_class = get_builder_class(project.documentation_type)
        builder = builder_class(version)
        self.assertIn(builder.sphinx_builder,
                      str(mock_Popen.call_args_list[1]))
    def test_build_pdf_latex_not_failure(self):
        '''Test pass during PDF builds and bad latex failure status code'''
        self.mocks.patches['html_build'].stop()
        self.mocks.patches['pdf_build'].stop()

        project = get(Project,
                      slug='project-2',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]
        assert project.conf_dir() == '/tmp/rtd'

        build_env = LocalEnvironment(project=project, version=version, build={})
        task = UpdateDocsTask(build_env=build_env, project=project,
                              version=version, search=False, localmedia=False)

        # Mock out the separate calls to Popen using an iterable side_effect
        returns = [
            (('', ''), 0),  # sphinx-build html
            (('', ''), 0),  # sphinx-build pdf
            (('Output written on foo.pdf', ''), 1),  # latex
            (('', ''), 0),  # makeindex
            (('', ''), 0),  # latex
        ]
        mock_obj = mock.Mock()
        mock_obj.communicate.side_effect = [output for (output, status)
                                            in returns]
        type(mock_obj).returncode = mock.PropertyMock(
            side_effect=[status for (output, status) in returns])
        self.mocks.popen.return_value = mock_obj

        with build_env:
            built_docs = task.build_docs()
        self.assertEqual(self.mocks.popen.call_count, 5)
        self.assertTrue(build_env.successful)
Beispiel #40
0
    def test_nodes_with_same_hash_oddness(self):

        node_hash = "AcommonHASH"
        page = "somepage"
        commit = "somecommit"
        project = get(Project, versions=[fixture()])

        project.add_node(node_hash=node_hash,
                         page=page,
                         version=project.versions.all()[0].slug,
                         commit=commit,
                         )

        # A new commit with a second instance of the exact same content.
        project.add_node(node_hash=node_hash,
                         page=page,
                         version=project.versions.all()[0].slug,
                         commit="ANEWCOMMIT",
                         )
        try:
            project.nodes.from_hash(project.versions.all()[0].slug, page, node_hash, project.slug)
        except NotImplementedError:
            self.fail("We don't have indexing yet.")
Beispiel #41
0
    def test_add_comment_view_without_existing_hash(self):

        comment_text = "Here's a comment added to a new hash."
        version = get(Version, project=fixture())
        node = create_node(project=version.project, version=version)
        user = create_user(username='******', password='******')

        number_of_nodes = DocumentNode.objects.count()

        post_data = {
            'node': random.getrandbits(128),
            'commit': random.getrandbits(128),
            'project': node.project.slug,
            'version': node.version.slug,
            'document_page': node.page,
            'text': comment_text
        }

        self.client.login(username="******", password="******")

        response = self.client.post('/api/v2/comments/', post_data)
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['text'], comment_text)
        self.assertEqual(DocumentNode.objects.count(), number_of_nodes + 1)  # We created a new node.
 def setUp(self):
     self.project = get(
         Project, slug="project-1", documentation_type="sphinx", conf_py_file="test_conf.py", versions=[fixture()]
     )
     self.version = self.project.versions.all()[0]