1 #!/usr/bin/env python 2 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 import os 7 import unittest 8 9 from environment import GetAppVersionNonMemoized 10 11 12 class EnvironmentTest(unittest.TestCase): 13 def testGetAppVersion(self): 14 # GetAppVersion uses 2 heuristics: the CURRENT_VERSION_ID environment 15 # variable that AppEngine sets, or the version extracted from app.yaml 16 # if no such variable exists (e.g. preview.py). The latter, we assume, 17 # is already tested because AppYamlHelper.ExtractVersion is already 18 # tested. So, for this test, we fake a CURRENT_VERSION_ID. 19 def test_single(expected, current_version_id): 20 key = 'CURRENT_VERSION_ID' 21 old_value = os.environ.get(key) 22 os.environ[key] = current_version_id 23 try: 24 self.assertEqual(expected, GetAppVersionNonMemoized()) 25 finally: 26 if old_value is None: 27 del os.environ[key] 28 else: 29 os.environ[key] = old_value 30 def test_all(expected): 31 test_single(expected, expected) 32 test_single(expected, expected + '.48w7dl48wl') 33 test_single(expected, expected + '/48w7dl48wl') 34 test_single(expected, expected + '.48w7dl48wl.w847lw83') 35 test_single(expected, expected + '.48w7dl48wl/w847lw83') 36 test_single(expected, expected + '/48w7dl48wl.w847lw83') 37 test_single(expected, expected + '/48w7dl48wl/w847lw83') 38 test_all('2') 39 test_all('2-0') 40 test_all('2-0-25') 41 test_all('2-0-25-b') 42 43 44 if __name__ == '__main__': 45 unittest.main() 46