Index: trunk/wiki/wikiation/wikiation_exttest/examples/out2.xml |
— | — | @@ -0,0 +1,39 @@ |
| 2 | +<?xml version="1.0"?> |
| 3 | +<exttests> |
| 4 | +<exttest> |
| 5 | + <name>{{SERVER}} directive</name> |
| 6 | + <code><![CDATA[{{SERVER}} yet another test]]></code> |
| 7 | + <expect><![CDATA[<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></expect> |
| 8 | + <result><![CDATA[<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></result> |
| 9 | + <diff><![CDATA[ <a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></diff> |
| 10 | +</exttest> |
| 11 | +<exttest> |
| 12 | + <name>plain text 2000</name> |
| 13 | + <code><![CDATA[tset: a deliberate spelling error]]></code> |
| 14 | + <expect><![CDATA[test: a deliberate spelling error, and more text]]></expect> |
| 15 | +</exttest> |
| 16 | +<exttest> |
| 17 | + <name>normal wikilink</name> |
| 18 | + <code><![CDATA[[[hello]]]]></code> |
| 19 | + <expect><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>]]></expect> |
| 20 | +</exttest> |
| 21 | +<exttest> |
| 22 | + <name>normal wikilink with pipe</name> |
| 23 | + <code><![CDATA[[[hello|more]]]]></code> |
| 24 | + <expect><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></expect> |
| 25 | + <result><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></result> |
| 26 | + <diff><![CDATA[ <a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></diff> |
| 27 | +</exttest> |
| 28 | +<exttest> |
| 29 | + <name>plain text</name> |
| 30 | + <code><![CDATA[tets: a deliberate spelling error.]]></code> |
| 31 | + <expect><![CDATA[test: a deliberate spelling error, and more text]]></expect> |
| 32 | + <result><![CDATA[tets: a deliberate spelling error.]]></result> |
| 33 | + <diff><![CDATA[- tets: a deliberate spelling error. |
| 34 | +? - ^ |
| 35 | + |
| 36 | ++ test: a deliberate spelling error, and more text |
| 37 | +? + ^^^^^^^^^^^^^^^ |
| 38 | +]]></diff> |
| 39 | +</exttest> |
| 40 | +</exttests> |
Index: trunk/wiki/wikiation/wikiation_exttest/examples/out3.xml |
— | — | @@ -0,0 +1,48 @@ |
| 2 | +<?xml version="1.0"?> |
| 3 | +<exttests> |
| 4 | +<exttest> |
| 5 | + <name>{{SERVER}} directive</name> |
| 6 | + <code><![CDATA[{{SERVER}} yet another test]]></code> |
| 7 | + <expect><![CDATA[<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></expect> |
| 8 | + <result><![CDATA[<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></result> |
| 9 | + <diff><![CDATA[ <a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></diff> |
| 10 | +</exttest> |
| 11 | +<exttest> |
| 12 | + <name>plain text 2000</name> |
| 13 | + <code><![CDATA[tset: a deliberate spelling error]]></code> |
| 14 | + <expect><![CDATA[test: a deliberate spelling error, and more text]]></expect> |
| 15 | + <result><![CDATA[tset: a deliberate spelling error]]></result> |
| 16 | + <diff><![CDATA[- tset: a deliberate spelling error |
| 17 | +? - |
| 18 | + |
| 19 | ++ test: a deliberate spelling error, and more text |
| 20 | +? + +++++++++++++++ |
| 21 | +]]></diff> |
| 22 | +</exttest> |
| 23 | +<exttest> |
| 24 | + <name>normal wikilink</name> |
| 25 | + <code><![CDATA[[[hello]]]]></code> |
| 26 | + <expect><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>]]></expect> |
| 27 | + <result><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>]]></result> |
| 28 | + <diff><![CDATA[ <a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>]]></diff> |
| 29 | +</exttest> |
| 30 | +<exttest> |
| 31 | + <name>normal wikilink with pipe</name> |
| 32 | + <code><![CDATA[[[hello|more]]]]></code> |
| 33 | + <expect><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></expect> |
| 34 | + <result><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></result> |
| 35 | + <diff><![CDATA[ <a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></diff> |
| 36 | +</exttest> |
| 37 | +<exttest> |
| 38 | + <name>plain text</name> |
| 39 | + <code><![CDATA[tets: a deliberate spelling error.]]></code> |
| 40 | + <expect><![CDATA[test: a deliberate spelling error, and more text]]></expect> |
| 41 | + <result><![CDATA[tets: a deliberate spelling error.]]></result> |
| 42 | + <diff><![CDATA[- tets: a deliberate spelling error. |
| 43 | +? - ^ |
| 44 | + |
| 45 | ++ test: a deliberate spelling error, and more text |
| 46 | +? + ^^^^^^^^^^^^^^^ |
| 47 | +]]></diff> |
| 48 | +</exttest> |
| 49 | +</exttests> |
Index: trunk/wiki/wikiation/wikiation_exttest/examples/example.xml |
— | — | @@ -0,0 +1,22 @@ |
| 2 | +<?xml version="1.0"?> |
| 3 | +<exttests> |
| 4 | + |
| 5 | + <exttest> |
| 6 | + <name>{{SERVER}} directive</name> |
| 7 | + <code>{{SERVER}} yet another test</code> |
| 8 | + <expect><![CDATA[<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></expect> |
| 9 | + </exttest> |
| 10 | + |
| 11 | + <exttest> |
| 12 | + <name>plain text</name> |
| 13 | + <code>test</code> |
| 14 | + <expect>test</expect> |
| 15 | + </exttest> |
| 16 | + |
| 17 | + <exttest> |
| 18 | + <name>normal wikilink</name> |
| 19 | + <code>[[hello]]</code> |
| 20 | + <expect><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>]]></expect> |
| 21 | + </exttest> |
| 22 | + |
| 23 | +</exttests> |
Index: trunk/wiki/wikiation/wikiation_exttest/examples/README |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +some of these files ahven't been upgraded to newer version of wikiation-webtest yet. |
| 3 | + |
| 4 | +use --dump-py and --dump-xml to generate your own example files |
Index: trunk/wiki/wikiation/wikiation_exttest/examples/out.py |
— | — | @@ -0,0 +1,7 @@ |
| 2 | +from exttest import * |
| 3 | +tests=[Test(name='''{{SERVER}} directive''', code='''{{SERVER}} yet another test''', expect='''<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test''', pageReference=PageReference(pageTitle='Testpage', startPosition=195, endPosition=511), diff=''' <a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test''', ok=True, result='''<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test''', enable=True), Test(name='''plain text''', code='''test: plain text''', expect='''test: plain text''', pageReference=PageReference(pageTitle='Testpage', startPosition=997, endPosition=1155), diff='''''', ok=None, result='''''', enable=False), Test(name='''plain text''', code='''tset: a deliberate spelling error''', expect='''test: a deliberate spelling error, and more text''', pageReference=PageReference(pageTitle='Testpage', startPosition=1419, endPosition=1626), diff='''''', ok=None, result='''''', enable=False), Test(name='''normal wikilink''', code='''[[hello]]''', expect='''<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>''', pageReference=PageReference(pageTitle='Testpage', startPosition=1976, endPosition=2212), diff='''''', ok=None, result='''''', enable=False), Test(name='''normal wikilink with pipe''', code='''[[hello|more]]''', expect='''<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>''', pageReference=PageReference(pageTitle='Testpage2', startPosition=8, endPosition=258), diff=''' <a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>''', ok=True, result='''<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>''', enable=True), Test(name='''plain text''', code='''tets: a deliberate spelling error.''', expect='''test: a deliberate spelling error, and more text''', pageReference=PageReference(pageTitle='Testpage3', startPosition=118, endPosition=326), diff='''- tets: a deliberate spelling error. |
| 4 | +? - ^ |
| 5 | + |
| 6 | ++ test: a deliberate spelling error, and more text |
| 7 | +? + ^^^^^^^^^^^^^^^ |
| 8 | +''', ok=False, result='''tets: a deliberate spelling error.''', enable=True)] |
Index: trunk/wiki/wikiation/wikiation_exttest/examples/example.py |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +#!/usr/bin/python |
| 3 | + |
| 4 | + |
| 5 | +from exttest import Test |
| 6 | + |
| 7 | + |
| 8 | +tests=[ |
| 9 | + Test( |
| 10 | + name="{{SERVER}} directive", |
| 11 | + code="{{SERVER}} yet another test", |
| 12 | + expect='<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test' |
| 13 | + ), |
| 14 | + Test( |
| 15 | + name="plain text", |
| 16 | + code="test", |
| 17 | + expect="test" |
| 18 | + ), |
| 19 | + Test( |
| 20 | + name="normal wikilink", |
| 21 | + code="[[hello]]", |
| 22 | + expect='<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>' |
| 23 | + ) |
| 24 | +] |
| 25 | + |
Index: trunk/wiki/wikiation/wikiation_exttest/examples/out.xml |
— | — | @@ -0,0 +1,50 @@ |
| 2 | +<?xml version="1.0"?> |
| 3 | +<tests> |
| 4 | +<test> |
| 5 | + <name>{{SERVER}} directive</name> |
| 6 | + <code><![CDATA[{{SERVER}} yet another test]]></code> |
| 7 | + <expect><![CDATA[<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></expect> |
| 8 | + <result><![CDATA[<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></result> |
| 9 | + <diff><![CDATA[ <a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></diff> |
| 10 | +</test> |
| 11 | +<test> |
| 12 | + <name>plain text</name> |
| 13 | + <code><![CDATA[test: plain text]]></code> |
| 14 | + <expect><![CDATA[test: plain text]]></expect> |
| 15 | + <result><![CDATA[]]></result> |
| 16 | + <diff><![CDATA[]]></diff> |
| 17 | +</test> |
| 18 | +<test> |
| 19 | + <name>plain text</name> |
| 20 | + <code><![CDATA[tset: a deliberate spelling error]]></code> |
| 21 | + <expect><![CDATA[test: a deliberate spelling error, and more text]]></expect> |
| 22 | + <result><![CDATA[]]></result> |
| 23 | + <diff><![CDATA[]]></diff> |
| 24 | +</test> |
| 25 | +<test> |
| 26 | + <name>normal wikilink</name> |
| 27 | + <code><![CDATA[[[hello]]]]></code> |
| 28 | + <expect><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>]]></expect> |
| 29 | + <result><![CDATA[]]></result> |
| 30 | + <diff><![CDATA[]]></diff> |
| 31 | +</test> |
| 32 | +<test> |
| 33 | + <name>normal wikilink with pipe</name> |
| 34 | + <code><![CDATA[[[hello|more]]]]></code> |
| 35 | + <expect><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></expect> |
| 36 | + <result><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></result> |
| 37 | + <diff><![CDATA[ <a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">more</a>]]></diff> |
| 38 | +</test> |
| 39 | +<test> |
| 40 | + <name>plain text</name> |
| 41 | + <code><![CDATA[tets: a deliberate spelling error.]]></code> |
| 42 | + <expect><![CDATA[test: a deliberate spelling error, and more text]]></expect> |
| 43 | + <result><![CDATA[tets: a deliberate spelling error.]]></result> |
| 44 | + <diff><![CDATA[- tets: a deliberate spelling error. |
| 45 | +? - ^ |
| 46 | + |
| 47 | ++ test: a deliberate spelling error, and more text |
| 48 | +? + ^^^^^^^^^^^^^^^ |
| 49 | +]]></diff> |
| 50 | +</test> |
| 51 | +</tests> |
Index: trunk/wiki/wikiation/wikiation_exttest/logintest.py |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +#!/usr/bin/python |
| 3 | + |
| 4 | +#This software, copyright (C) 2008-2009 by Wikiation. |
| 5 | +# This software is developed by Kim Bruning. |
| 6 | +# |
| 7 | +# Distributed under the terms of the MIT license. |
| 8 | + |
| 9 | +# Logintest: a quick test of logindata |
| 10 | + |
| 11 | +import logindata |
| 12 | + |
| 13 | +l=logindata.LoginData( |
| 14 | + name='6Basic', |
| 15 | + protocol='http', |
| 16 | + server='6.wikiation.nl', |
| 17 | + scriptpath='/revisions/REL1_13_2', |
| 18 | + version='1.13.2', |
| 19 | + lang='en', |
| 20 | + user='------', |
| 21 | + password='-------' |
| 22 | + ) |
| 23 | + |
| 24 | +site=l.login() |
| 25 | +print site |
| 26 | +page=logindata.wikipedia.Page(site,'Hello World') |
| 27 | + |
| 28 | +page.put("hello world\n"); |
Property changes on: trunk/wiki/wikiation/wikiation_exttest/logintest.py |
___________________________________________________________________ |
Added: svn:executable |
1 | 29 | + |
Index: trunk/wiki/wikiation/wikiation_exttest/testpages/Testpage |
— | — | @@ -0,0 +1,37 @@ |
| 2 | +This is a test page. |
| 3 | +Let's also add xml and see what happens. |
| 4 | + |
| 5 | +<pre> |
| 6 | + |
| 7 | + <exttest> |
| 8 | + <name>{{SERVER}} directive</name> |
| 9 | + <code>{{SERVER}} yet another test</code> |
| 10 | + <expect><![CDATA[<a href="http://83.149.110.226" class="external free" title="http://83.149.110.226" rel="nofollow">http://83.149.110.226</a> yet another test]]></expect> |
| 11 | + </exttest> |
| 12 | + |
| 13 | +<extresult></extresult> |
| 14 | + |
| 15 | +</pre> |
| 16 | +some odd text in between |
| 17 | + |
| 18 | +<pre> |
| 19 | + <exttest> |
| 20 | + <name>plain text</name> |
| 21 | + <code>test</code> |
| 22 | + <expect>test</expect> |
| 23 | + </exttest> |
| 24 | +<extresult></extresult> |
| 25 | + |
| 26 | + |
| 27 | + <exttest> |
| 28 | + <name>normal wikilink</name> |
| 29 | + <code>[[hello]]</code> |
| 30 | + <expect><![CDATA[<a href="https://www.mediawiki.org/index.php?title=Hello&action=edit" class="new" title="Hello">hello</a>]]></expect> |
| 31 | + </exttest> |
| 32 | + |
| 33 | +<extresult></extresult> |
| 34 | +</pre> |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +[[Category:automated tests]] |
Index: trunk/wiki/wikiation/wikiation_exttest/settings.py.example |
— | — | @@ -0,0 +1,61 @@ |
| 2 | +# This software, copyright (C) 2008-2009 by Wikiation. |
| 3 | +# This software is developed by Kim Bruning. |
| 4 | +# |
| 5 | +# Distributed under the terms of the MIT license |
| 6 | + |
| 7 | + |
| 8 | +#Settings file for wikiation_webtest |
| 9 | +import os |
| 10 | + |
| 11 | +# path to pywikipedia |
| 12 | +#(calculated, in this case) |
| 13 | +pywikipedia_path=os.path.join(os.path.dirname(__file__),'..','pywikipedia') |
| 14 | + |
| 15 | +from logindata import LoginData |
| 16 | + |
| 17 | +# How many tests per page should be permitted? |
| 18 | +# (wikiation wants to hardlimit this to 1 only) |
| 19 | +# (0 = infinite) |
| 20 | +tests_per_page=1 |
| 21 | + |
| 22 | +#What is the default category name? |
| 23 | +category_name="Automated tests" |
| 24 | + |
| 25 | +# Trim spaces in elements. |
| 26 | +# Certain people introduce spurious whitespace, even in CDATA. ARGH! |
| 27 | +# If you cannot smite such infidels, turn on this flag instead to strip |
| 28 | +# their whitespace. |
| 29 | +# I'm not sure that this is the canonical behaviour. O:-) |
| 30 | +strip_whitespace=True |
| 31 | + |
| 32 | + |
| 33 | +# site information |
| 34 | + |
| 35 | +# wiki to read testcases from, and write reports to |
| 36 | +# (logically not used if reading tests from file) |
| 37 | +source_login=LoginData( |
| 38 | + name='test_source', |
| 39 | + protocol='http', |
| 40 | + server='6.wikiation.nl', |
| 41 | + scriptpath='/revisions/REL1_13_2', |
| 42 | + lang='en', |
| 43 | + encoding='utf-8', |
| 44 | + user='---------', |
| 45 | + password='--------' |
| 46 | + ) |
| 47 | + |
| 48 | +# wiki to actually run the test on. |
| 49 | +target_login=LoginData( |
| 50 | + name='test_target', |
| 51 | + protocol='http', |
| 52 | + server='6.wikiation.nl', |
| 53 | + scriptpath='/revisions/exttest_target', |
| 54 | + lang='en', |
| 55 | + encoding='utf-8', |
| 56 | + user='---------', |
| 57 | + password='--------' |
| 58 | + ) |
| 59 | + |
| 60 | + |
| 61 | +#test page name (botTest is default |
| 62 | +pageName="Bot_test" |
Index: trunk/wiki/wikiation/wikiation_exttest/LICENSE |
— | — | @@ -0,0 +1,21 @@ |
| 2 | +This software, copyright (C) 2008-2009 by Wikiation. This software is developed by Kim Bruning. |
| 3 | + |
| 4 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +of this software and associated documentation files (the "Software"), to deal |
| 6 | +in the Software without restriction, including without limitation the rights to |
| 7 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 8 | +of the Software, and to permit persons to whom the Software is furnished to do |
| 9 | +so, subject to the following conditions: |
| 10 | + |
| 11 | +The above copyright notice and this permission notice shall be included in all |
| 12 | +copies or substantial portions of the Software. |
| 13 | + |
| 14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | +SOFTWARE. |
| 21 | + |
| 22 | + |
Index: trunk/wiki/wikiation/wikiation_exttest/base_family.py |
— | — | @@ -0,0 +1,85 @@ |
| 2 | +# -*- coding: utf-8 -*- # REQUIRED |
| 3 | +# This software, copyright (C) 2008-2009 by Wikiation. |
| 4 | +# This software is developed by Kim Bruning. |
| 5 | +# |
| 6 | +# Distributed under the terms of the MIT license. |
| 7 | + |
| 8 | + |
| 9 | +import sys, settings |
| 10 | +if settings.pywikipedia_path not in sys.path: |
| 11 | + sys.path.append(settings.pywikipedia_path) |
| 12 | + |
| 13 | +import config, family, urllib # REQUIRED |
| 14 | +class Family(family.Family): # REQUIRED |
| 15 | + """friendlier version of tghe pywikipedia family class. |
| 16 | + We can use this in conjunction with none-pywikipedia |
| 17 | + config files.""" |
| 18 | + def __init__(self, |
| 19 | + name='test', |
| 20 | + protocol='http', |
| 21 | + server='6.wikiation.nl', |
| 22 | + scriptpath='/revisions/REL1.13.2', |
| 23 | + version='1.13.2', |
| 24 | + lang='nl', |
| 25 | + encoding='utf-8', |
| 26 | + api_supported=False, |
| 27 | + RversionTab=None # very rare beast, you probably won't need it. |
| 28 | + ): |
| 29 | + |
| 30 | + family.Family.__init__(self) |
| 31 | + self.name = name # REQUIRED; replace with actual name |
| 32 | + |
| 33 | + self.langs = { # REQUIRED |
| 34 | + lang: server, # Include one line for each wiki in family |
| 35 | + } |
| 36 | + self._protocol=protocol |
| 37 | + self._scriptpath=scriptpath |
| 38 | + self._version=version |
| 39 | + self._encoding=encoding |
| 40 | + # may as well add these here, so we can have a 1 stop shop |
| 41 | + self._lang=lang |
| 42 | + self._server=server |
| 43 | + self._api_supported=api_supported |
| 44 | + self._RversionTab=RversionTab |
| 45 | + |
| 46 | + def protocol(self, code): |
| 47 | + """ |
| 48 | + Can be overridden to return 'https'. Other protocols are not supported. |
| 49 | + """ |
| 50 | + return self._protocol |
| 51 | + |
| 52 | + def scriptpath(self, code): |
| 53 | + """The prefix used to locate scripts on this wiki. |
| 54 | + |
| 55 | + This is the value displayed when you enter {{SCRIPTPATH}} on a |
| 56 | + wiki page (often displayed at [[Help:Variables]] if the wiki has |
| 57 | + copied the master help page correctly). |
| 58 | + |
| 59 | + The default value is the one used on Wikimedia Foundation wikis, |
| 60 | + but needs to be overridden in the family file for any wiki that |
| 61 | + uses a different value. |
| 62 | + |
| 63 | + """ |
| 64 | + return self._scriptpath |
| 65 | + |
| 66 | + # IMPORTANT: if your wiki does not support the api.php interface, |
| 67 | + # you must uncomment the second line of this method: |
| 68 | + def apipath(self, code): |
| 69 | + if self._api_supported: |
| 70 | + return '%s/api.php' % self.scriptpath(code) |
| 71 | + else: |
| 72 | + raise NotImplementedError, "%s wiki family does not support api.php" % self.name |
| 73 | + |
| 74 | + # Which version of MediaWiki is used? |
| 75 | + def version(self, code): |
| 76 | + # Replace with the actual version being run on your wiki |
| 77 | + return self._version |
| 78 | + |
| 79 | + def code2encoding(self, code): |
| 80 | + """Return the encoding for a specific language wiki""" |
| 81 | + # Most wikis nowadays use UTF-8, but change this if yours uses |
| 82 | + # a different encoding |
| 83 | + return self._encoding |
| 84 | + |
| 85 | + def RversionTab(self, code): |
| 86 | + return self._RversionTab |
Index: trunk/wiki/wikiation/wikiation_exttest/wikiation_exttest.py |
— | — | @@ -0,0 +1,471 @@ |
| 2 | +#!/usr/bin/python |
| 3 | +# -*- coding: utf-8 -*- |
| 4 | + |
| 5 | +# This software, copyright (C) 2008-2009 by Wikiation. |
| 6 | +# This software is developed by Kim Bruning. |
| 7 | +# |
| 8 | +# Distributed under the terms of the MIT license |
| 9 | + |
| 10 | +import sys,os |
| 11 | +import settings |
| 12 | + |
| 13 | +sys.path.append(settings.pywikipedia_path) |
| 14 | +cwd=os.getcwd() |
| 15 | +os.chdir(settings.pywikipedia_path) |
| 16 | +import wikipedia |
| 17 | +import login |
| 18 | +import catlib |
| 19 | +os.chdir(cwd) |
| 20 | + |
| 21 | +import difflib |
| 22 | +import imp |
| 23 | +from exttest import Test, PageReference |
| 24 | +from xml.etree import ElementTree |
| 25 | + |
| 26 | + |
| 27 | +class MissingDataException (Exception): |
| 28 | + pass |
| 29 | + |
| 30 | +class WikiWebTest: |
| 31 | + """ |
| 32 | + Run extension tests on a mediawiki wiki. |
| 33 | + """ |
| 34 | + |
| 35 | + """open marker for test sequence , must be long and unique""" |
| 36 | + open=u"---START of wikiation test sequence---" |
| 37 | + """close marker for test sequence, must be long and unique""" |
| 38 | + close=u"---END of wikiation test sequence---" |
| 39 | + |
| 40 | + |
| 41 | + def __init__ (self,site): |
| 42 | + self.site=site |
| 43 | + self.html=None |
| 44 | + |
| 45 | + def feedWikiText (self,wikitext, pageName="Bot_test"): |
| 46 | + """feed wikitext to the server, and get html back""" |
| 47 | + |
| 48 | + #make a new page with just the wikitext |
| 49 | + page=wikipedia.Page(self.site, pageName) |
| 50 | + page.put(wikitext) |
| 51 | + |
| 52 | + #get raw html for the page back |
| 53 | + address=self.site.get_address(pageName) |
| 54 | + html=self.site.getUrl(address) |
| 55 | + |
| 56 | + return html |
| 57 | + |
| 58 | + |
| 59 | + def genTest(self,codeToBeTested): |
| 60 | + """enclose codeToBeTested in test sequence""" |
| 61 | + |
| 62 | + if codeToBeTested==None: |
| 63 | + raise MissingDataException("code to be tested is Null"); |
| 64 | + |
| 65 | + testCode=WikiWebTest.open+codeToBeTested+WikiWebTest.close |
| 66 | + |
| 67 | + return testCode |
| 68 | + |
| 69 | + |
| 70 | + def cleanFeed(self,codeToBeTested, pageName="Bot_test"): |
| 71 | + """like feedWikiText, but return just the bit we're actually |
| 72 | + interested in""" |
| 73 | + |
| 74 | + testCode=self.genTest(codeToBeTested) |
| 75 | + html=self.feedWikiText(testCode,pageName) |
| 76 | + enclosedHtml=self.getEnclosed(html) |
| 77 | + |
| 78 | + self.html=html |
| 79 | + return enclosedHtml |
| 80 | + |
| 81 | + |
| 82 | + def getEnclosed(self,html): |
| 83 | + """pull the code-of-interest out from between the open and close markers""" |
| 84 | + |
| 85 | + startOpen=html.index(WikiWebTest.open) |
| 86 | + start=startOpen+len(WikiWebTest.open) |
| 87 | + |
| 88 | + end=html.index(WikiWebTest.close) |
| 89 | + |
| 90 | + return html[start:end] |
| 91 | + |
| 92 | + |
| 93 | + def test(self, wikiText, expectHtml, test=None, pageName="Bot_test"): |
| 94 | + """do the test, report comparison as plain text for now |
| 95 | + I tried the htmltable, but mediawiki refuses to eat it :-/""" |
| 96 | + |
| 97 | + actualHtml=self.cleanFeed(wikiText, pageName) |
| 98 | + |
| 99 | + actualHtmlLines=actualHtml.splitlines(1); |
| 100 | + expectHtmlLines=expectHtml.splitlines(1); |
| 101 | + |
| 102 | + differ=difflib.Differ() |
| 103 | + diff_text_list= list(differ.compare(actualHtmlLines,expectHtmlLines)) |
| 104 | + diff_text="\n".join(diff_text_list) |
| 105 | + |
| 106 | + if test: |
| 107 | + if actualHtml==expectHtml: |
| 108 | + test.ok=True |
| 109 | + |
| 110 | + if actualHtml!=expectHtml: |
| 111 | + test.ok=False |
| 112 | + |
| 113 | + test.diff=diff_text |
| 114 | + test.result=actualHtml |
| 115 | + |
| 116 | + return diff_text |
| 117 | + |
| 118 | +def _title(title): |
| 119 | + """ |
| 120 | + ----------------------- |
| 121 | + | make a pretty title | |
| 122 | + ----------------------- |
| 123 | + """ |
| 124 | + titlerow='| '+title+' |' |
| 125 | + stripe="\n"+( "-"*len(titlerow) )+"\n" |
| 126 | + return stripe+titlerow+stripe |
| 127 | + |
| 128 | +def runtestset(webtest, tests, pageName=None) : |
| 129 | + """Take a List of Test-s, and feed them to WikiWebTest to run them""" |
| 130 | + |
| 131 | + if pageName==None: |
| 132 | + pageName=settings.pageName |
| 133 | + |
| 134 | + for test in tests: |
| 135 | + |
| 136 | + print _title(test.name+' :') |
| 137 | + if test.enable: |
| 138 | + diff=webtest.test(test.code, test.expect, test, pageName) |
| 139 | + print unicode(diff).encode('utf8') |
| 140 | + if test.ok: |
| 141 | + print "\n--OK!\n" |
| 142 | + elif test.known_bug: |
| 143 | + print "\n--OK, known bug.\n" |
| 144 | + else: |
| 145 | + print "\n--FAIL\n" |
| 146 | + else: |
| 147 | + print "test not enabled\n" |
| 148 | + |
| 149 | + |
| 150 | + print _title("TESTSET COMPLETED") |
| 151 | + |
| 152 | + |
| 153 | +def _isCommented(text,offset,tagstart): |
| 154 | + """ |
| 155 | + For a given position in a string, determine if it is located |
| 156 | + in a comment block. Used here to check whether <exttest> or |
| 157 | + </exttest> is located inside a comment. |
| 158 | + 'text' is the text to check, |
| 159 | + 'offset' is the offset from start of string. |
| 160 | + 'tagstart' is the position to check (start of our tag) |
| 161 | + """ |
| 162 | + endcommentp=0 |
| 163 | + while True: |
| 164 | + commentp=text.find("<!--",offset,tagstart) |
| 165 | + if commentp!=-1: |
| 166 | + endcommentp=text.find("-->",commentp,tagstart) |
| 167 | + if endcommentp==-1: |
| 168 | + break |
| 169 | + offset=endcommentp+len("-->") |
| 170 | + else: |
| 171 | + break |
| 172 | + |
| 173 | + return endcommentp==-1 |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +def article2testset(article): |
| 178 | + """parse a pywikipedia Page (article), to yield a testset""" |
| 179 | + text=article.get() |
| 180 | + testset=[] |
| 181 | + count=0 |
| 182 | + offset=0 |
| 183 | + while True: |
| 184 | + startPosition=text.find("<exttest>",offset) |
| 185 | + if startPosition==-1: |
| 186 | + break |
| 187 | + |
| 188 | + if _isCommented(text,offset,startPosition): |
| 189 | + offset=startPosition+1 |
| 190 | + continue |
| 191 | + |
| 192 | + endTagPosition=text.find("</exttest>",offset) |
| 193 | + |
| 194 | + if endTagPosition==-1: |
| 195 | + raise Exception("malformed xml in page "+str(article)) |
| 196 | + |
| 197 | + if _isCommented(text,offset,endTagPosition): |
| 198 | + offset=endTagPosition+1 |
| 199 | + continue |
| 200 | + |
| 201 | + endPosition=endTagPosition+len("</exttest>") |
| 202 | + |
| 203 | + xmlString=text[startPosition:endPosition] |
| 204 | + try: |
| 205 | + test=xml2testset(unicode(xmlString).encode('utf8')) |
| 206 | + except Exception, e: |
| 207 | + raise Exception("Problem loading page [["+article.title()+"]]: ",e) |
| 208 | + test[0].pageReference=PageReference( |
| 209 | + pageTitle=article.title(), |
| 210 | + startPosition=startPosition, |
| 211 | + endPosition=endPosition) |
| 212 | + count+=1 |
| 213 | + if settings.tests_per_page!=0 and count>settings.tests_per_page: |
| 214 | + test[0].enable=False |
| 215 | + |
| 216 | + testset+=test |
| 217 | + |
| 218 | + offset=endPosition |
| 219 | + |
| 220 | + return testset |
| 221 | + |
| 222 | +def tests2page(tests, site, pageTitle): |
| 223 | + """Write a test report back to a wikipage. |
| 224 | + Only operates between <extresult></extresult> tags; |
| 225 | + this way, if something goes wrong, hopefully we won't |
| 226 | + b0rk the _entire_ page. |
| 227 | + tests is the tests relevant to this page, site is the pywikipedia |
| 228 | + site object for this website, and pageTitle is the title of the |
| 229 | + page on the site.""" |
| 230 | + page=wikipedia.Page(site,pageTitle) |
| 231 | + text=page.get() |
| 232 | + offset=0 |
| 233 | + for test in tests: |
| 234 | + ref=test.pageReference |
| 235 | + |
| 236 | + s=text.find("<extresult>",ref.endPosition+offset) |
| 237 | + startPosition=s+len("<extresult>") |
| 238 | + endPosition=text.find("</extresult>",startPosition) |
| 239 | + if s!=-1 and endPosition!=-1: |
| 240 | + before=text[:startPosition] |
| 241 | + middle="\n<!-- BOT OUTPUT-->\n;Result " |
| 242 | + if test.ok: |
| 243 | + middle+='<span style="color:green">OK</span>' |
| 244 | + elif test.ok==False: |
| 245 | + if test.known_bug: |
| 246 | + middle+='<span style="color:yellow">Known Bug</span>' |
| 247 | + else: |
| 248 | + middle+='<span style="color:red">Differs from expected</span>' |
| 249 | + else: |
| 250 | + middle+='<span style="color:orange">unknown</span>' |
| 251 | + if test.enable: |
| 252 | + middle+="\n;html output\n" |
| 253 | + middle+="<pre>\n"+test.result+"\n</pre>" |
| 254 | + middle+="\n;diff\n" |
| 255 | + middle+="<pre>\n"+test.diff+"</pre>" |
| 256 | + else: |
| 257 | + middle+="\n;Only "+str(settings.tests_per_page)+" tests are allowed per page" |
| 258 | + middle+="\n<!-- END OF BOT OUTPUT-->\n" |
| 259 | + after=text[endPosition:] |
| 260 | + text=before+middle+after |
| 261 | + offset+=len(middle)-(endPosition-startPosition) |
| 262 | + |
| 263 | + page.put(text,"testresult") |
| 264 | + |
| 265 | +def testset2pages(testset, site): |
| 266 | + """Goes through testset, and writes results back to each page |
| 267 | + on the pywikipedia site. |
| 268 | + In the case case where multiple tests per page are permitted, |
| 269 | + testset results are grouped by page, so that only 1 write |
| 270 | + needs to be done per page.""" |
| 271 | + byPage={} |
| 272 | + # reorganize tests by page so we can |
| 273 | + # do a page at a time |
| 274 | + for test in testset: |
| 275 | + title=test.pageReference.pageTitle |
| 276 | + if title not in byPage: |
| 277 | + byPage[title]=[] |
| 278 | + byPage[title].append(test) |
| 279 | + |
| 280 | + for title, tests in byPage.iteritems(): |
| 281 | + tests2page(tests, site, title) |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | +def category2testset(site,categoryName="Automated tests"): |
| 286 | + """Scan a category on the given pywikipedia site for valid |
| 287 | + extension tests, and generate a testset (a list of Test objects)""" |
| 288 | + category=catlib.Category(site,categoryName) |
| 289 | + testset=[] |
| 290 | + for article in category.articles(): |
| 291 | + testset+=article2testset(article) |
| 292 | + |
| 293 | + return testset |
| 294 | + |
| 295 | +def runcategorytestset(source_site, webtest, categoryName="Automated tests"): |
| 296 | + """Scan a category for valid extension tests, |
| 297 | + and run all the tests using the webtest object.""" |
| 298 | + testset=category2testset(source_site,categoryName) |
| 299 | + runtestset(webtest,testset) |
| 300 | + |
| 301 | + return testset |
| 302 | + |
| 303 | +def runcategoryandreport(source_site, webtest, categoryName="Automated tests"): |
| 304 | + """Scan a category for valid extension tests, |
| 305 | + run all the tests using the webtest object, and report |
| 306 | + the results back to the relevant pages on the wiki. |
| 307 | + """ |
| 308 | + testset=runcategorytestset(source_site, webtest, categoryName) |
| 309 | + testset2pages(testset, source_site) |
| 310 | + return testset |
| 311 | + |
| 312 | +def _elementText(element,tag): |
| 313 | + """find the relevant element contents in an elementtree element, |
| 314 | + and strip spurious whitespace from the ends if settings.strip_whitespace |
| 315 | + is set""" |
| 316 | + text=element.findtext(tag) |
| 317 | + #This strips spurious whitespace from CDATA, due to users inserting it. |
| 318 | + #ick. |
| 319 | + if text and settings.strip_whitespace: |
| 320 | + text=text.strip() |
| 321 | + return text |
| 322 | + |
| 323 | +def xml2testset(xmlString): |
| 324 | + """converts xml string to a testset (a list of Test objects). |
| 325 | + Next to xml that actually contains a testset (obviously), this function |
| 326 | + will also eat an xml string containing only a single exttest element |
| 327 | + (intended for internal use only, ymmv). If settings.strip_whitespace |
| 328 | + is set, spurious whitespace will be stripped from the start and end of |
| 329 | + the element contents, even inside CDATA!""" |
| 330 | + if not xmlString: |
| 331 | + raise Exception("xml2testset: Empty xmlString.") |
| 332 | + tests=[] |
| 333 | + elements=ElementTree.XML(xmlString) |
| 334 | + for testElement in elements.getiterator("exttest"): |
| 335 | + test=Test() |
| 336 | + test.name=_elementText(testElement, "name") |
| 337 | + test.code=_elementText(testElement, "code") |
| 338 | + test.expect=_elementText(testElement,"expect") |
| 339 | + test.result=_elementText(testElement, "result") |
| 340 | + test.diff=_elementText(testElement, "diff") |
| 341 | + if testElement.find("known_bug") is not None: |
| 342 | + test.known_bug=True |
| 343 | + |
| 344 | + if not test.name: |
| 345 | + print "WARNING: <name> element missing" |
| 346 | + if not test.expect: |
| 347 | + print "WARNING:", |
| 348 | + if test.name: |
| 349 | + print "in "+test.name+":", |
| 350 | + print " <expect> element missing" |
| 351 | + |
| 352 | + if test.code: |
| 353 | + tests.append(test) |
| 354 | + else: |
| 355 | + report="" |
| 356 | + if test.name: |
| 357 | + report+="In"+test.name+" " |
| 358 | + else: |
| 359 | + report+="In <unnamed test>: (<name> element missing or left blank, so reports might be unclear)" |
| 360 | + if not test.code: |
| 361 | + report +="; missing <code> element (required)" |
| 362 | + if not test.expect: |
| 363 | + report +="; missing <expect> element (not required, but typically recommended)" |
| 364 | + report +="." |
| 365 | + raise MissingDataException(report) |
| 366 | + |
| 367 | + return tests |
| 368 | + |
| 369 | +def runxmltestset(webtest, xmlstring): |
| 370 | + """Take a testset defined in xml format and run it with WikiWebtest |
| 371 | + webtest""" |
| 372 | + testset=xml2testset(xmlstring) |
| 373 | + runtestset(webtest,testset) |
| 374 | + return testset |
| 375 | + |
| 376 | +def dumppy(testset,filename): |
| 377 | + """write testset to file in python .py format. |
| 378 | + This file can be import-ed normally in python to obtain |
| 379 | + the testset contents. |
| 380 | + Note that the file has test.py as a dependency (in case you |
| 381 | + want to ship it elsewhere).""" |
| 382 | + f=file(filename,"w") |
| 383 | + f.write("from exttest import *\n") |
| 384 | + f.write("tests="+repr(testset)) |
| 385 | + f.close() |
| 386 | + |
| 387 | +def dumpxml(testset,filename): |
| 388 | + """write testset to file in xml format.""" |
| 389 | + xml='<?xml version="1.0"?>\n' |
| 390 | + xml+="<exttests>\n" |
| 391 | + for test in testset: |
| 392 | + xml+=test.toXML() |
| 393 | + xml+="</exttests>\n" |
| 394 | + f=file(filename,"w") |
| 395 | + f.write(xml) |
| 396 | + f.close() |
| 397 | + |
| 398 | +def do_login(site_language, site_name, site_password): |
| 399 | + raise Exception("do_login is Deprecated. Use LoginData instead") |
| 400 | + |
| 401 | +def main(): |
| 402 | + testset=[] |
| 403 | + category_name=settings.category_name |
| 404 | + allOk=False |
| 405 | + |
| 406 | + if "--category-name" in sys.argv: |
| 407 | + category_name=sys.argv[ sys.argv.index("--category-name")+1] |
| 408 | + allOk=True |
| 409 | + if "--pyfile" in sys.argv: |
| 410 | + target_site=settings.target_login.login() |
| 411 | + webtest=WikiWebTest(target_site) |
| 412 | + filename=sys.argv[ sys.argv.index("--pyfile")+1] |
| 413 | + print "loading '"+filename+"'" |
| 414 | + testmodule=imp.load_source("testmodule",filename) |
| 415 | + tests=testmodule.tests |
| 416 | + testset=runtestset(webtest,tests) |
| 417 | + allOk=True |
| 418 | + elif "--xmlfile" in sys.argv: |
| 419 | + target_site=settings.target_login.login() |
| 420 | + webtest=WikiWebTest(target_site) |
| 421 | + filename=sys.argv[ sys.argv.index("--xmlfile")+1] |
| 422 | + print "loading '"+filename+"'" |
| 423 | + xmlfile=file(filename) |
| 424 | + xmlstring=xmlfile.read() |
| 425 | + xmlfile.close() |
| 426 | + testset=runxmltestset(webtest, xmlstring) |
| 427 | + allOk=True |
| 428 | + elif "--category" in sys.argv: |
| 429 | + print "testing category" |
| 430 | + |
| 431 | + source_site=settings.source_login.login() |
| 432 | + target_site=settings.target_login.login() |
| 433 | + webtest=WikiWebTest(target_site) |
| 434 | + testset=runcategorytestset(source_site, webtest, category_name) |
| 435 | + allOk=True |
| 436 | + elif "--category-and-write" in sys.argv: |
| 437 | + print "running cat and writing back to the wiki" |
| 438 | + source_site=settings.source_login.login() |
| 439 | + target_site=settings.target_login.login() |
| 440 | + webtest=WikiWebTest(target_site) |
| 441 | + testset=runcategoryandreport(source_site, webtest, category_name) |
| 442 | + allOk=True |
| 443 | + elif "--test" in sys.argv: |
| 444 | + print webtest.test("{{SERVER}} yet another test","<a something> yet another test") |
| 445 | + allOk=True |
| 446 | + elif "--help" in sys.argv: |
| 447 | + print file("HELP").read() |
| 448 | + allOk=True |
| 449 | + |
| 450 | + if "--dump-xml" in sys.argv: |
| 451 | + filename=sys.argv[ sys.argv.index("--dump-xml")+1] |
| 452 | + print "saving xml to '"+filename+"'." |
| 453 | + dumpxml(testset,filename) |
| 454 | + allOk=True |
| 455 | + |
| 456 | + if "--dump-py" in sys.argv: |
| 457 | + filename=sys.argv[ sys.argv.index("--dump-py")+1] |
| 458 | + print "saving py to '"+filename+"'." |
| 459 | + dumppy(testset,filename) |
| 460 | + allOk=True |
| 461 | + |
| 462 | + if not allOk: |
| 463 | + print "I don't understand. Try --help for help?" |
| 464 | + |
| 465 | + |
| 466 | +if __name__=="__main__": |
| 467 | + try: |
| 468 | + main() |
| 469 | + finally: |
| 470 | + wikipedia.stopme() |
| 471 | + |
| 472 | + |
Property changes on: trunk/wiki/wikiation/wikiation_exttest/wikiation_exttest.py |
___________________________________________________________________ |
Added: svn:executable |
1 | 473 | + |
Index: trunk/wiki/wikiation/wikiation_exttest/some.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/wiki/wikiation/wikiation_exttest/some.png |
___________________________________________________________________ |
Added: svn:mime-type |
2 | 474 | + application/octet-stream |
Index: trunk/wiki/wikiation/wikiation_exttest/exttest.py |
— | — | @@ -0,0 +1,68 @@ |
| 2 | +# This software, copyright (C) 2008-2009 by Wikiation. |
| 3 | +# This software is developed by Kim Bruning. |
| 4 | +# |
| 5 | +# Distributed under the terms of the MIT license. |
| 6 | + |
| 7 | +class Test: |
| 8 | + name="" |
| 9 | + code="" |
| 10 | + expect="" |
| 11 | + pageReference=None |
| 12 | + diff="" |
| 13 | + ok=None |
| 14 | + result="" |
| 15 | + enable=True |
| 16 | + known_bug=False |
| 17 | + |
| 18 | + |
| 19 | + def __init__(self, name="", code="", expect="", pageReference=None, diff="", result="", ok=None, enable=True, known_bug=False): |
| 20 | + self.name=name |
| 21 | + self.code=code |
| 22 | + self.expect=expect |
| 23 | + self.pageReference=None |
| 24 | + self.diff=diff |
| 25 | + self.result=result |
| 26 | + self.ok=ok |
| 27 | + self.enable=enable |
| 28 | + self.known_bug=known_bug |
| 29 | + |
| 30 | + def __repr__(self): |
| 31 | + return "Test(name='''"+self.name+\ |
| 32 | + "''', code='''"+self.code+\ |
| 33 | + "''', expect='''"+self.expect+\ |
| 34 | + "''', pageReference="+repr(self.pageReference)+\ |
| 35 | + ", diff='''"+self.diff+\ |
| 36 | + "''', ok="+str(self.ok)+\ |
| 37 | + ", result='''"+self.result+\ |
| 38 | + "''', enable="+str(self.enable)+\ |
| 39 | + ", known_bug="+str(self.known_bug)+\ |
| 40 | + ")" |
| 41 | + |
| 42 | + def toXML(self): |
| 43 | + xml="<exttest>\n" |
| 44 | + xml+=" <name>"+self.name+"</name>\n" |
| 45 | + xml+=" <code><![CDATA["+self.code+"]]></code>\n" |
| 46 | + xml+=" <expect><![CDATA["+self.expect+"]]></expect>\n" |
| 47 | + if self.result: |
| 48 | + xml+=" <result><![CDATA["+self.result+"]]></result>\n" |
| 49 | + if self.diff: |
| 50 | + xml+=" <diff><![CDATA["+self.diff+"]]></diff>\n" |
| 51 | + if self.known_bug: |
| 52 | + xml+=" <known bug/>" |
| 53 | + xml+="</exttest>\n" |
| 54 | + return xml |
| 55 | + |
| 56 | +class PageReference: |
| 57 | + startPosition=0 |
| 58 | + endPosition=0 |
| 59 | + pageTitle="" |
| 60 | + |
| 61 | + def __init__(self, pageTitle="", startPosition=0, endPosition=0): |
| 62 | + self.pageTitle=pageTitle |
| 63 | + self.startPosition=startPosition |
| 64 | + self.endPosition=endPosition |
| 65 | + |
| 66 | + def __repr__(self): |
| 67 | + return "PageReference(pageTitle='"+self.pageTitle+"', startPosition="+str(self.startPosition)+", endPosition="+str(self.endPosition)+")" |
| 68 | + |
| 69 | + |
Index: trunk/wiki/wikiation/wikiation_exttest/HELP |
— | — | @@ -0,0 +1,94 @@ |
| 2 | +-------------------------- |
| 3 | +Help for wikiation-exttest |
| 4 | + |
| 5 | +This software, copyright (C) 2008-2009 by Wikiation. |
| 6 | +This software is developed by Kim Bruning. |
| 7 | + |
| 8 | +Distributed under the terms of the MIT license |
| 9 | + |
| 10 | +Purpose: |
| 11 | +Regression testing of mediawiki and mediawiki extension modules. |
| 12 | +Currently checks whether certain wikisyntax generates the expected (X)HTML. |
| 13 | +In future, generic web requests might also be checked. |
| 14 | + |
| 15 | +The test is performed by logging on to the configured wiki and creating a |
| 16 | +new page with the specified wikisyntax, surrounded by (long) unique marker |
| 17 | +strings. |
| 18 | + |
| 19 | + |
| 20 | +Syntax: |
| 21 | + |
| 22 | +(unix) |
| 23 | +./wikiation_webtest.py [options] |
| 24 | + |
| 25 | +(all os) |
| 26 | +python wikiation_webtest.py [options] |
| 27 | + |
| 28 | +Options are all GNU long form: |
| 29 | + |
| 30 | +base operations (pick 1): |
| 31 | + |
| 32 | +--pyfile <filename> |
| 33 | + Execute tests from a python file of the appropriate format (a |
| 34 | + list of Test objects) |
| 35 | + (see examples/example.py, test.py). |
| 36 | + Writes a brief report to stdout while testing. |
| 37 | + |
| 38 | +--xmlfile <filename> |
| 39 | + Execute tests from an xml file (see examples/example.xml for format) |
| 40 | + Writes a brief report to stdout while testing. |
| 41 | + |
| 42 | +--category |
| 43 | + Execute tests from a category on the configured wiki |
| 44 | + (default: [[Category:Automated tests]]). |
| 45 | + Will check each page in the category for <exttest></exttest> |
| 46 | + tags, assemble a test-set, and execute it. |
| 47 | + |
| 48 | +--category-and-write |
| 49 | + similar to --category above, however, if the <exttest> element is |
| 50 | + followed by a <result>...</result> element ( note: <result/> |
| 51 | + currently doesn't work), the contents of the result element will |
| 52 | + be replaced by a wikiformatted report on the test result. |
| 53 | + This is helpful on-wiki for people who like to have their |
| 54 | + tests and results on the same page. A separate element is used |
| 55 | + to reduce the odds of wikiation-webtest accidentally mangeling |
| 56 | + the page. |
| 57 | + |
| 58 | +--test |
| 59 | + A quick simple built-in test to check if everything is working ok |
| 60 | + (checks the {{SERVER}} flag). It should report a failure and a diff. |
| 61 | + Useful for checking if your configuration is ok. |
| 62 | + |
| 63 | +--help |
| 64 | + Display this help |
| 65 | + |
| 66 | +Other flags: |
| 67 | + |
| 68 | +--dump-xml <filename> |
| 69 | +--dump-py <filename> |
| 70 | + After concluding the test, save respectively xml or python to the |
| 71 | + specified filename, in a format suitable for reading by --pyfile or |
| 72 | + --xmlfile respectively. |
| 73 | + |
| 74 | + Both filetypes also include the outcome of the test |
| 75 | + (HTML), and an ascii diff of the outcome with the expected outcome. |
| 76 | + |
| 77 | + In the case of --category or --category-and-write, the .py |
| 78 | + file also includes PageReference information (see: |
| 79 | + test.PageReference). Be aware that PageReference information |
| 80 | + is only accurate at the time it was generated. If anyone alters |
| 81 | + the contents of the test category it may no longer be valid. |
| 82 | + This might be a problem in your own programs. |
| 83 | + |
| 84 | + To prevent the above problems in wikiation_webtest, |
| 85 | + --pyfile and --xmlfile only use test information. |
| 86 | + PageReference information, (X)HTML results, and diffs are ignored. |
| 87 | + |
| 88 | +--category-name <category name> |
| 89 | + Specify a different category to operate on. Just state the category name itself |
| 90 | + (To use [[Category:Foobar]], you just say --category-name Foobar ). If the category |
| 91 | + name uses spaces or other strange characters, you may need to escape or |
| 92 | + quote it. If you want to use unicode strings, ensure your shell and term pass |
| 93 | + unicode correctly. |
| 94 | + By default, wikiation webtest operates on the category Automated tests |
| 95 | + (that is to say: [[Category:Automated tests]]). |
Index: trunk/wiki/wikiation/wikiation_exttest/families/wikiation_family.py |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +# -*- coding: utf-8 -*- # REQUIRED
|
| 3 | +import config, family, urllib # REQUIRED
|
| 4 | +
|
| 5 | +class Family(family.Family): # REQUIRED
|
| 6 | + def __init__(self): # REQUIRED
|
| 7 | + family.Family.__init__(self) # REQUIRED
|
| 8 | + self.name = 'wikiation' # REQUIRED; replace with actual name
|
| 9 | +
|
| 10 | + self.langs = { # REQUIRED
|
| 11 | + 'nl': '83.149.110.226', # Include one line for each wiki in family
|
| 12 | + }
|
| 13 | +
|
| 14 | + def scriptpath(self, code):
|
| 15 | + """The prefix used to locate scripts on this wiki.
|
| 16 | +
|
| 17 | + This is the value displayed when you enter {{SCRIPTPATH}} on a
|
| 18 | + wiki page (often displayed at [[Help:Variables]] if the wiki has
|
| 19 | + copied the master help page correctly).
|
| 20 | +
|
| 21 | + The default value is the one used on Wikimedia Foundation wikis,
|
| 22 | + but needs to be overridden in the family file for any wiki that
|
| 23 | + uses a different value.
|
| 24 | +
|
| 25 | + """
|
| 26 | + return ''
|
| 27 | +
|
| 28 | + # IMPORTANT: if your wiki does not support the api.php interface,
|
| 29 | + # you must uncomment the second line of this method:
|
| 30 | + def apipath(self, code):
|
| 31 | + # raise NotImplementedError, "%s wiki family does not support api.php" % self.name
|
| 32 | + return '%s/api.php' % self.scriptpath(code)
|
| 33 | +
|
| 34 | + # Which version of MediaWiki is used?
|
| 35 | + def version(self, code):
|
| 36 | + # Replace with the actual version being run on your wiki
|
| 37 | + return '1.12'
|
| 38 | +
|
| 39 | + def code2encoding(self, code):
|
| 40 | + """Return the encoding for a specific language wiki"""
|
| 41 | + # Most wikis nowadays use UTF-8, but change this if yours uses
|
| 42 | + # a different encoding
|
| 43 | + return 'utf-8'
|
Index: trunk/wiki/wikiation/wikiation_exttest/logindata.py |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +# This software, copyright (C) 2008-2009 by Wikiation. |
| 3 | +# This software is developed by Kim Bruning. |
| 4 | +# |
| 5 | +# Distributed under the terms of the MIT license |
| 6 | + |
| 7 | +import sys, os |
| 8 | +import settings |
| 9 | +if settings.pywikipedia_path not in sys.path: |
| 10 | + sys.path.append(settings.pywikipedia_path) |
| 11 | + |
| 12 | +cwd=os.getcwd() |
| 13 | +os.chdir(settings.pywikipedia_path) |
| 14 | +import wikipedia, login |
| 15 | +os.chdir(cwd) |
| 16 | +import base_family |
| 17 | + |
| 18 | +class LoginData: |
| 19 | + |
| 20 | + def __init__( |
| 21 | + self, |
| 22 | + name='MY_NAME_FOR_THIS_SERVER', |
| 23 | + protocol='http', |
| 24 | + server='www.my_server.com', |
| 25 | + scriptpath='/my/script/path/', |
| 26 | + version='1.13.2', |
| 27 | + lang='en', |
| 28 | + encoding='utf-8', |
| 29 | + user='MY_BOT_USER', |
| 30 | + password='MY_SECRET_PASSWORD', |
| 31 | + RversionTab=None, |
| 32 | + api_supported=False |
| 33 | + ): |
| 34 | + self.lang=lang |
| 35 | + self.user=user |
| 36 | + self.password=password |
| 37 | + self.family=base_family.Family( |
| 38 | + name=name, |
| 39 | + protocol=protocol, |
| 40 | + server=server, |
| 41 | + scriptpath=scriptpath, |
| 42 | + version=version, |
| 43 | + lang=lang, |
| 44 | + encoding=encoding, |
| 45 | + RversionTab=RversionTab, |
| 46 | + api_supported=api_supported) |
| 47 | + self.site=None |
| 48 | + |
| 49 | + def login(self): |
| 50 | + self.site=wikipedia.Site( |
| 51 | + code=self.lang, |
| 52 | + fam=self.family, |
| 53 | + user=self.user |
| 54 | + ) |
| 55 | + loginManager=login.LoginManager( |
| 56 | + password=self.password, |
| 57 | + site=self.site, |
| 58 | + username=self.user |
| 59 | + ) |
| 60 | + loginManager.login() |
| 61 | + return self.site |