summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2017-01-06 03:30:03 +0000
committerrsiddharth <s@ricketyspace.net>2017-01-06 03:30:03 +0000
commitd35105f158819f0f731a4efc7e138905ef8e627d (patch)
tree43f5d6cf8cd851dd5c8657eda7c3e8b56517fb8a
parente46931f435cf00f1d70a6a6ccb755b92b7eff441 (diff)
Add `push_wiki_page` function.
* gd_diff.py (get_wiki_mc, push_wiki_page): New functions. * tests/test_gd_diff.py (TestGdDiff.test_push_wiki_page): New method; test for `push_wiki_page` function.
-rw-r--r--gd_diff.py49
-rw-r--r--tests/test_gd_diff.py45
2 files changed, 94 insertions, 0 deletions
diff --git a/gd_diff.py b/gd_diff.py
index 19b71a5..a126d56 100644
--- a/gd_diff.py
+++ b/gd_diff.py
@@ -12,11 +12,14 @@ import os
import re
import shlex
import sys
+import xmlrpc.client
import requests
from os import path
from subprocess import run, PIPE
+from urllib.parse import urljoin
+from xmlrpc.client import ServerProxy, MultiCall, Fault
from bs4 import BeautifulSoup
from pkg_resources import resource_string
@@ -410,6 +413,52 @@ def write_wiki_page(release, content):
write_file(wp_file, content)
+def get_wiki_mc(url, user, passwd): # pragma: no cover
+ """Return instance of `xmlprc.client.MultiCall` object.
+
+ """
+ url = urljoin(url, '?action=xmlrpc2')
+ conn = ServerProxy(url, allow_none=True)
+
+ try:
+ token = conn.getAuthToken(user, passwd)
+ except Fault as f:
+ print(f.faultString)
+ exit(1)
+
+ mc = MultiCall(conn)
+ mc.applyAuthToken(token)
+
+ return mc
+
+
+def push_wiki_page(url, user, passwd, version, content):
+ """Push `release`' wiki page to wiki at `uri`.
+
+ """
+ def process_result(r, f=None):
+ if(r == 'SUCCESS'):
+ print('auth success.')
+ elif(r == True):
+ print('wiki page updated.')
+ elif(f and f.faultCode == 'INVALID'):
+ print('auth failure')
+ elif(f and f.faultCode == 1):
+ print('wiki page not updated.')
+
+
+ page = '/'.join(['Documentation', version, 'DifferencesWithDebian'])
+ mc = get_wiki_mc(url, user, passwd)
+ mc.putPage(page, content)
+
+ results = mc()
+ try:
+ for r in results:
+ process_result(r)
+ except Fault as f:
+ result_process(None, f)
+
+
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version', version=__version__)
diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py
index 22f8a48..a8bac94 100644
--- a/tests/test_gd_diff.py
+++ b/tests/test_gd_diff.py
@@ -11,6 +11,10 @@ import json
import os
import subprocess
import sys
+import time
+import xmlrpc.client
+
+import requests
import gd_diff
@@ -470,6 +474,47 @@ class TestGdDiff(object):
assert wiki_page == gns_wiki_header() + '\n' + wiki_table
+ def test_push_wiki_page(self):
+ url = 'http://localhost:8080'
+ user = 's'
+ passw = 'gtzarko' # "get the zark out"; if you've been wondering.
+ version = '3'
+ content = 'test zarks! @ {}'.format(time.ctime())
+
+ # ensure moin server is running
+ try:
+ r = requests.get(url)
+ a = ''
+ if(r.status_code != 200):
+ return # skip testing
+ except requests.ConnectionError:
+ return # skip testing
+
+ # test
+ expected_barfs = [
+ 'auth success.', 'wiki page updated.',
+ 'auth success.', 'wiki page not updated.',
+ 'auth failure',
+ 'auth failure'
+ ]
+ barfs = []
+ with mock.patch('sys.stdout', new=StringIO()) as output:
+ try:
+ # success
+ push_wiki_page(url, user, passw, version, content)
+ # another success
+ push_wiki_page(url, user, passw, version, content)
+ # auth error
+ push_wiki_page(url, 'z', passw, version, content)
+ # auth error
+ push_wiki_page(url, user, 'zark_out', version, content)
+ barfs = output.getvalue().strip('\n').split('\n')
+ except SystemExit:
+ return # zark it. wiki has disabled xmlrpc.
+
+ assert barfs == expected_barfs
+
+
def test_get_args_gd_diff_version(self):
mock_sys_argv = ['gd-diff', '--version']
with mock.patch('sys.stdout', new=StringIO()) as output, \