Beispiel #1
0
class FormFormatTest(unittest.TestCase):
    def setUp(self):
        from tootwi.formats import FormFormat
        self.format = FormFormat()
    
    def test_creation(self):
        from tootwi.formats import Format
        self.assertIsInstance(self.format, Format)
        self.assertEqual(self.format.extension, None)
    
    def test_decoding_of_none_sample_fails(self):
        from tootwi.errors import FormatValueIsNotStringError
        with self.assertRaises(FormatValueIsNotStringError):
            result = self.format.decode(None)
    
    def test_decoding_of_empty_sample(self):
        sample = ' '
        result = self.format.decode(sample)
        self.assertEqual(result, {})
    
    def test_decoding_of_ascii_sample(self):
        sample = 'a=123&b=456'
        result = self.format.decode(sample)
        self.assertEqual(result, {'a':'123', 'b': '456'})
    
    def test_decoding_of_unicode_sample(self):
        output = u'\u043f\u0440\u0438\u0432\u0435\u0442' # russian 'privet' ('hello')
        sample = 'a=%s&b=%s%s' % (output, output, output)
        result = self.format.decode(sample)
        self.assertEqual(result, {'a':output, 'b': output+output})
    
    def test_decoding_of_urlencoded_sample(self):
        output = u'\u043f\u0440\u0438\u0432\u0435\u0442' # russian 'privet' ('hello')
        sample = 'a=%25&b=%20%30&c=%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82'
        result = self.format.decode(sample)
        self.assertEqual(result, {'a':'%', 'b': ' 0', 'c': output})
Beispiel #2
0
 def setUp(self):
     from tootwi.formats import FormFormat
     self.format = FormFormat()