test_rdf.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. import unittest
  5. import xml.dom.minidom
  6. import os.path
  7. from cuddlefish import rdf, packaging
  8. parent = os.path.dirname
  9. test_dir = parent(os.path.abspath(__file__))
  10. template_dir = os.path.join(parent(test_dir), "../../app-extension")
  11. class RDFTests(unittest.TestCase):
  12. def testBug567660(self):
  13. obj = rdf.RDF()
  14. data = u'\u2026'.encode('utf-8')
  15. x = '<?xml version="1.0" encoding="utf-8"?><blah>%s</blah>' % data
  16. obj.dom = xml.dom.minidom.parseString(x)
  17. self.assertEqual(obj.dom.documentElement.firstChild.nodeValue,
  18. u'\u2026')
  19. self.assertEqual(str(obj).replace("\n",""), x.replace("\n",""))
  20. def failUnlessIn(self, substring, s, msg=""):
  21. if substring not in s:
  22. self.fail("(%s) substring '%s' not in string '%s'"
  23. % (msg, substring, s))
  24. def testUnpack(self):
  25. basedir = os.path.join(test_dir, "bug-715340-files")
  26. for n in ["pkg-1-pack", "pkg-2-unpack", "pkg-3-pack"]:
  27. cfg = packaging.get_config_in_dir(os.path.join(basedir, n))
  28. m = rdf.gen_manifest(template_dir, cfg, jid="JID")
  29. if n.endswith("-pack"):
  30. # these ones should remain packed
  31. self.failUnlessEqual(m.get("em:unpack"), "false")
  32. self.failUnlessIn("<em:unpack>false</em:unpack>", str(m), n)
  33. else:
  34. # and these should be unpacked
  35. self.failUnlessEqual(m.get("em:unpack"), "true")
  36. self.failUnlessIn("<em:unpack>true</em:unpack>", str(m), n)
  37. def testTitle(self):
  38. basedir = os.path.join(test_dir, 'bug-906359-files')
  39. for n in ['title', 'fullName', 'none']:
  40. cfg = packaging.get_config_in_dir(os.path.join(basedir, n))
  41. m = rdf.gen_manifest(template_dir, cfg, jid='JID')
  42. self.failUnlessEqual(m.get('em:name'), 'a long ' + n)
  43. self.failUnlessIn('<em:name>a long ' + n + '</em:name>', str(m), n)
  44. if __name__ == '__main__':
  45. unittest.main()