Skip to content

Commit

Permalink
Fixed WikiFileManager push to wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
tholzheim committed Dec 1, 2021
1 parent 88a7860 commit abd5521
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 11 additions & 0 deletions tests/test_wikiFileManager.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
10 changes: 4 additions & 6 deletions wikifile/wikiFileManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
"""
Expand Down

0 comments on commit abd5521

Please sign in to comment.