|
1 #!/usr/bin/env python |
|
2 |
|
3 # This Source Code Form is subject to the terms of the Mozilla Public |
|
4 # License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
5 # You can obtain one at http://mozilla.org/MPL/2.0/. |
|
6 |
|
7 import os |
|
8 import tempfile |
|
9 import unittest |
|
10 import zipfile |
|
11 |
|
12 import mozfile |
|
13 from mozversion import get_version |
|
14 |
|
15 |
|
16 class SourcesTest(unittest.TestCase): |
|
17 """test getting version information from a sources xml""" |
|
18 |
|
19 def setUp(self): |
|
20 self.tempdir = tempfile.mkdtemp() |
|
21 |
|
22 self.binary = os.path.join(self.tempdir, 'binary') |
|
23 with open(self.binary, 'w') as f: |
|
24 f.write('foobar') |
|
25 |
|
26 with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: |
|
27 f.writelines("""[App]\nName = B2G\n""") |
|
28 |
|
29 def tearDown(self): |
|
30 mozfile.remove(self.tempdir) |
|
31 |
|
32 def _create_zip(self, revision, date='date'): |
|
33 zip_path = os.path.join( |
|
34 self.tempdir, 'gaia', 'profile', 'webapps', |
|
35 'settings.gaiamobile.org', 'application.zip') |
|
36 os.makedirs(os.path.dirname(zip_path)) |
|
37 app_zip = zipfile.ZipFile(zip_path, 'w') |
|
38 app_zip.writestr('resources/gaia_commit.txt', revision + '\n' + date) |
|
39 app_zip.close() |
|
40 |
|
41 def test_gaia_commit(self): |
|
42 self._create_zip('a' * 40, 'date') |
|
43 v = get_version(self.binary) |
|
44 self.assertEqual(v.get('gaia_changeset'), 'a' * 40) |
|
45 self.assertEqual(v.get('gaia_date'), 'date') |
|
46 |
|
47 def test_invalid_gaia_commit(self): |
|
48 self._create_zip('a' * 41) |
|
49 v = get_version(self.binary) |
|
50 self.assertIsNone(v.get('gaia_changeset')) |
|
51 |
|
52 def test_missing_gaia_commit(self): |
|
53 v = get_version(self.binary) |
|
54 self.assertIsNone(v.get('gaia_changeset')) |
|
55 self.assertIsNone(v.get('gaia_date')) |
|
56 |
|
57 |
|
58 if __name__ == '__main__': |
|
59 unittest.main() |