cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / app_yaml_helper_test.py
blob3e51f6858495a24b7aa9fe3c4083e56539b10b1b
1 #!/usr/bin/env python
2 # Copyright 2013 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.
6 import unittest
8 from app_yaml_helper import AppYamlHelper
9 from extensions_paths import SERVER2
10 from host_file_system_provider import HostFileSystemProvider
11 from mock_file_system import MockFileSystem
12 from object_store_creator import ObjectStoreCreator
13 from test_file_system import MoveTo, TestFileSystem
14 from test_util import DisableLogging
16 _ExtractVersion, _IsGreater, _GenerateAppYaml = (
17 AppYamlHelper.ExtractVersion,
18 AppYamlHelper.IsGreater,
19 AppYamlHelper.GenerateAppYaml)
21 class AppYamlHelperTest(unittest.TestCase):
22 def testExtractVersion(self):
23 def run_test(version):
24 self.assertEqual(version, _ExtractVersion(_GenerateAppYaml(version)))
25 run_test('0')
26 run_test('0-0')
27 run_test('0-0-0')
28 run_test('1')
29 run_test('1-0')
30 run_test('1-0-0')
31 run_test('1-0-1')
32 run_test('1-1-0')
33 run_test('1-1-1')
34 run_test('2-0-9')
35 run_test('2-0-12')
36 run_test('2-1')
37 run_test('2-1-0')
38 run_test('2-11-0')
39 run_test('3-1-0')
40 run_test('3-1-3')
41 run_test('3-12-0')
43 def testIsGreater(self):
44 def assert_is_greater(lhs, rhs):
45 self.assertTrue(_IsGreater(lhs, rhs), '%s is not > %s' % (lhs, rhs))
46 self.assertFalse(_IsGreater(rhs, lhs),
47 '%s should not be > %s' % (rhs, lhs))
48 assert_is_greater('0-0', '0')
49 assert_is_greater('0-0-0', '0')
50 assert_is_greater('0-0-0', '0-0')
51 assert_is_greater('1', '0')
52 assert_is_greater('1', '0-0')
53 assert_is_greater('1', '0-0-0')
54 assert_is_greater('1-0', '0-0')
55 assert_is_greater('1-0-0-0', '0-0-0')
56 assert_is_greater('2-0-12', '2-0-9')
57 assert_is_greater('2-0-12', '2-0-9-0')
58 assert_is_greater('2-0-12-0', '2-0-9')
59 assert_is_greater('2-0-12-0', '2-0-9-0')
60 assert_is_greater('2-1', '2-0-9')
61 assert_is_greater('2-1', '2-0-12')
62 assert_is_greater('2-1-0', '2-0-9')
63 assert_is_greater('2-1-0', '2-0-12')
64 assert_is_greater('3-1-0', '2-1')
65 assert_is_greater('3-1-0', '2-1-0')
66 assert_is_greater('3-1-0', '2-11-0')
67 assert_is_greater('3-1-3', '3-1-0')
68 assert_is_greater('3-12-0', '3-1-0')
69 assert_is_greater('3-12-0', '3-1-3')
70 assert_is_greater('3-12-0', '3-1-3-0')
72 @DisableLogging('warning')
73 def testInstanceMethods(self):
74 test_data = {
75 'app.yaml': _GenerateAppYaml('1-0'),
76 'app_yaml_helper.py': 'Copyright notice etc'
79 updates = []
80 # Pass a specific file system at head to the HostFileSystemProvider so that
81 # we know it's always going to be backed by a MockFileSystem. The Provider
82 # may decide to wrap it in caching etc.
83 file_system_at_head = MockFileSystem(
84 TestFileSystem(test_data, relative_to=SERVER2))
86 def apply_update(update):
87 update = MoveTo(SERVER2, update)
88 file_system_at_head.Update(update)
89 updates.append(update)
91 def host_file_system_constructor(branch, commit=None):
92 self.assertEqual('master', branch)
93 self.assertTrue(commit is not None)
94 return MockFileSystem.Create(
95 TestFileSystem(test_data, relative_to=SERVER2), updates[:int(commit)])
97 object_store_creator = ObjectStoreCreator.ForTest()
98 host_file_system_provider = HostFileSystemProvider(
99 object_store_creator,
100 default_master_instance=file_system_at_head,
101 constructor_for_test=host_file_system_constructor)
102 helper = AppYamlHelper(object_store_creator, host_file_system_provider)
104 def assert_is_up_to_date(version):
105 self.assertTrue(helper.IsUpToDate(version),
106 '%s is not up to date' % version)
107 self.assertRaises(ValueError,
108 helper.GetFirstRevisionGreaterThan, version)
110 self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
111 assert_is_up_to_date('1-0-0')
112 assert_is_up_to_date('1-5-0')
114 # Revision 1.
115 apply_update({
116 'app.yaml': _GenerateAppYaml('1-5-0')
119 self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
120 self.assertEqual(1, helper.GetFirstRevisionGreaterThan('1-0-0'))
121 assert_is_up_to_date('1-5-0')
122 assert_is_up_to_date('2-5-0')
124 # Revision 2.
125 apply_update({
126 'app_yaml_helper.py': 'fixed a bug'
129 self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
130 self.assertEqual(1, helper.GetFirstRevisionGreaterThan('1-0-0'))
131 assert_is_up_to_date('1-5-0')
132 assert_is_up_to_date('2-5-0')
134 # Revision 3.
135 apply_update({
136 'app.yaml': _GenerateAppYaml('1-6-0')
139 self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
140 self.assertEqual(1, helper.GetFirstRevisionGreaterThan('1-0-0'))
141 self.assertEqual(3, helper.GetFirstRevisionGreaterThan('1-5-0'))
142 assert_is_up_to_date('2-5-0')
144 # Revision 4.
145 apply_update({
146 'app.yaml': _GenerateAppYaml('1-8-0')
148 # Revision 5.
149 apply_update({
150 'app.yaml': _GenerateAppYaml('2-0-0')
152 # Revision 6.
153 apply_update({
154 'app.yaml': _GenerateAppYaml('2-2-0')
156 # Revision 7.
157 apply_update({
158 'app.yaml': _GenerateAppYaml('2-4-0')
160 # Revision 8.
161 apply_update({
162 'app.yaml': _GenerateAppYaml('2-6-0')
165 self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
166 self.assertEqual(1, helper.GetFirstRevisionGreaterThan('1-0-0'))
167 self.assertEqual(3, helper.GetFirstRevisionGreaterThan('1-5-0'))
168 self.assertEqual(5, helper.GetFirstRevisionGreaterThan('1-8-0'))
169 self.assertEqual(6, helper.GetFirstRevisionGreaterThan('2-0-0'))
170 self.assertEqual(6, helper.GetFirstRevisionGreaterThan('2-1-0'))
171 self.assertEqual(7, helper.GetFirstRevisionGreaterThan('2-2-0'))
172 self.assertEqual(7, helper.GetFirstRevisionGreaterThan('2-3-0'))
173 self.assertEqual(8, helper.GetFirstRevisionGreaterThan('2-4-0'))
174 self.assertEqual(8, helper.GetFirstRevisionGreaterThan('2-5-0'))
175 assert_is_up_to_date('2-6-0')
176 assert_is_up_to_date('2-7-0')
178 if __name__ == '__main__':
179 unittest.main()