Added unittests for objectstorage behaviors.
Change-Id: I84a6f09935effa58df76e07887a1d47e79e59eb8
This commit is contained in:
parent
4a1cb016e8
commit
38a4239056
@ -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):
|
||||
|
15
metatests/__init__.py
Normal file
15
metatests/__init__.py
Normal file
@ -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.
|
||||
"""
|
15
metatests/objectstorage/__init__.py
Normal file
15
metatests/objectstorage/__init__.py
Normal file
@ -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.
|
||||
"""
|
15
metatests/objectstorage/objectstorage_api/__init__.py
Normal file
15
metatests/objectstorage/objectstorage_api/__init__.py
Normal file
@ -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.
|
||||
"""
|
57
metatests/objectstorage/objectstorage_api/behaviors_test.py
Normal file
57
metatests/objectstorage/objectstorage_api/behaviors_test.py
Normal file
@ -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)
|
17
metatests/objectstorage/objectstorage_api/client_test.py
Normal file
17
metatests/objectstorage/objectstorage_api/client_test.py
Normal file
@ -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'
|
@ -1 +1,3 @@
|
||||
httpretty
|
||||
mock
|
||||
unittest2
|
||||
|
Loading…
x
Reference in New Issue
Block a user