michael@0: #!/usr/bin/env python
michael@0:
michael@0: import os
michael@0: import tempfile
michael@0: import unittest
michael@0: import shutil
michael@0: from mozprofile import addons
michael@0:
michael@0:
michael@0: here = os.path.dirname(os.path.abspath(__file__))
michael@0:
michael@0:
michael@0: class AddonIDTest(unittest.TestCase):
michael@0: """ Test finding the addon id in a variety of install.rdf styles """
michael@0:
michael@0: def make_install_rdf(self, filecontents):
michael@0: path = tempfile.mkdtemp()
michael@0: f = open(os.path.join(path, "install.rdf"), "w")
michael@0: f.write(filecontents)
michael@0: f.close()
michael@0: return path
michael@0:
michael@0: def test_addonID(self):
michael@0: testlist = self.get_test_list()
michael@0: for t in testlist:
michael@0: try:
michael@0: p = self.make_install_rdf(t)
michael@0: a = addons.AddonManager(os.path.join(p, "profile"))
michael@0: addon_id = a.addon_details(p)['id']
michael@0: self.assertEqual(addon_id, "winning", "We got the addon id")
michael@0: finally:
michael@0: shutil.rmtree(p)
michael@0:
michael@0: def test_addonID_xpi(self):
michael@0: a = addons.AddonManager("profile")
michael@0: addon = a.addon_details(os.path.join(here, "addons", "empty.xpi"))
michael@0: self.assertEqual(addon['id'], "test-empty@quality.mozilla.org", "We got the addon id")
michael@0:
michael@0: def get_test_list(self):
michael@0: """ This just returns a hardcoded list of install.rdf snippets for testing.
michael@0: When adding snippets for testing, remember that the id we're looking for
michael@0: is "winning" (no quotes). So, make sure you have that id in your snippet
michael@0: if you want it to pass.
michael@0: """
michael@0: tests = [
michael@0: """
michael@0:
michael@0:
michael@0: winning
michael@0: MozMill
michael@0: 2.0a
michael@0: Adam Christian
michael@0: A testing extension based on the Windmill Testing Framework client source
michael@0: true
michael@0:
michael@0:
michael@0:
michael@0: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
michael@0: 3.5
michael@0: 8.*
michael@0:
michael@0:
michael@0:
michael@0:
michael@0:
michael@0: {3550f703-e582-4d05-9a08-453d09bdfdc6}
michael@0: 3.0a1pre
michael@0: 3.2*
michael@0:
michael@0:
michael@0:
michael@0:
michael@0:
michael@0: {718e30fb-e89b-41dd-9da7-e25a45638b28}
michael@0: 0.6a1
michael@0: 1.0pre
michael@0:
michael@0:
michael@0:
michael@0:
michael@0:
michael@0: {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
michael@0: 2.0a1
michael@0: 2.1*
michael@0:
michael@0:
michael@0:
michael@0:
michael@0:
michael@0: songbird@songbirdnest.com
michael@0: 0.3pre
michael@0: 1.3.0a
michael@0:
michael@0:
michael@0:
michael@0:
michael@0: toolkit@mozilla.org
michael@0: 1.9.1
michael@0: 2.0*
michael@0:
michael@0:
michael@0:
michael@0: """,
michael@0: """
michael@0:
michael@0:
michael@0:
michael@0:
michael@0: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
michael@0: 3.5
michael@0: 8.*
michael@0:
michael@0:
michael@0: winning
michael@0: MozMill
michael@0: 2.0a
michael@0: Adam Christian
michael@0: A testing extension based on the Windmill Testing Framework client source
michael@0: true
michael@0:
michael@0: """,
michael@0: """
michael@0:
michael@0: winning
michael@0: foo
michael@0: 42
michael@0: A testing extension based on the Windmill Testing Framework client source
michael@0:
michael@0: """,
michael@0: """
michael@0:
michael@0:
michael@0:
michael@0:
michael@0: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
michael@0: 3.5
michael@0: 8.*
michael@0:
michael@0:
michael@0: winning
michael@0: MozMill
michael@0: 2.0a
michael@0: Adam Christian
michael@0: A testing extension based on the Windmill Testing Framework client source
michael@0: true
michael@0:
michael@0: """]
michael@0: return tests
michael@0:
michael@0: if __name__ == '__main__':
michael@0: unittest.main()