1010
1111import pytest
1212
13- from apiver_deps import B2Api
13+ from apiver_deps import B2Api , BucketTrackingMixin
1414from apiver_deps import B2HttpApiConfig
1515from apiver_deps import Bucket
1616from apiver_deps import InMemoryCache
@@ -102,11 +102,13 @@ def test_api_initialization(self, kwargs, _raw_api_class):
102102 assert download_manager .strategies [0 ].max_streams == kwargs ['max_download_streams_per_file' ]
103103
104104
105- class TestApi (TestBase ):
105+ class TestApiBase (TestBase ):
106+ B2_API_CLASS = B2Api
107+
106108 def setUp (self ):
107109 self .account_info = InMemoryAccountInfo ()
108110 self .cache = InMemoryCache ()
109- self .api = B2Api (
111+ self .api = self . B2_API_CLASS (
110112 self .account_info , self .cache , api_config = B2HttpApiConfig (_raw_api_class = RawSimulator )
111113 )
112114 self .raw_api = self .api .session .raw_api
@@ -115,6 +117,8 @@ def setUp(self):
115117 def _authorize_account (self ):
116118 self .api .authorize_account ('production' , self .application_key_id , self .master_key )
117119
120+
121+ class TestApi (TestApiBase ):
118122 @pytest .mark .apiver (to_ver = 1 )
119123 def test_get_bucket_by_id_up_to_v1 (self ):
120124 bucket = self .api .get_bucket_by_id ("this id doesn't even exist" )
@@ -158,3 +162,24 @@ def test_get_download_url_for_fileid(self):
158162 download_url = self .api .get_download_url_for_fileid ('file-id' )
159163
160164 assert download_url == 'http://download.example.com/b2api/v2/b2_download_file_by_id?fileId=file-id'
165+
166+
167+ class TestBucketTrackingMixin (TestApiBase ):
168+ class BucketTrackingApi (BucketTrackingMixin , B2Api ):
169+ pass
170+
171+ B2_API_CLASS = BucketTrackingApi
172+
173+ def test_bucket_tracking (self ):
174+ self ._authorize_account ()
175+
176+ bucket_1 , bucket_2 , bucket_3 = [
177+ self .api .create_bucket (f'bucket-{ i + 1 } ' , 'allPrivate' ) for i in range (3 )
178+ ]
179+
180+ self .api .delete_bucket (bucket_2 )
181+ self .api .delete_bucket (bucket_3 )
182+
183+ bucket_4 = self .api .create_bucket ('bucket-4' , 'allPrivate' )
184+
185+ assert {bucket .id_ for bucket in self .api .buckets } == {bucket_1 .id_ , bucket_4 .id_ }
0 commit comments