gns-deb-diff

automate the documentation of the differences between gNewSense and Debian.
git clone git://git.ricketyspace.net/gns-deb-diff.git
Log | Files | Refs

commit d35105f158819f0f731a4efc7e138905ef8e627d
parent e46931f435cf00f1d70a6a6ccb755b92b7eff441
Author: rsiddharth <s@ricketyspace.net>
Date:   Fri,  6 Jan 2017 03:30:03 +0000

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.

Diffstat:
gd_diff.py | 49+++++++++++++++++++++++++++++++++++++++++++++++++
tests/test_gd_diff.py | 45+++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 94 insertions(+), 0 deletions(-)

diff --git 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 @@ -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, \