From abd5521ee9301ca4f11ad9ae1f60a0fa0b1b9240 Mon Sep 17 00:00:00 2001 From: tholzheim Date: Wed, 1 Dec 2021 12:44:41 +0100 Subject: [PATCH] Fixed WikiFileManager push to wiki --- tests/test_wikiFileManager.py | 11 +++++++++++ wikifile/wikiFileManager.py | 10 ++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/test_wikiFileManager.py b/tests/test_wikiFileManager.py index 4a27781..a743672 100644 --- a/tests/test_wikiFileManager.py +++ b/tests/test_wikiFileManager.py @@ -1,10 +1,12 @@ import unittest +import uuid import warnings import getpass from pathlib import Path from wikibot.wikiuser import WikiUser +from wikifile.wikiFile import WikiFile from wikifile.wikiFileManager import WikiFileManager from wikibot.wikipush import WikiPush from datetime import datetime @@ -264,6 +266,15 @@ def testWikiUser(self): self.assertTrue(isinstance(wikiUser, WikiUser)) + def testPushNewPageToWiki(self): + """ + tests pushing a wikiFile to the target wiki with the page not existing at first + """ + wikiFile=WikiFile(wikiFileManager=self.wikiFileManager, wikiText="Test Page", name=str(uuid.uuid1())) + self.wikiFileManager.pushWikiFilesToWiki([wikiFile]) + + + if __name__ == "__main__": # import sys;sys.argv = ['', 'Test.testName'] unittest.main() \ No newline at end of file diff --git a/wikifile/wikiFileManager.py b/wikifile/wikiFileManager.py index 9f3cf6a..6f75bad 100644 --- a/wikifile/wikiFileManager.py +++ b/wikifile/wikiFileManager.py @@ -219,7 +219,7 @@ def pagesListToDict(self, data: list, titleKey: str = "pageTitle", removeKey:boo del record[titleKey] return pagesDict - def pushWikiFilesToWiki(self, wiki_files: list): + def pushWikiFilesToWiki(self, wiki_files: list, updateMsg:str=None): """ Pushes the content of the given wikiFiles to the corresponding wiki pages in the wiki If targetWikiId is not defined no pages will be pushed @@ -236,11 +236,9 @@ def pushWikiFilesToWiki(self, wiki_files: list): for wiki_file in wiki_files: if isinstance(wiki_file, WikiFile): page_content = str(wiki_file) - update_msg = f"modified through csv import by {self.wikiPush.toWiki.wikiUser.user}" - page = wiki_file.getPage() - if page is None: - page = self.wikiPush.fromWiki.getPage(wiki_file.getPageTitle()) - page.edit(page_content, update_msg) + if updateMsg is None: updateMsg=f"modified through WikiFileManager by {self.wikiPush.toWiki.wikiUser.user}" + page = self.wikiPush.toWiki.getPage(wiki_file.getPageTitle()) + page.edit(page_content, updateMsg) def getUpdatedPages(self, records: dict, wikiSon: str) -> list: """