Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / rietveld_patcher_test.py
blobde217a59aa298088e38fc42b22327d0b843aa9de
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 appengine_url_fetcher import AppEngineUrlFetcher
11 from extensions_paths import (
12 ARTICLES_TEMPLATES, EXTENSIONS, DOCS, JSON_TEMPLATES, PUBLIC_TEMPLATES)
13 from fake_fetchers import ConfigureFakeFetchers
14 from file_system import FileNotFoundError
15 from rietveld_patcher import RietveldPatcher
16 import url_constants
19 def _PrefixWith(prefix, lst):
20 return [posixpath.join(prefix, item) for item in lst]
23 class RietveldPatcherTest(unittest.TestCase):
24 def setUp(self):
25 ConfigureFakeFetchers()
26 self._patcher = RietveldPatcher(
27 '14096030',
28 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER))
30 def _ReadLocalFile(self, filename):
31 with open(os.path.join(sys.path[0],
32 'test_data',
33 'rietveld_patcher',
34 'expected',
35 filename), 'r') as f:
36 return f.read()
38 def _ApplySingle(self, path):
39 return self._patcher.Apply([path], None).Get()[path]
41 def testGetVersion(self):
42 self.assertEqual(self._patcher.GetVersion(), '22002')
44 def testGetPatchedFiles(self):
45 added, deleted, modified = self._patcher.GetPatchedFiles()
46 self.assertEqual(
47 sorted(added),
48 _PrefixWith(DOCS, ['examples/test',
49 'templates/articles/test_foo.html',
50 'templates/public/extensions/test_foo.html']))
51 self.assertEqual(deleted,
52 ['%s/extensions/runtime.html' % PUBLIC_TEMPLATES])
53 self.assertEqual(
54 sorted(modified),
55 _PrefixWith(EXTENSIONS, ['api/test.json',
56 'docs/templates/json/extensions_sidenav.json',
57 'manifest.h']))
59 def testApply(self):
60 article_path = '%s/test_foo.html' % ARTICLES_TEMPLATES
62 # Apply to an added file.
63 self.assertEqual(
64 self._ReadLocalFile('test_foo.html'),
65 self._ApplySingle('%s/extensions/test_foo.html' % PUBLIC_TEMPLATES))
67 # Apply to a modified file.
68 self.assertEqual(
69 self._ReadLocalFile('extensions_sidenav.json'),
70 self._ApplySingle('%s/extensions_sidenav.json' % JSON_TEMPLATES))
72 # Applying to a deleted file doesn't throw exceptions. It just returns
73 # empty content.
74 # self.assertRaises(FileNotFoundError, self._ApplySingle,
75 # 'docs/templates/public/extensions/runtime.html')
77 # Apply to an unknown file.
78 self.assertRaises(FileNotFoundError, self._ApplySingle, 'not_existing')
80 if __name__ == '__main__':
81 unittest.main()