def test_bucket__get_valid_bucket_by_id__retrieves_bucket(self): """ Retrieving an invalid bucket results in an BucketError. """ self.mock_api.list_buckets.return_value = {"buckets": []} self.mock_api.limited_account = False blaze = B2Objects('', '', True) self.assertRaises(BucketError, blaze.bucket, 'bucket that does not exist 129307yu9')
def test_create_bucket__creates_a_bucket(self): """ Must create a bucket using the provided configuration. """ data = Responses.create_bucket.value.dict self.mock_api.create_bucket.return_value = data blaze = B2Objects('', '') bucket = blaze.create_bucket(data['bucketName'], True) self.mock_api.create_bucket.assert_called_with(data['bucketName'], True, None, None, None) self.assertTrue(isinstance(bucket, Bucket))
def test_buckets__lists_existing_buckets(self): """ Must return a list of Bucket instances associated with the api object. """ self.mock_api.list_buckets.return_value = Responses.list_buckets.value.dict blaze = B2Objects('', '') buckets = blaze.buckets() for bucket in buckets: self.assertTrue(isinstance(bucket, Bucket)) self.assertIs(bucket._api, self.mock_api) # pylint: disable = protected-access
def test_bucket__valid_bucket__retrieves_bucket(self): """ Must retrieve a single bucket matching the specified parameters. """ # Change response so that it only lists a single bucket data = Responses.list_buckets.value.dict.copy() del data['buckets'][1:] bucket_info = data['buckets'][0] # Mock the B2 service self.mock_api.list_buckets.return_value = data self.mock_api.limited_account = False blaze = B2Objects('', '') # Retrieve the bucket by name bucket = blaze.bucket(name=bucket_info['bucketName']) self.assertTrue(isinstance(bucket, Bucket)) self.assertEqual(bucket.id, bucket_info['bucketId']) # Retrieve the bucket by id bucket = blaze.bucket(bucket_id=bucket_info['bucketId']) self.assertTrue(isinstance(bucket, Bucket)) self.assertEqual(bucket.name, bucket_info['bucketName'])
def test_app_key(self): """ The app_key property must return the application key associated with the instance. """ app_key = 'app_key' self.mock_api.app_key = app_key blaze = B2Objects('', app_key) self.assertEqual(blaze.app_key, app_key)
def test_account_id(self): """ The account_id property must return the account id associated with the instance. """ account_id = 'account_id' self.mock_api.account_id = account_id blaze = B2Objects(account_id, '') self.assertEqual(blaze.account_id, account_id)
def test_init__api_initialized(self): """ The B2Objects must call the authentication method. """ account_id = 'account_id' app_key = 'app_key' B2Objects(account_id, app_key) self.mock_blaze.assert_called_with(account_id, app_key, False, None)