http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9193
Revision: 9193 Author: jayvdb Date: 2011-04-24 04:05:14 +0000 (Sun, 24 Apr 2011) Log Message: ----------- Basic tests for query.py
Modified Paths: -------------- trunk/pywikipedia/query.py
Added Paths: ----------- trunk/pywikipedia/tests/test_pywiki.py trunk/pywikipedia/tests/test_query.py
Modified: trunk/pywikipedia/query.py =================================================================== --- trunk/pywikipedia/query.py 2011-04-23 15:37:11 UTC (rev 9192) +++ trunk/pywikipedia/query.py 2011-04-24 04:05:14 UTC (rev 9193) @@ -279,3 +279,15 @@
def IsString(s): return type( s ) in [str, unicode] + +if __name__ == '__main__': + """ + Testing code for this module + """ + wikipedia.output(""" + This module is not for direct usage from the command prompt. + """) + # unit tests + import tests.test_query + import unittest + unittest.main(tests.test_query)
Added: trunk/pywikipedia/tests/test_pywiki.py =================================================================== --- trunk/pywikipedia/tests/test_pywiki.py (rev 0) +++ trunk/pywikipedia/tests/test_pywiki.py 2011-04-24 04:05:14 UTC (rev 9193) @@ -0,0 +1,19 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +"""Unit test framework for pywiki""" +__version__ = '$Id: $' + +import unittest +import test_utils + +import wikipedia as pywikibot + + +class PyWikiTestCase(unittest.TestCase): + + def setUp(self): + self.site = pywikibot.getSite('en', 'wikipedia') + +if __name__ == "__main__": + unittest.main()
Added: trunk/pywikipedia/tests/test_query.py =================================================================== --- trunk/pywikipedia/tests/test_query.py (rev 0) +++ trunk/pywikipedia/tests/test_query.py 2011-04-24 04:05:14 UTC (rev 9193) @@ -0,0 +1,57 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +"""Unit tests for userlib.py""" +__version__ = '$Id: test_userlib.py 9043 2011-03-13 10:25:08Z xqt $' + +import unittest +import tests.test_pywiki + +import query + + +class PyWikiQueryTestCase(tests.test_pywiki.PyWikiTestCase): + + def assertEqualQueryResult(self, params, expectedresult): + data = query.GetData(params, self.site) + self.assertEqual(data[u'query'], expectedresult) + + def test_basic(self): + params = { + 'action': 'query', + 'list': 'users', + 'usprop': ['registration'], + 'ususers': u'Example', + } + expectedresult = {u'users': [ + { + u'userid': 215131, + u'name': u'Example', + u'registration': u'2005-03-19T00:17:19Z' + } + ]} + self.assertEqualQueryResult(params, expectedresult) + + def test_multi(self): + params = { + 'action': 'query', + 'list': 'users', + 'usprop': ['registration'], + 'ususers': u'Example|Example2', + } + expectedresult = {u'users': [ + { + u'userid': 215131, + u'name': u'Example', + u'registration': u'2005-03-19T00:17:19Z' + }, + { + u'userid': 5176706, + u'name': u'Example2', + u'registration': u'2007-08-26T02:13:33Z' + }, + ]} + self.assertEqualQueryResult(params, expectedresult) + +if __name__ == "__main__": + unittest.main()