michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import unittest michael@0: import xml.dom.minidom michael@0: import os.path michael@0: michael@0: from cuddlefish import rdf, packaging michael@0: michael@0: parent = os.path.dirname michael@0: test_dir = parent(os.path.abspath(__file__)) michael@0: template_dir = os.path.join(parent(test_dir), "../../app-extension") michael@0: michael@0: class RDFTests(unittest.TestCase): michael@0: def testBug567660(self): michael@0: obj = rdf.RDF() michael@0: data = u'\u2026'.encode('utf-8') michael@0: x = '%s' % data michael@0: obj.dom = xml.dom.minidom.parseString(x) michael@0: self.assertEqual(obj.dom.documentElement.firstChild.nodeValue, michael@0: u'\u2026') michael@0: self.assertEqual(str(obj).replace("\n",""), x.replace("\n","")) michael@0: michael@0: def failUnlessIn(self, substring, s, msg=""): michael@0: if substring not in s: michael@0: self.fail("(%s) substring '%s' not in string '%s'" michael@0: % (msg, substring, s)) michael@0: michael@0: def testUnpack(self): michael@0: basedir = os.path.join(test_dir, "bug-715340-files") michael@0: for n in ["pkg-1-pack", "pkg-2-unpack", "pkg-3-pack"]: michael@0: cfg = packaging.get_config_in_dir(os.path.join(basedir, n)) michael@0: m = rdf.gen_manifest(template_dir, cfg, jid="JID") michael@0: if n.endswith("-pack"): michael@0: # these ones should remain packed michael@0: self.failUnlessEqual(m.get("em:unpack"), "false") michael@0: self.failUnlessIn("false", str(m), n) michael@0: else: michael@0: # and these should be unpacked michael@0: self.failUnlessEqual(m.get("em:unpack"), "true") michael@0: self.failUnlessIn("true", str(m), n) michael@0: michael@0: def testTitle(self): michael@0: basedir = os.path.join(test_dir, 'bug-906359-files') michael@0: for n in ['title', 'fullName', 'none']: michael@0: cfg = packaging.get_config_in_dir(os.path.join(basedir, n)) michael@0: m = rdf.gen_manifest(template_dir, cfg, jid='JID') michael@0: self.failUnlessEqual(m.get('em:name'), 'a long ' + n) michael@0: self.failUnlessIn('a long ' + n + '', str(m), n) michael@0: michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()