OLD | NEW |
(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 json |
| 7 import unittest |
| 8 |
| 9 from compiled_file_system import CompiledFileSystem |
| 10 from content_providers import ContentProviders |
| 11 from object_store_creator import ObjectStoreCreator |
| 12 from test_file_system import TestFileSystem |
| 13 from test_util import DisableLogging |
| 14 |
| 15 |
| 16 _HOST = 'https://developer.chrome.com' |
| 17 |
| 18 |
| 19 _CONTENT_PROVIDERS = { |
| 20 'apples': { |
| 21 'chroot': 'apples', |
| 22 'serveFrom': 'apples-dir', |
| 23 'type': 'chromium', |
| 24 }, |
| 25 'bananas': { |
| 26 'serveFrom': '', |
| 27 'type': 'chromium', |
| 28 }, |
| 29 'tomatoes': { |
| 30 'chroot': 'tomatoes/are/a', |
| 31 'serveFrom': 'tomatoes-dir/are/a', |
| 32 'type': 'chromium', |
| 33 }, |
| 34 } |
| 35 |
| 36 |
| 37 _FILE_SYSTEM_DATA = { |
| 38 'docs': { |
| 39 'templates': { |
| 40 'json': { |
| 41 'content_providers.json': json.dumps(_CONTENT_PROVIDERS), |
| 42 }, |
| 43 }, |
| 44 }, |
| 45 'apples': { |
| 46 'gala.txt': 'gala apples', |
| 47 'green': { |
| 48 'granny smith.txt': 'granny smith apples', |
| 49 }, |
| 50 }, |
| 51 'tomatoes': { |
| 52 'are': { |
| 53 'a': { |
| 54 'vegetable.txt': 'no they aren\'t', |
| 55 'fruit': { |
| 56 'cherry.txt': 'cherry tomatoes', |
| 57 }, |
| 58 }, |
| 59 }, |
| 60 }, |
| 61 } |
| 62 |
| 63 |
| 64 class ContentProvidersTest(unittest.TestCase): |
| 65 def setUp(self): |
| 66 self._content_providers = ContentProviders( |
| 67 CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()), |
| 68 TestFileSystem(_FILE_SYSTEM_DATA)) |
| 69 |
| 70 def testSimpleRootPath(self): |
| 71 provider = self._content_providers.GetByName('apples') |
| 72 self.assertEqual( |
| 73 'gala apples', |
| 74 provider.GetContentInfo(_HOST, 'gala.txt').Get().content) |
| 75 self.assertEqual( |
| 76 'granny smith apples', |
| 77 provider.GetContentInfo(_HOST, 'green/granny smith.txt').Get().content) |
| 78 |
| 79 def testComplexRootPath(self): |
| 80 provider = self._content_providers.GetByName('tomatoes') |
| 81 self.assertEqual( |
| 82 'no they aren\'t', |
| 83 provider.GetContentInfo(_HOST, 'vegetable.txt').Get().content) |
| 84 self.assertEqual( |
| 85 'cherry tomatoes', |
| 86 provider.GetContentInfo(_HOST, 'fruit/cherry.txt').Get().content) |
| 87 |
| 88 def testEmptyRootPath(self): |
| 89 provider = self._content_providers.GetByName('bananas') |
| 90 self.assertEqual( |
| 91 'gala apples', |
| 92 provider.GetContentInfo(_HOST, 'apples/gala.txt').Get().content) |
| 93 |
| 94 def testSimpleServlet(self): |
| 95 provider, path = self._content_providers.GetByServlet('apples-dir') |
| 96 self.assertEqual('apples', provider.name) |
| 97 self.assertEqual('', path) |
| 98 provider, path = self._content_providers.GetByServlet( |
| 99 'apples-dir/are/forever') |
| 100 self.assertEqual('apples', provider.name) |
| 101 self.assertEqual('are/forever', path) |
| 102 |
| 103 def testComplexServlet(self): |
| 104 provider, path = self._content_providers.GetByServlet('tomatoes-dir/are/a') |
| 105 self.assertEqual('tomatoes', provider.name) |
| 106 self.assertEqual('', path) |
| 107 provider, path = self._content_providers.GetByServlet( |
| 108 'tomatoes-dir/are/a/fruit/they/are') |
| 109 self.assertEqual('tomatoes', provider.name) |
| 110 self.assertEqual('fruit/they/are', path) |
| 111 |
| 112 def testEmptyStringServlet(self): |
| 113 provider, path = self._content_providers.GetByServlet('tomatoes-dir/are') |
| 114 self.assertEqual('bananas', provider.name) |
| 115 self.assertEqual('tomatoes-dir/are', path) |
| 116 provider, path = self._content_providers.GetByServlet('') |
| 117 self.assertEqual('bananas', provider.name) |
| 118 self.assertEqual('', path) |
| 119 |
| 120 @DisableLogging('error') |
| 121 def testProviderNotFound(self): |
| 122 self.assertEqual(None, self._content_providers.GetByName('cabbages')) |
| 123 |
| 124 |
| 125 if __name__ == '__main__': |
| 126 unittest.main() |
OLD | NEW |