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

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

Issue 10835012: Extension Docs Server: Include a list of samples used in the api reference page. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 4 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import os 7 import os
8 import unittest 8 import unittest
9 9
10 from file_system_cache import FileSystemCache 10 from file_system_cache import FileSystemCache
11 from local_file_system import LocalFileSystem 11 from local_file_system import LocalFileSystem
12 from api_data_source import APIDataSource 12 from api_data_source import APIDataSource
13 13
14 class FakeSamplesDataSource:
15 def Create(self, request):
16 return {}
17
14 class APIDataSourceTest(unittest.TestCase): 18 class APIDataSourceTest(unittest.TestCase):
15 def setUp(self): 19 def setUp(self):
16 self._base_path = os.path.join('test_data', 'test_json') 20 self._base_path = os.path.join('test_data', 'test_json')
17 21
18 def _ReadLocalFile(self, filename): 22 def _ReadLocalFile(self, filename):
19 with open(os.path.join(self._base_path, filename), 'r') as f: 23 with open(os.path.join(self._base_path, filename), 'r') as f:
20 return f.read() 24 return f.read()
21 25
22 def testSimple(self): 26 def testSimple(self):
23 cache_builder = FileSystemCache.Builder(LocalFileSystem(self._base_path)) 27 cache_builder = FileSystemCache.Builder(LocalFileSystem(self._base_path))
24 data_source = APIDataSource(cache_builder, './') 28 data_source_factory = APIDataSource.Factory(cache_builder,
29 './',
30 FakeSamplesDataSource())
31 data_source = data_source_factory.Create({})
25 32
26 # Take the dict out of the list. 33 # Take the dict out of the list.
27 expected = json.loads(self._ReadLocalFile('expected_test_file.json')) 34 expected = json.loads(self._ReadLocalFile('expected_test_file.json'))
28 expected.update({ 'permissions': None }) 35 expected['permissions'] = None
29 self.assertEqual(expected, data_source['test_file']) 36 self.assertEqual(expected, data_source['test_file'])
30 self.assertEqual(expected, data_source['testFile']) 37 self.assertEqual(expected, data_source['testFile'])
31 self.assertEqual(expected, data_source['testFile.html']) 38 self.assertEqual(expected, data_source['testFile.html'])
32 self.assertRaises(OSError, data_source.get, 'junk') 39 self.assertRaises(OSError, data_source.get, 'junk')
33 40
34 if __name__ == '__main__': 41 if __name__ == '__main__':
35 unittest.main() 42 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698