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

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

Issue 14273035: Docserver: refactor the Handler/ServerInstance relationship into a servlet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: done 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 | Annotate | Revision Log
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 sys 8 import sys
9 import unittest 9 import unittest
10 10
11 from samples_data_source import SamplesDataSource 11 from samples_data_source import SamplesDataSource
12 12 from servlet import Request
13 class _FakeRequest(object):
14 pass
15 13
16 class SamplesDataSourceTest(unittest.TestCase): 14 class SamplesDataSourceTest(unittest.TestCase):
17 def setUp(self): 15 def setUp(self):
18 self._base_path = os.path.join(sys.path[0], 16 self._base_path = os.path.join(sys.path[0],
19 'test_data', 17 'test_data',
20 'samples_data_source') 18 'samples_data_source')
21 19
22 def _ReadLocalFile(self, filename): 20 def _ReadLocalFile(self, filename):
23 with open(os.path.join(self._base_path, filename), 'r') as f: 21 with open(os.path.join(self._base_path, filename), 'r') as f:
24 return f.read() 22 return f.read()
25 23
26 def _FakeGet(self, key): 24 def _FakeGet(self, key):
27 return json.loads(self._ReadLocalFile(key)) 25 return json.loads(self._ReadLocalFile(key))
28 26
29 def testFilterSamples(self): 27 def testFilterSamples(self):
30 sds = SamplesDataSource({}, {}, 'fake_path', _FakeRequest()) 28 sds = SamplesDataSource({}, {}, 'fake_path', Request('/', {}))
31 sds.get = self._FakeGet 29 sds.get = self._FakeGet
32 self.assertEquals(json.loads(self._ReadLocalFile('expected.json')), 30 self.assertEquals(json.loads(self._ReadLocalFile('expected.json')),
33 sds.FilterSamples('samples.json', 'bobaloo')) 31 sds.FilterSamples('samples.json', 'bobaloo'))
34 32
35 if __name__ == '__main__': 33 if __name__ == '__main__':
36 unittest.main() 34 unittest.main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/render_servlet.py ('k') | chrome/common/extensions/docs/server2/server_instance.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698