Bug 1040069 - Return None for the gaia commit if it can't be found. r=ahalberstadt

This commit is contained in:
Dave Hunt 2014-07-21 02:57:00 +02:00
parent 3bc0df27dc
commit 7c95173e9a
2 changed files with 20 additions and 6 deletions

View File

@ -140,6 +140,9 @@ class B2GVersion(Version):
self._info['gaia_changeset'] = re.match(
'^\w{40}$', changeset) and changeset or None
self._info['gaia_date'] = date
except KeyError:
self.warn('Unable to find resources/gaia_commit.txt in '
'application.zip')
finally:
mozfile.remove(tempdir)

View File

@ -29,27 +29,38 @@ class SourcesTest(unittest.TestCase):
def tearDown(self):
mozfile.remove(self.tempdir)
def _create_zip(self, revision, date='date'):
def _create_zip(self, revision=None, date=None):
zip_path = os.path.join(
self.tempdir, 'gaia', 'profile', 'webapps',
'settings.gaiamobile.org', 'application.zip')
os.makedirs(os.path.dirname(zip_path))
app_zip = zipfile.ZipFile(zip_path, 'w')
app_zip.writestr('resources/gaia_commit.txt', revision + '\n' + date)
if revision or date:
app_zip.writestr('resources/gaia_commit.txt',
'%s\n%s' % (revision, date))
app_zip.close()
def test_gaia_commit(self):
self._create_zip('a' * 40, 'date')
revision, date = ('a' * 40, 'date')
self._create_zip(revision, date)
v = get_version(self.binary)
self.assertEqual(v.get('gaia_changeset'), 'a' * 40)
self.assertEqual(v.get('gaia_date'), 'date')
self.assertEqual(v.get('gaia_changeset'), revision)
self.assertEqual(v.get('gaia_date'), date)
def test_invalid_gaia_commit(self):
self._create_zip('a' * 41)
revision, date = ('a' * 41, 'date')
self._create_zip(revision, date)
v = get_version(self.binary)
self.assertIsNone(v.get('gaia_changeset'))
self.assertEqual(v.get('gaia_date'), date)
def test_missing_zip_file(self):
v = get_version(self.binary)
self.assertIsNone(v.get('gaia_changeset'))
self.assertIsNone(v.get('gaia_date'))
def test_missing_gaia_commit(self):
self._create_zip()
v = get_version(self.binary)
self.assertIsNone(v.get('gaia_changeset'))
self.assertIsNone(v.get('gaia_date'))