Esempio n. 1
0
    def test_build(self, mock_Popen, 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 = ProjectFactory(allow_comments=True)

        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(conf_path):
                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]))
Esempio n. 2
0
    def test_builder_no_comments(self):

        # Normal build
        project = ProjectFactory(allow_comments=False)
        version = project.versions.all()[0]
        builder = project.doc_builder()(version)
        self.assertEqual(builder.sphinx_builder, "readthedocs")
Esempio n. 3
0
    def test_build_respects_epub_flag(self, EpubBuilder_build,
                                      PdfBuilder_build, HtmlBuilder_build,
                                      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 = ProjectFactory(enable_pdf_build=False,
                                 enable_epub_build=True)
        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(conf_path):
                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)
Esempio n. 4
0
    def test_build(self, mock_Popen, 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 = ProjectFactory(allow_comments=True)

        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])
                      )
Esempio n. 5
0
    def test_builder_no_comments(self):

        # Normal build
        project = ProjectFactory(allow_comments=False)
        version = project.versions.all()[0]
        builder = project.doc_builder()(version)
        self.assertEqual(builder.sphinx_builder, 'readthedocs')
Esempio n. 6
0
    def test_build(self, mock_Popen, 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 = ProjectFactory(allow_comments=True)

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

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

        with mock.patch('codecs.open', mock.mock_open(), create=True):
            built_docs = build_docs(
                version,
                False,
                False,
                False,
                False,
                False,
                False,
                False,
            )

        builder = project.doc_builder()(version)
        self.assertIn(builder.sphinx_builder,
                      str(mock_Popen.call_args_list[1]))
Esempio n. 7
0
    def test_builder_comments(self):

        # Normal build
        project = ProjectFactory(allow_comments=True)
        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_build(self, mock_Popen, 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 = ProjectFactory(allow_comments=True)

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

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

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

        def patched_exists(path):
            if path == conf_path:
                return True
            return original_exists(path)

        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with mock.patch.object(os.path, 'exists', patched_exists):
                built_docs = build_docs(version,
                                        False,
                                        False,
                                        False,
                                        False,
                                        False,
                                        False,
                                        False,
                                        )

        builder = project.doc_builder()(version)
        self.assertIn(builder.sphinx_builder,
                      str(mock_Popen.call_args_list[1])
                      )
Esempio n. 9
0
    def test_nodes_with_same_hash_oddness(self):

        node_hash = "AcommonHASH"
        page = "somepage"
        commit = "somecommit"
        project = ProjectFactory()

        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.")
Esempio n. 10
0
    def test_build(self, mock_Popen, 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 = ProjectFactory(allow_comments=True)

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

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

        with mock.patch("codecs.open", mock.mock_open(), create=True):
            built_docs = build_docs(version, False, False, False, False, False, False, False)

        builder = project.doc_builder()(version)
        self.assertIn(builder.sphinx_builder, str(mock_Popen.call_args_list[1]))
Esempio n. 11
0
    def test_nodes_with_same_hash_oddness(self):

        node_hash = "AcommonHASH"
        page = "somepage"
        commit = "somecommit"
        project = ProjectFactory()

        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.")
Esempio n. 12
0
    def test_build_respects_epub_flag(self,
                                      EpubBuilder_build,
                                      PdfBuilder_build,
                                      HtmlBuilder_build,
                                      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 = ProjectFactory(
            enable_pdf_build=False,
            enable_epub_build=True)
        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)
Esempio n. 13
0
    def test_node_cannot_be_created_without_commit_and_hash(self):
        project = ProjectFactory()
        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))
Esempio n. 14
0
    def test_moderate_comment_by_approving(self):
        user = UserFactory(username="******", password="******")
        project = ProjectFactory()
        project.users.add(user)
        node = DocumentNodeFactory(project=project)

        comment = DocumentCommentFactory(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())