Adding the orphaned options pages to the navigation
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / caching_rietveld_patcher_test.py
bloba147a9e391d971f2f7549ebe756ed76c84a96c71
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
7 from caching_rietveld_patcher import (CachingRietveldPatcher,
8 _VERSION_CACHE_MAXAGE)
9 from datetime import datetime
10 from object_store_creator import ObjectStoreCreator
11 from test_patcher import TestPatcher
13 _TEST_PATCH_VERSION = '1'
14 _TEST_PATCH_FILES = (['add.txt'], ['del.txt'], ['modify.txt'])
15 _TEST_PATCH_DATA = {
16 'add.txt': 'add',
17 'modify.txt': 'modify',
20 class FakeDateTime(object):
21 def __init__(self, time=datetime.now()):
22 self.time = time
24 def now(self):
25 return self.time
27 class CachingRietveldPatcherTest(unittest.TestCase):
28 def setUp(self):
29 self._datetime = FakeDateTime()
30 self._test_patcher = TestPatcher(_TEST_PATCH_VERSION,
31 _TEST_PATCH_FILES,
32 _TEST_PATCH_DATA)
33 self._patcher = CachingRietveldPatcher(
34 self._test_patcher,
35 ObjectStoreCreator(start_empty=False),
36 self._datetime)
38 def testGetVersion(self):
39 # Invalidate cache.
40 self._datetime.time += _VERSION_CACHE_MAXAGE
41 # Fill cache.
42 self._patcher.GetVersion()
43 count = self._test_patcher.get_version_count
44 # Should read from cache.
45 self._patcher.GetVersion()
46 self.assertEqual(count, self._test_patcher.get_version_count)
47 # Invalidate cache.
48 self._datetime.time += _VERSION_CACHE_MAXAGE
49 # Should fetch version.
50 self._patcher.GetVersion()
51 self.assertEqual(count + 1, self._test_patcher.get_version_count)
53 def testGetPatchedFiles(self):
54 # Fill cache.
55 self._patcher.GetPatchedFiles()
56 count = self._test_patcher.get_patched_files_count
57 # Should read from cache.
58 self._patcher.GetPatchedFiles()
59 self.assertEqual(count, self._test_patcher.get_patched_files_count)
61 def testApply(self):
62 # Fill cache.
63 self._patcher.Apply(['add.txt'], None).Get()
64 count = self._test_patcher.apply_count
65 # Should read from cache even though it's reading another file.
66 self._patcher.Apply(['modify.txt'], None).Get()
67 self.assertEqual(count, self._test_patcher.apply_count)
69 if __name__ == '__main__':
70 unittest.main()