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