2 # Copyright 2014 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.
10 from future
import Future
11 from server_instance
import ServerInstance
12 from test_file_system
import TestFileSystem
13 from test_util
import Server2Path
16 def _ReadLocalFile(filename
):
17 base_path
= Server2Path('test_data', 'samples_data_source')
18 with
open(os
.path
.join(base_path
, filename
), 'r') as f
:
22 class _FakeCache(object):
23 def __init__(self
, obj
):
26 def GetFromFileListing(self
, _
):
27 return Future(value
=self
._cache
)
30 class SamplesModelSourceTest(unittest
.TestCase
):
32 server_instance
= ServerInstance
.ForTest(file_system
=TestFileSystem({}))
33 self
._samples
_model
= server_instance
.platform_bundle
.GetSamplesModel(
35 self
._samples
_model
._samples
_cache
= _FakeCache(json
.loads(_ReadLocalFile(
38 def testFilterSamples(self
):
39 self
.assertEquals(json
.loads(_ReadLocalFile('expected.json')),
40 self
._samples
_model
.FilterSamples('bobaloo').Get())
42 if __name__
== '__main__':