addon-sdk/source/python-lib/cuddlefish/tests/test_rdf.py

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:273db8cbc9bd
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import unittest
6 import xml.dom.minidom
7 import os.path
8
9 from cuddlefish import rdf, packaging
10
11 parent = os.path.dirname
12 test_dir = parent(os.path.abspath(__file__))
13 template_dir = os.path.join(parent(test_dir), "../../app-extension")
14
15 class RDFTests(unittest.TestCase):
16 def testBug567660(self):
17 obj = rdf.RDF()
18 data = u'\u2026'.encode('utf-8')
19 x = '<?xml version="1.0" encoding="utf-8"?><blah>%s</blah>' % data
20 obj.dom = xml.dom.minidom.parseString(x)
21 self.assertEqual(obj.dom.documentElement.firstChild.nodeValue,
22 u'\u2026')
23 self.assertEqual(str(obj).replace("\n",""), x.replace("\n",""))
24
25 def failUnlessIn(self, substring, s, msg=""):
26 if substring not in s:
27 self.fail("(%s) substring '%s' not in string '%s'"
28 % (msg, substring, s))
29
30 def testUnpack(self):
31 basedir = os.path.join(test_dir, "bug-715340-files")
32 for n in ["pkg-1-pack", "pkg-2-unpack", "pkg-3-pack"]:
33 cfg = packaging.get_config_in_dir(os.path.join(basedir, n))
34 m = rdf.gen_manifest(template_dir, cfg, jid="JID")
35 if n.endswith("-pack"):
36 # these ones should remain packed
37 self.failUnlessEqual(m.get("em:unpack"), "false")
38 self.failUnlessIn("<em:unpack>false</em:unpack>", str(m), n)
39 else:
40 # and these should be unpacked
41 self.failUnlessEqual(m.get("em:unpack"), "true")
42 self.failUnlessIn("<em:unpack>true</em:unpack>", str(m), n)
43
44 def testTitle(self):
45 basedir = os.path.join(test_dir, 'bug-906359-files')
46 for n in ['title', 'fullName', 'none']:
47 cfg = packaging.get_config_in_dir(os.path.join(basedir, n))
48 m = rdf.gen_manifest(template_dir, cfg, jid='JID')
49 self.failUnlessEqual(m.get('em:name'), 'a long ' + n)
50 self.failUnlessIn('<em:name>a long ' + n + '</em:name>', str(m), n)
51
52
53 if __name__ == '__main__':
54 unittest.main()

mercurial