コード例 #1
0
    def test_create_page(self, mocked_session):
        mocked_session.return_value.post.return_value.json.return_value = {
            "edit": {
                "result": "Success"
            }
        }

        page_title = "page title example"
        post_page_params = {
            "action": "edit",
            "maxlag": "5",
            "title": page_title,
            "createonly": "true",
            "contentmodel": "wikitext",
            "bot": "true",
            "format": "json",
        }

        token = "token example"
        page_text = "page text example"
        post_json_data = {"token": token, "text": page_text}

        mediawiki = MediaWikiService()
        mediawiki.create_page(token, page_title, page_text)
        mocked_session.return_value.post.assert_called_with(
            url="https://your-wiki.org/api.php",
            params=post_page_params,
            data=post_json_data,
        )
        mocked_session.return_value.post.return_value.json.assert_called_with()
コード例 #2
0
 def test_create_page_fails_with_existing_page(self, mocked_session):
     mediawiki = MediaWikiService()
     mocked_session.return_value.post.return_value.json.return_value = {
         "error": {
             "code": "articleexists"
         }
     }
     with self.assertRaises(MediaWikiServiceError):
         token = "token example"
         page_title = "page title example"
         page_text = "page text example"
         mediawiki.create_page(token, page_title, page_text)
コード例 #3
0
    def create_page(self, document_data: dict) -> None:
        """
        Creates a wiki page

        Keyword arguments:
        document_data -- All required data for a project using
                         Organised Editing Guidelines
        """
        mediawiki = MediaWikiService()
        wikitext = WikiTextService()
        token = mediawiki.get_token()

        page_title = self.templates.oeg_page

        overview_page_sections = self.document_to_page_sections(document_data)

        sections_text = wikitext.generate_text_from_dict(
            self.templates.page_template,
            f"=={self.templates.page_initial_section}==",
            overview_page_sections,
        )
        updated_text = WikiTableService().add_table_row(
            page_text=sections_text,
            new_row=self.generate_activities_list_table_row(document_data),
            table_section_title=self.templates.activities_list_section_title,
            table_template=self.templates.table_template,
        )
        if mediawiki.is_existing_page(page_title):
            page_text = MediaWikiService().get_page_text(
                self.templates.oeg_page)
            overview_page_table = (WikiSectionService().get_section_table(
                page_text,
                self.templates.activities_list_section_title).string)
            updated_text = WikiTableService().add_table_row(
                page_text=page_text,
                new_row=self.generate_activities_list_table_row(document_data),
                table_section_title=self.templates.
                activities_list_section_title,
                table_template=overview_page_table,
            )
            mediawiki.edit_page(token, self.templates.oeg_page, updated_text)
        else:
            mediawiki.create_page(token, page_title, updated_text)
コード例 #4
0
    def create_page(self, document_data: dict):
        """
        Creates a wiki page

        Keyword arguments:
        document_data -- All required data for a project using
                         Organised Editing Guidelines
        """
        mediawiki = MediaWikiService()

        organisation_page_sections = self.document_to_page_sections(
            document_data)

        sections_text = WikiTextService().generate_text_from_dict(
            self.templates.page_template,
            self.templates.page_initial_section,
            organisation_page_sections,
        )
        updated_text = WikiTableService().add_table_row(
            page_text=sections_text,
            new_row=self.generate_projects_list_table_row(document_data),
            table_section_title=self.templates.projects_section,
            table_template=self.templates.table_template,
        )

        page_title = f"{self.templates.oeg_page}/{document_data['organisation']['name'].capitalize()}"
        token = mediawiki.get_token()
        if mediawiki.is_existing_page(page_title):
            page_text = MediaWikiService().get_page_text(page_title)
            organisation_page_table = (WikiSectionService().get_section_table(
                page_text, self.templates.projects_list_section).string)
            updated_text = WikiTableService().add_table_row(
                page_text=page_text,
                new_row=self.generate_projects_list_table_row(document_data),
                table_section_title=self.templates.projects_list_section,
                table_template=organisation_page_table,
            )
            mediawiki.edit_page(token, page_title, updated_text)
        else:
            mediawiki.create_page(token, page_title, updated_text)
コード例 #5
0
    def create_page(self, document_data: dict) -> None:
        """
        Creates a wiki page

        Keyword arguments:
        document_data -- All required data for a project using
                         Organised Editing Guidelines
        """
        mediawiki = MediaWikiService()

        token = mediawiki.get_token()

        project_page_sections = self.document_to_page_sections(document_data)

        sections_text = WikiTextService().generate_text_from_dict(
            self.templates.page_template,
            f"=={self.templates.page_initial_section}==",
            project_page_sections,
        )
        updated_text = WikiTableService().add_table_row(
            page_text=sections_text,
            new_row=self.get_project_users_table_rows(document_data),
            table_section_title=self.templates.team_user_section,
            table_template=self.templates.table_template,
        )

        page_title = (f"{self.templates.oeg_page}/Projects/"
                      f'{document_data["project"]["name"].capitalize()}')
        if mediawiki.is_existing_page(page_title):
            raise ValueError(
                "Error reporting project "
                f"'{document_data['project']['name'].capitalize()}'."
                " Project already was reported.")
        else:
            mediawiki.create_page(
                token=token,
                page_title=page_title,
                page_text=updated_text,
            )