def test_create_buckets(self, obj_mock, request_mock): """Test bucket creation.""" request_mock.return_value.status_code = 200 request_mock.return_value.json.return_value = mock.sentinel.json_data obj_mock.return_value = mock.sentinel.result name = 'project_name' credentials = mock.Mock() prj = project.Project(name, credentials) result = prj.create_bucket(mock.sentinel.name, mock.sentinel.location, mock.sentinel.storage, mock.sentinel.acl, mock.sentinel.def_acl, mock.sentinel.projection) self.assertEqual(mock.sentinel.result, result) request_mock.assert_called_once_with( 'POST', 'https://www.googleapis.com/storage/v1/b?project=project_name', headers={'Authorization': mock.ANY}, json={ 'storageClass': mock.sentinel.storage, 'name': mock.sentinel.name, 'location': mock.sentinel.location }, params={ 'predefinedAcl': mock.sentinel.acl, 'projection': mock.sentinel.projection, 'predefinedDefaultObjectAcl': mock.sentinel.def_acl }) obj_mock.assert_called_once_with(mock.sentinel.json_data, credentials)
def test_init(self, mock_init): """Test init providing all arguments.""" prj = project.Project(mock.sentinel.project_id, mock.sentinel.credentials, mock.sentinel.retry_params) mock_init.assert_called_once_with(mock.sentinel.credentials, mock.sentinel.retry_params) self.assertEqual(mock.sentinel.project_id, prj.project_id)
def test_list(self, obj_mock, mock_request): """Test default bucket listing.""" expected = [{ 'kind': 'storage#buckets', 'items': [mock.sentinel.result1, mock.sentinel.result2], 'nextPageToken': mock.sentinel.next_token }, { 'kind': 'storage#buckets', 'items': [mock.sentinel.result3] }] mock_request.return_value.json.side_effect = expected expected2 = [mock.sentinel.result4, mock.sentinel.result5] obj_mock.side_effect = expected2 name = 'project_name' creds = mock.Mock() retry_params = common.RetryParams.get_default() prj = project.Project(name, creds) result = prj.list(mock.sentinel.fields, mock.sentinel.max_results, mock.sentinel.projection, mock.sentinel.prefix, mock.sentinel.page_token) self.assertEqual(expected2, result) self.assertListEqual([ mock.call(parse=True, url='https://www.googleapis.com/storage/v1/b', project=name, fields=mock.sentinel.fields, maxResults=mock.sentinel.max_results, projection=mock.sentinel.projection, prefix=mock.sentinel.prefix, pageToken=mock.sentinel.page_token), mock.call(parse=True, url='https://www.googleapis.com/storage/v1/b', project=name, fields=mock.sentinel.fields, maxResults=mock.sentinel.max_results, projection=mock.sentinel.projection, prefix=mock.sentinel.prefix, pageToken=mock.sentinel.next_token) ], mock_request.call_args_list) self.assertListEqual([ mock.call(mock.sentinel.result1, creds, retry_params), mock.call(mock.sentinel.result2, creds, retry_params), mock.call(mock.sentinel.result3, creds, retry_params) ], obj_mock.call_args_list)
def test_str(self): """Test string representation.""" name = 'project_name' prj = project.Project(name) self.assertEqual(name, str(prj))
def test_get_default_bucket_none(self): """Test getting the default bucket name for a project.""" prj = project.Project(None) self.assertEqual(None, prj.default_bucket_name)
def test_get_default_bucket(self): """Test getting the default bucket name for a project.""" name = 'project_name' prj = project.Project(name) expected = name + '.appspot.com' self.assertEqual(expected, prj.default_bucket_name)
def test_init_defaults(self, mock_init): """Test init providing only required arguments.""" prj = project.Project(mock.sentinel.project_id) mock_init.assert_called_once_with(None, None) self.assertEqual(mock.sentinel.project_id, prj.project_id)