Back to index

moin  1.9.0~rc2
test_web.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - MoinMoin.util.web Tests
00004 
00005     @copyright: 2003-2004 by Juergen Hermann <jh@web.de>
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 from MoinMoin import wikiutil
00010 from MoinMoin.util import web
00011 from MoinMoin.widget import html
00012 
00013 
00014 class TestMakeQueryString:
00015     """util.web: making query string"""
00016 
00017     def testMakeQueryStringFromArgument(self):
00018         """ util.web: make query sting from argument """
00019         tests = (
00020             # description,          arg,                expected
00021             ('string unchanged',    'a=b',              'a=b'),
00022             ('string value',        {'a': 'b'},         'a=b'),
00023             ('integer value',       {'a': 1},           'a=1'),
00024             ('multiply values',     {'a': 1, 'b': 2},   'a=1&b=2'),
00025             )
00026 
00027         for description, arg, expected in tests:
00028             assert wikiutil.makeQueryString(arg) == expected
00029 
00030     def testMakeQueryStringFromKeywords(self):
00031         """ util.web: make query sting from keywords """
00032         assert wikiutil.makeQueryString(a=1, b='string') == 'a=1&b=string'
00033 
00034     def testMakeQueryStringFromArgumentAndKeywords(self):
00035         """ util.web: make query sting from argument and keywords """
00036 
00037         tests = (
00038             # description,      arg,                    expected
00039             ('kw ignored',      'a=1',                  'a=1'),
00040             ('kw added to arg', {'a': 1},               'a=1&b=kw'),
00041             ('kw override arg', {'a': 1, 'b': 'arg'},   'a=1&b=kw'),
00042             )
00043 
00044         for description, arg, expected in tests:
00045             # Call makeQueryString with both arg and keyword
00046             assert wikiutil.makeQueryString(arg, b='kw') == expected
00047 
00048 
00049 class TestMakeSelection:
00050     """util.web: creating html select"""
00051 
00052     values = ('one', 'two', 'simple', ('complex', 'A tuple & <escaped text>'))
00053 
00054     html._SORT_ATTRS = 1
00055     expected = (
00056         u'<select name="test" size="1">'
00057         u'<option value="one">one</option>'
00058         u'<option value="two">two</option>'
00059         u'<option value="simple">simple</option>'
00060         u'<option value="complex">A tuple &amp; &lt;escaped text&gt;</option>'
00061         u'</select>'
00062     )
00063 
00064     def testMakeSelectNoSelection(self):
00065         """util.web: creating html select with no selection"""
00066         expected = self.expected
00067         result = unicode(web.makeSelection('test', self.values, size=1))
00068         assert result == expected
00069 
00070     def testMakeSelectNoSelection2(self):
00071         """util.web: creating html select with non existing selection"""
00072         expected = self.expected
00073         result = unicode(web.makeSelection('test', self.values, 'three', size=1))
00074         assert result == expected
00075 
00076     def testMakeSelectWithSelectedItem(self):
00077         """util.web: creating html select with selected item"""
00078         expected = self.expected.replace('value="two"', 'selected value="two"')
00079         result = unicode(web.makeSelection('test', self.values, 'two', size=1))
00080         assert result == expected
00081 
00082 
00083 coverage_modules = ['MoinMoin.util.web']
00084