cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / rietveld_patcher_test.py
blob2dfc035de95cf3f6478cc37dd5a2e4d1f1d1d381
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 os
7 import posixpath
8 import sys
9 import unittest
10 from environment_wrappers import CreateUrlFetcher
11 from extensions_paths import (
12 ARTICLES_TEMPLATES, CHROME_EXTENSIONS, DOCS, JSON_TEMPLATES,
13 PUBLIC_TEMPLATES)
14 from fake_fetchers import ConfigureFakeFetchers
15 from file_system import FileNotFoundError
16 from rietveld_patcher import RietveldPatcher
17 from test_util import Server2Path
18 import url_constants
21 def _PrefixWith(prefix, lst):
22 return [posixpath.join(prefix, item) for item in lst]
25 class RietveldPatcherTest(unittest.TestCase):
26 def setUp(self):
27 ConfigureFakeFetchers()
28 self._patcher = RietveldPatcher(
29 '14096030',
30 CreateUrlFetcher(url_constants.CODEREVIEW_SERVER))
32 def _ReadLocalFile(self, filename):
33 with open(Server2Path('test_data',
34 'rietveld_patcher',
35 'expected',
36 filename), 'r') as f:
37 return f.read()
39 def _ApplySingle(self, path):
40 return self._patcher.Apply([path], None).Get()[path]
42 def testGetVersion(self):
43 self.assertEqual(self._patcher.GetVersion(), '22002')
45 def testGetPatchedFiles(self):
46 added, deleted, modified = self._patcher.GetPatchedFiles()
47 self.assertEqual(
48 sorted(added),
49 _PrefixWith(DOCS, ['examples/test',
50 'templates/articles/test_foo.html',
51 'templates/public/extensions/test_foo.html']))
52 self.assertEqual(deleted,
53 ['%sextensions/runtime.html' % PUBLIC_TEMPLATES])
54 self.assertEqual(
55 sorted(modified),
56 _PrefixWith(CHROME_EXTENSIONS,
57 ['api/test.json',
58 'docs/templates/json/extensions_sidenav.json',
59 'manifest.h']))
61 def testApply(self):
62 article_path = '%stest_foo.html' % ARTICLES_TEMPLATES
64 # Apply to an added file.
65 self.assertEqual(
66 self._ReadLocalFile('test_foo.html'),
67 self._ApplySingle('%sextensions/test_foo.html' % PUBLIC_TEMPLATES))
69 # Apply to a modified file.
70 self.assertEqual(
71 self._ReadLocalFile('extensions_sidenav.json'),
72 self._ApplySingle('%sextensions_sidenav.json' % JSON_TEMPLATES))
74 # Applying to a deleted file doesn't throw exceptions. It just returns
75 # empty content.
76 # self.assertRaises(FileNotFoundError, self._ApplySingle,
77 # 'docs/templates/public/extensions/runtime.html')
79 # Apply to an unknown file.
80 self.assertRaises(FileNotFoundError, self._ApplySingle, 'not_existing')
82 if __name__ == '__main__':
83 unittest.main()