summaryrefslogtreecommitdiff
path: root/test/test_mdict.py
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2010-01-25 23:43:39 +0100
committerMarcel Hellkamp <marc@gsites.de>2010-01-25 23:43:39 +0100
commit89117e596220b56d29aac0138be72953ce06d7af (patch)
tree7f3385a13199d0c88a648e1186bedbd2ef0b7d87 /test/test_mdict.py
parenta3e57d16de67843a7a1c525a4b919a4b40fdaae3 (diff)
downloadbottle-89117e596220b56d29aac0138be72953ce06d7af.tar.gz
Another 5% code coverage, some real and many cosmetic changes. Read more...
Added app_push() and app_pop() to easily work on a separate bottle app without interfering with other modules. This makes testing easier a lot. Response.charset now gets its value from the Content-Type header and is read only. Add '; charset=...' to response.content_type to change it. The static_file() helper does not change the response.header dict anymore. This side effect is gone. The new headers are part of the returned HTTPResponse object and applied later. This way it is easier to recover from an 40x error by just ignoring the returned HTTPError object. You don't have to undo the header changes anymore. Secure cookies now work with Python3 too. This is a pure hack. Don't use it.
Diffstat (limited to 'test/test_mdict.py')
-rw-r--r--test/test_mdict.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test_mdict.py b/test/test_mdict.py
new file mode 100644
index 0000000..f5411c4
--- /dev/null
+++ b/test/test_mdict.py
@@ -0,0 +1,41 @@
+import unittest
+from bottle import MultiDict, HeaderDict
+
+class TestMultiDict(unittest.TestCase):
+ def test_isadict(self):
+ """ MultiDict should behaves like a normal dict """
+ d, m = dict(a=5), MultiDict(a=5)
+ d['key'], m['key'] = 'value', 'value'
+ d['k2'], m['k2'] = 'v1', 'v1'
+ d['k2'], m['k2'] = 'v2', 'v2'
+ self.assertEqual(d.keys(), m.keys())
+ self.assertEqual(d.values(), m.values())
+ self.assertEqual(d.get('key'), m.get('key'))
+ self.assertEqual(d.get('cay'), m.get('cay'))
+ self.assertEqual(list(iter(d)), list(iter(m)))
+ self.assertEqual([k for k in d], [k for k in m])
+ self.assertEqual(len(d), len(m))
+ self.assertEqual('key' in d, 'key' in m)
+ self.assertEqual('cay' in d, 'cay' in m)
+ self.assertRaises(KeyError, lambda: m['cay'])
+
+ def test_ismulti(self):
+ """ MultiDict has some special features """
+ m = MultiDict(a=5)
+ m['a'] = 6
+ self.assertEqual([5, 6], m.getall('a'))
+ self.assertEqual([], m.getall('b'))
+ self.assertEqual([('a', 5), ('a', 6)], list(m.iterallitems()))
+
+ def test_isheader(self):
+ """ HeaderDict replaces by default and title()s its keys """
+ m = HeaderDict(abc_def=5)
+ m['abc_def'] = 6
+ self.assertEqual(['6'], m.getall('abc_def'))
+ m.append('abc_def', 7)
+ self.assertEqual(['6', '7'], m.getall('abc_def'))
+ self.assertEqual([('Abc_Def', '6'), ('Abc_Def', '7')], list(m.iterallitems()))
+
+if __name__ == '__main__':
+ unittest.main()
+