diff --git a/cloudcafe/objectstorage/objectstorage_api/behaviors.py b/cloudcafe/objectstorage/objectstorage_api/behaviors.py index 721452f1..66dcf4f2 100644 --- a/cloudcafe/objectstorage/objectstorage_api/behaviors.py +++ b/cloudcafe/objectstorage/objectstorage_api/behaviors.py @@ -22,9 +22,12 @@ from cloudcafe.objectstorage.objectstorage_api.client \ class ObjectStorageAPI_Behaviors(BaseBehavior): - def __init__(self, client=None): + def __init__(self, client=None, config=None): self.client = client - self.config = ObjectStorageAPIConfig() + if config: + self.config = config + else: + self.config = ObjectStorageAPIConfig() @behavior(ObjectStorageAPIClient) def create_container(self, name=None): diff --git a/metatests/__init__.py b/metatests/__init__.py new file mode 100644 index 00000000..59ab77fa --- /dev/null +++ b/metatests/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2013 Rackspace + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" diff --git a/metatests/objectstorage/__init__.py b/metatests/objectstorage/__init__.py new file mode 100644 index 00000000..59ab77fa --- /dev/null +++ b/metatests/objectstorage/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2013 Rackspace + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" diff --git a/metatests/objectstorage/objectstorage_api/__init__.py b/metatests/objectstorage/objectstorage_api/__init__.py new file mode 100644 index 00000000..59ab77fa --- /dev/null +++ b/metatests/objectstorage/objectstorage_api/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2013 Rackspace + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" diff --git a/metatests/objectstorage/objectstorage_api/behaviors_test.py b/metatests/objectstorage/objectstorage_api/behaviors_test.py new file mode 100644 index 00000000..c62850ed --- /dev/null +++ b/metatests/objectstorage/objectstorage_api/behaviors_test.py @@ -0,0 +1,57 @@ +""" +Copyright 2013 Rackspace + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import unittest +from mock import MagicMock +from mock import Mock +from requests import Response + +from cloudcafe.objectstorage.objectstorage_api.behaviors \ + import ObjectStorageAPI_Behaviors +from cloudcafe.objectstorage.objectstorage_api.client \ + import ObjectStorageAPIClient +from cloudcafe.objectstorage.objectstorage_api.config \ + import ObjectStorageAPIConfig +from metatests.objectstorage.objectstorage_api import client_test + + +class ApiBehaviorsTest(unittest.TestCase): + + def test_create_container(self): + response = Mock(spec=Response) + response.ok = True + + client = Mock(spec=ObjectStorageAPIClient) + client.create_container = MagicMock(return_value=response) + + config = Mock(spec=ObjectStorageAPIConfig) + + behavior = ObjectStorageAPI_Behaviors(client, config) + behavior.create_container(client_test.VALID_CONTAINER_NAME) + client.create_container.assert_called_with( + client_test.VALID_CONTAINER_NAME) + + def test_throws_exception_if_create_container_fails(self): + response = Mock(spec=Response) + response.ok = False + + client = Mock(spec=ObjectStorageAPIClient) + client.create_container = MagicMock(return_value=response) + + config = Mock(spec=ObjectStorageAPIConfig) + + behavior = ObjectStorageAPI_Behaviors(client, config) + with self.assertRaises(Exception): + behavior.create_container(client_test.VALID_CONTAINER_NAME) diff --git a/metatests/objectstorage/objectstorage_api/client_test.py b/metatests/objectstorage/objectstorage_api/client_test.py new file mode 100644 index 00000000..70d8ce11 --- /dev/null +++ b/metatests/objectstorage/objectstorage_api/client_test.py @@ -0,0 +1,17 @@ +""" +Copyright 2013 Rackspace + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +VALID_CONTAINER_NAME = 'foo' diff --git a/pip-requires b/pip-requires index b0284b10..b8682a13 100644 --- a/pip-requires +++ b/pip-requires @@ -1 +1,3 @@ httpretty +mock +unittest2