Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: chrome/common/extensions/docs/server2/rietveld_patcher_test.py

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
Property Changes:
Added: svn:eol-style
+ LF
Added: svn:executable
+ *
OLDNEW
(Empty)
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.
5
6 import os
7 import sys
8 import unittest
9 from appengine_url_fetcher import AppEngineUrlFetcher
10 from fake_fetchers import ConfigureFakeFetchers
11 from file_system import FileNotFoundError
12 from object_store_creator import ObjectStoreCreator
13 from rietveld_patcher import RietveldPatcher
14 from svn_constants import EXTENSIONS_PATH
15 import url_constants
16
17 class RietveldPatcherTest(unittest.TestCase):
18 def setUp(self):
19 ConfigureFakeFetchers(os.path.join(sys.path[0], os.pardir))
20 self._patcher = RietveldPatcher(
21 EXTENSIONS_PATH,
22 '14096030',
23 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER),
24 ObjectStoreCreator.Factory('1-0', 'test'))
25
26 def _ReadLocalFile(self, filename):
27 with open(os.path.join(sys.path[0],
28 'test_data',
29 'rietveld_patcher',
30 'expected',
31 filename), 'r') as f:
32 return f.read()
33
34 def _ApplySingle(self, path, binary=False):
35 return self._patcher.Apply([path], None, binary).Get()[path]
36
37 def testGetVersion(self):
38 self.assertEqual(self._patcher.GetVersion(), '22002')
39
40 def testGetPatchedFiles(self):
41 added, deleted, modified = self._patcher.GetPatchedFiles()
42 self.assertEqual(sorted(added),
43 sorted([
44 u'docs/templates/articles/test_foo.html',
45 u'docs/templates/public/extensions/test_foo.html']))
46 self.assertEqual(sorted(deleted),
47 sorted([
48 u'docs/templates/public/extensions/runtime.html']))
49 self.assertEqual(sorted(modified),
50 sorted([
51 u'api/test.json',
52 u'docs/templates/json/extensions_sidenav.json']))
53
54 def testApply(self):
55 article_path = 'docs/templates/articles/test_foo.html'
56
57 # Make sure RietveldPatcher handles |binary| correctly.
58 self.assertTrue(isinstance(self._ApplySingle(article_path, True), str),
59 'Expected result is binary. It was text.')
60 self.assertTrue(isinstance(self._ApplySingle(article_path), unicode),
61 'Expected result is text. It was binary.')
62
63 # Apply to an added file.
64 self.assertEqual(
65 self._ReadLocalFile('test_foo.html'),
66 self._ApplySingle(
67 'docs/templates/public/extensions/test_foo.html'))
68
69 # Apply to a modified file.
70 self.assertEqual(
71 self._ReadLocalFile('extensions_sidenav.json'),
72 self._ApplySingle(
73 'docs/templates/json/extensions_sidenav.json'))
74
75 # Apply to a deleted file.
76 self.assertRaises(FileNotFoundError, self._ApplySingle,
77 'docs/templates/public/extensions/runtime.html')
78
79 if __name__ == '__main__':
80 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698