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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/python-lib/cuddlefish/tests/test_rdf.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +import unittest
     1.9 +import xml.dom.minidom
    1.10 +import os.path
    1.11 +
    1.12 +from cuddlefish import rdf, packaging
    1.13 +
    1.14 +parent = os.path.dirname
    1.15 +test_dir = parent(os.path.abspath(__file__))
    1.16 +template_dir = os.path.join(parent(test_dir), "../../app-extension")
    1.17 +
    1.18 +class RDFTests(unittest.TestCase):
    1.19 +    def testBug567660(self):
    1.20 +        obj = rdf.RDF()
    1.21 +        data = u'\u2026'.encode('utf-8')
    1.22 +        x = '<?xml version="1.0" encoding="utf-8"?><blah>%s</blah>' % data
    1.23 +        obj.dom = xml.dom.minidom.parseString(x)
    1.24 +        self.assertEqual(obj.dom.documentElement.firstChild.nodeValue,
    1.25 +                         u'\u2026')
    1.26 +        self.assertEqual(str(obj).replace("\n",""), x.replace("\n",""))
    1.27 +
    1.28 +    def failUnlessIn(self, substring, s, msg=""):
    1.29 +        if substring not in s:
    1.30 +            self.fail("(%s) substring '%s' not in string '%s'"
    1.31 +                      % (msg, substring, s))
    1.32 +
    1.33 +    def testUnpack(self):
    1.34 +        basedir = os.path.join(test_dir, "bug-715340-files")
    1.35 +        for n in ["pkg-1-pack", "pkg-2-unpack", "pkg-3-pack"]:
    1.36 +            cfg = packaging.get_config_in_dir(os.path.join(basedir, n))
    1.37 +            m = rdf.gen_manifest(template_dir, cfg, jid="JID")
    1.38 +            if n.endswith("-pack"):
    1.39 +                # these ones should remain packed
    1.40 +                self.failUnlessEqual(m.get("em:unpack"), "false")
    1.41 +                self.failUnlessIn("<em:unpack>false</em:unpack>", str(m), n)
    1.42 +            else:
    1.43 +                # and these should be unpacked
    1.44 +                self.failUnlessEqual(m.get("em:unpack"), "true")
    1.45 +                self.failUnlessIn("<em:unpack>true</em:unpack>", str(m), n)
    1.46 +
    1.47 +    def testTitle(self):
    1.48 +        basedir = os.path.join(test_dir, 'bug-906359-files')
    1.49 +        for n in ['title', 'fullName', 'none']:
    1.50 +            cfg = packaging.get_config_in_dir(os.path.join(basedir, n))
    1.51 +            m = rdf.gen_manifest(template_dir, cfg, jid='JID')
    1.52 +            self.failUnlessEqual(m.get('em:name'), 'a long ' + n)
    1.53 +            self.failUnlessIn('<em:name>a long ' + n + '</em:name>', str(m), n)
    1.54 +
    1.55 +
    1.56 +if __name__ == '__main__':
    1.57 +    unittest.main()

mercurial