|
22 | 22 | from ..test_base import TestBase |
23 | 23 |
|
24 | 24 |
|
| 25 | +class TestServices(TestBase): |
| 26 | + def setUp(self): |
| 27 | + self.account_info = InMemoryAccountInfo() |
| 28 | + self.cache = InMemoryCache() |
| 29 | + |
| 30 | + def test_api_initialization(self): |
| 31 | + class DummyA: |
| 32 | + def __init__(self, *args, **kwargs): |
| 33 | + pass |
| 34 | + |
| 35 | + class DummyB: |
| 36 | + def __init__(self, *args, **kwargs): |
| 37 | + pass |
| 38 | + |
| 39 | + for kwargs, _raw_api_class in [ |
| 40 | + ( |
| 41 | + dict( |
| 42 | + max_upload_workers = 1, |
| 43 | + max_copy_workers = 2, |
| 44 | + max_download_workers = 3, |
| 45 | + save_to_buffer_size = 4, |
| 46 | + check_download_hash = False, |
| 47 | + max_download_streams_per_file = 5, |
| 48 | + ), |
| 49 | + DummyA, |
| 50 | + ), |
| 51 | + ( |
| 52 | + dict( |
| 53 | + max_upload_workers = 2, |
| 54 | + max_copy_workers = 3, |
| 55 | + max_download_workers = 4, |
| 56 | + save_to_buffer_size = 5, |
| 57 | + check_download_hash = True, |
| 58 | + max_download_streams_per_file = 6, |
| 59 | + ), |
| 60 | + DummyB, |
| 61 | + ) |
| 62 | + ]: # yapf: disable |
| 63 | + |
| 64 | + api_config = B2HttpApiConfig(_raw_api_class=_raw_api_class) |
| 65 | + |
| 66 | + self.api = B2Api( |
| 67 | + self.account_info, |
| 68 | + self.cache, |
| 69 | + api_config=api_config, |
| 70 | + |
| 71 | + **kwargs |
| 72 | + ) # yapf: disable |
| 73 | + |
| 74 | + assert self.api.account_info is self.account_info |
| 75 | + assert self.api.api_config is api_config |
| 76 | + assert self.api.cache is self.cache |
| 77 | + |
| 78 | + assert self.api.session.account_info is self.account_info |
| 79 | + assert self.api.session.cache is self.cache |
| 80 | + assert isinstance(self.api.session.raw_api, _raw_api_class) |
| 81 | + |
| 82 | + assert isinstance(self.api.file_version_factory, B2Api.FILE_VERSION_FACTORY_CLASS) |
| 83 | + assert isinstance( |
| 84 | + self.api.download_version_factory, |
| 85 | + B2Api.DOWNLOAD_VERSION_FACTORY_CLASS, |
| 86 | + ) |
| 87 | + |
| 88 | + services = self.api.services |
| 89 | + assert isinstance(services, B2Api.SERVICES_CLASS) |
| 90 | + |
| 91 | + # max copy/upload/download workers could only be verified with mocking |
| 92 | + |
| 93 | + download_manager = services.download_manager |
| 94 | + assert isinstance(download_manager, services.DOWNLOAD_MANAGER_CLASS) |
| 95 | + |
| 96 | + assert download_manager.write_buffer_size == kwargs['save_to_buffer_size'] |
| 97 | + assert download_manager.check_hash == kwargs['check_download_hash'] |
| 98 | + assert download_manager.strategies[0].max_streams == kwargs[ |
| 99 | + 'max_download_streams_per_file'] |
| 100 | + |
| 101 | + |
25 | 102 | class TestApi(TestBase): |
26 | 103 | def setUp(self): |
27 | 104 | self.account_info = InMemoryAccountInfo() |
|
0 commit comments