def test_force_unicode(self): self.assertEqual(force_unicode(b'Hello \xe2\x98\x83'), 'Hello ☃') # Don't mangle, it's already Unicode. self.assertEqual(force_unicode('Hello ☃'), 'Hello ☃') self.assertEqual(force_unicode(1), '1', "force_unicode() should convert ints") self.assertEqual(force_unicode(1.0), '1.0', "force_unicode() should convert floats") self.assertEqual(force_unicode(None), 'None', 'force_unicode() should convert None')
def test_safe_urlencode(self): self.assertEqual( force_unicode(unquote_plus(safe_urlencode({'test': 'Hello ☃! Helllo world!'}))), 'test=Hello ☃! Helllo world!') self.assertEqual( force_unicode(unquote_plus(safe_urlencode({'test': ['Hello ☃!', 'Helllo world!']}, True))), "test=Hello \u2603!&test=Helllo world!") self.assertEqual( force_unicode(unquote_plus(safe_urlencode({'test': ('Hello ☃!', 'Helllo world!')}, True))), "test=Hello \u2603!&test=Helllo world!")
def test__build_doc(self): doc = { 'id': 'doc_1', 'title': 'Example doc ☃ 1', 'price': 12.59, 'popularity': 10, } doc_xml = force_unicode(ET.tostring(self.solr._build_doc(doc), encoding='utf-8')) self.assertTrue('<field name="title">Example doc ☃ 1</field>' in doc_xml) self.assertTrue('<field name="id">doc_1</field>' in doc_xml) self.assertEqual(len(doc_xml), 152)