commit 12aa4ce0119dfe0c082d1ae4c4fb3a646fd67cac Author: Isis Lovecruft isis@torproject.org Date: Wed Apr 23 07:14:51 2014 +0000
Add unittests for bridgedb.parse.headers.parseAcceptLanguage(). --- lib/bridgedb/test/test_parse_headers.py | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
diff --git a/lib/bridgedb/test/test_parse_headers.py b/lib/bridgedb/test/test_parse_headers.py new file mode 100644 index 0000000..ddcf66f --- /dev/null +++ b/lib/bridgedb/test/test_parse_headers.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# +# This file is part of BridgeDB, a Tor bridge distribution system. +# +# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 isis@torproject.org +# please also see AUTHORS file +# :copyright: (c) 2014, Isis Lovecruft +# (c) 2007-2014, The Tor Project, Inc. +# (c) 2007-2014, all entities within the AUTHORS file +# :license: see LICENSE for licensing information + +"""Unittests for the :mod:`bridgedb.parse.headers` module.""" + +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +from twisted.trial import unittest + +from bridgedb.parse import headers + + +class ParseAcceptLanguageTests(unittest.TestCase): + """Unittests for :func:`bridgedb.parse.headers.parseAcceptLanguage`.""" + + def test_noHeaders(self): + """No header should return an empty list.""" + header = None + langs = headers.parseAcceptLanguage(header) + self.assertIsInstance(langs, list) + self.assertEqual(len(langs), 0) + + def test_defaultTBBHeader(self): + """The header 'en-us,en;q=0.5' should return ['en_us', 'en'].""" + header = 'en-us,en;q=0.5' + langs = headers.parseAcceptLanguage(header) + self.assertIsInstance(langs, list) + self.assertEqual(len(langs), 2) + self.assertEqual(langs[0], 'en_us') + self.assertEqual(langs[1], 'en') + + def test_addNonLocalizedVariant(self): + """The header 'en-us,en-gb;q=0.5' should return + ['en_us', 'en', 'en_gb']. + """ + header = 'en-us,en-gb;q=0.5' + langs = headers.parseAcceptLanguage(header) + self.assertIsInstance(langs, list) + self.assertEqual(len(langs), 3) + self.assertEqual(langs[0], 'en_us') + self.assertEqual(langs[1], 'en') + self.assertEqual(langs[2], 'en_gb')