Permalink
Browse files

Added tox.ini. Removed integration tests

  • Loading branch information...
1 parent 8088180 commit 444efe9c12c84eb9e3bbf6a949c69f562ee73872 @sudorandom sudorandom committed Jun 18, 2012
@@ -3,7 +3,6 @@
See COPYING for license information
"""
-from object_storage.client import Client
import object_storage.consts
__version__ = object_storage.consts.__version__
@@ -30,6 +29,7 @@ def get_httplib2_client(username, password, auth_url=None, auth_token=None, **kw
@param auth_token: If provided, bypasses authentication and uses the given auth_token
@return: `object_storage.client.Client`
"""
+ from object_storage.client import Client
from object_storage.transport.httplib2conn import AuthenticatedConnection, Authentication
auth = Authentication(username, password, auth_url=auth_url, auth_token=auth_token, **kwargs)
@@ -40,6 +40,7 @@ def get_httplib2_client(username, password, auth_url=None, auth_token=None, **kw
def get_requests_client(username, password, auth_url=None, auth_token=None, **kwargs):
""" Returns an Object Storage client (using Requests) """
+ from object_storage.client import Client
from object_storage.transport.requestsconn import AuthenticatedConnection, Authentication
auth = Authentication(username, password, auth_url=auth_url, auth_token=auth_token, **kwargs)
@@ -50,6 +51,7 @@ def get_requests_client(username, password, auth_url=None, auth_token=None, **kw
def get_twisted_client(username, password, auth_url=None, auth_token=None, **kwargs):
""" Returns an Object Storage client (using Twisted) """
+ from object_storage.client import Client
from object_storage.transport.twist import AuthenticatedConnection, Authentication
auth = Authentication(username, password, auth_url=auth_url, auth_token=auth_token, **kwargs)
View
@@ -3,7 +3,7 @@
See COPYING for license information.
"""
-from object_storage.utils import json
+from object_storage.utils import json, Model
from object_storage.container import Container
from object_storage.storage_object import StorageObject
@@ -12,11 +12,10 @@
from object_storage import errors
import logging
-import UserDict
logger = logging.getLogger(__name__)
-class AccountModel(UserDict.UserDict):
+class AccountModel(Model):
def __init__(self, controller, headers={}):
_headers = {}
@@ -4,14 +4,13 @@
See COPYING for license information
"""
import os
-from object_storage.utils import json
-import UserDict
+from object_storage.utils import json, Model
from object_storage import errors
from object_storage.storage_object import StorageObject
from object_storage.utils import get_path
-class ContainerModel(UserDict.UserDict):
+class ContainerModel(Model):
def __init__(self, controller, name, headers={}):
self.name = name
_headers = {}
View
@@ -5,7 +5,7 @@
"""
-class ObjectStorageError(StandardError):
+class ObjectStorageError(Exception):
""" A general Object Storage error. """
pass
@@ -3,11 +3,13 @@
See COPYING for license information
"""
-from object_storage.utils import json
+from object_storage.utils import json, Model
import mimetypes
import os
-import StringIO
-import UserDict
+try:
+ import StringIO
+except ImportError:
+ from io import StringIO as StringIO
try:
from hashlib import md5
except ImportError:
@@ -17,7 +19,7 @@
from object_storage.utils import get_path
-class StorageObjectModel(UserDict.UserDict):
+class StorageObjectModel(Model):
def __init__(self, controller, container, name, headers={}):
self.container = container
self.name = name
@@ -168,7 +168,7 @@ def send(self, chunk):
self.req.send(chunk)
except timeout, err:
raise err
- except Exception, err:
+ except:
raise ResponseError(0, 'Disconnected')
def finish(self):
@@ -178,6 +178,8 @@ def finish(self):
self.req.send("0\r\n\r\n")
except timeout, err:
raise err
+ except:
+ raise ResponseError(0, 'Disconnected')
res = self.req.getresponse()
content = res.read()
View
@@ -5,6 +5,7 @@
"""
import urllib
+import sys
try:
import json
@@ -17,13 +18,36 @@
except ImportError:
ImportError("Requires a json parsing library")
+try:
+ from UserDict import DictMixin
+except ImportError:
+ from collections import MutableMapping as DictMixin
+
+
+class Model(DictMixin):
+ def __getitem__(self, key):
+ return self.properties[key]
-def unicode_quote(s):
- """ Solves an issue with url-quoting unicode strings"""
- if isinstance(s, unicode):
- return urllib.quote(s.encode("utf-8"))
- else:
- return urllib.quote(str(s))
+ def __setitem__(self, key, item):
+ self.properties[key] = item
+
+ def __delitem__(self, key):
+ del self.properties[key]
+
+ def keys(self):
+ return self.properties.keys()
+
+if sys.version_info >= (3,):
+ def unicode_quote(s):
+ from urllib.parse import quote
+ return quote(s)
+else:
+ def unicode_quote(s):
+ """ Solves an issue with url-quoting unicode strings"""
+ if isinstance(s, unicode):
+ return urllib.quote(s.encode("utf-8"))
+ else:
+ return urllib.quote(str(s))
def get_path(parts=None):
View
@@ -1,9 +1,22 @@
#!/usr/bin/python
from setuptools import setup, find_packages
-from object_storage import __version__
+import sys
+from object_storage.consts import __version__
name = 'softlayer-object-storage'
version = __version__
+_ver = sys.version_info
+
+requirements = ['httplib2']
+if _ver[0] == 2 and _ver[1] < 6:
+ requirements.append('simplejson')
+
+
+# Python 3 conversion
+extra = {}
+if sys.version_info >= (3,):
+ extra['use_2to3'] = True
+
setup(
name=name,
version=version,
@@ -22,9 +35,8 @@
author_email='sldn@softlayer.com',
url='https://github.com/softlayer/softlayer-object-storage-python',
license='MIT',
- packages=find_packages(exclude=['test', 'ez_setup', 'examples']),
test_suite='tests',
- install_requires=['httplib2'],
- setup_requires=['mock'],
- namespace_packages=[]
+ packages=find_packages(exclude=['tests']),
+ install_requires=requirements,
+ **extra
)
No changes.
@@ -1,135 +0,0 @@
-import unittest
-import time
-import os
-from object_storage import get_httplib2_client
-import ConfigParser
-
-
-class ClientTest(unittest.TestCase):
- container_name = 'python_test_container'
- object_name = 'python_test_object'
-
- def setUp(self):
- config = ConfigParser.ConfigParser()
- config.read(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'user.conf'))
- account = dict(config.items('account'))
- username = account.get('username')
- api_key = account.get('api_key')
- auth_url = account.get('auth_url')
- datacenter = account.get('datacenter')
- network = account.get('network')
- protocol = account.get('protocol')
- self.client = get_httplib2_client(username, api_key,
- auth_url=auth_url,
- protocol=protocol,
- datacenter=datacenter,
- network=network)
-
- def tearDown(self):
- for container in self.client:
- if container.name.startswith('python_test'):
- for obj in container:
- if obj.name.startswith('python_test'):
- obj.delete()
- container.delete()
-
- def filter_by_name(self, lst):
- new_list = []
- for item in lst:
- if item.name.startswith('python_test'):
- new_list.append(item)
- return new_list
-
- def test_auth_setup(self):
- self.client.conn.auth.authenticate()
-
- def test_create_container(self):
- container = self.client[self.container_name].create()
- container = self.client[self.container_name].load()
- self.assert_(container.props['name'] == self.container_name, "Container name matches")
- self.assert_(container.props['count'] == 0, "Container count is 0")
- self.assert_(container.props['size'] == 0.0, "Container size is 0")
-
- def test_create_object(self):
- container = self.client[self.container_name].create()
- obj = container[self.object_name]
- obj.content_type = "text/html"
- obj.create()
- obj.send("<html></html>")
- obj = container[self.object_name].load()
- self.assert_(obj.props['hash'] == 'c83301425b2ad1d496473a5ff3d9ecca', "Hash matches")
- self.assert_(obj.props['content_type'] == "text/html", "Content-type matches")
- self.assert_(obj.props['size'] == 13.0, "Size matches")
- self.assert_(obj.read() == "<html></html>", "Object body matches")
-
- def test_enable_cdn(self):
- container = self.client[self.container_name].create()
- lst = self.client.public_containers()
- container.enable_cdn()
- time.sleep(2)
- lst = self.client.public_containers()
-
- result_list = self.filter_by_name(lst)
- self.assert_(len(result_list) == 1)
- self.assert_(result_list.pop().name == self.container_name, "The container has CDN enabled")
- self.assert_(container.props['read'] == ".r:*", "The container has read property set")
- container.delete()
- time.sleep(2)
- lst = self.client.public_containers()
- result_list = self.filter_by_name(lst)
- self.assert_(len(result_list) == 0)
-
- def test_set_ttl(self):
- container = self.client[self.container_name].create()
- container.set_ttl(1000)
- self.assert_(self.client[self.container_name].load().props['ttl'] == 1000, "TTL is set correctly")
-
- container.set_ttl(None)
- self.assert_(self.client[self.container_name].load().props['ttl'] == 0, "TTL is cleared correctly")
-
- def test_search_container(self):
- time.sleep(2)
- results = self.client.search({'q': '*'})
- result_list = self.filter_by_name(results['results'])
- self.assert_(len(result_list) == 0, "Search returns no results")
-
- container = self.client[self.container_name].create()
- time.sleep(2)
- results = self.client.search('*test*', type='container')
- result_list = self.filter_by_name(results['results'])
- self.assert_(len(result_list) == 1, "Correct amount of search results")
- self.assert_(result_list.pop().name == self.container_name, "Correct search result name")
-
- container.delete()
- time.sleep(2)
- results = self.client.search('*test*', type='container')
- result_list = self.filter_by_name(results['results'])
- self.assert_(len(result_list) == 0, "Search returns no results")
-
- def test_search_object(self):
- time.sleep(2)
- results = self.client.search('*test*')
- result_list = self.filter_by_name(results['results'])
- self.assert_(len(result_list) == 0, "Search returns no results")
-
- container = self.client[self.container_name].create()
- obj = container[self.object_name]
- obj.content_type = 'application/text'
- obj.create()
- time.sleep(3)
-
- results = self.client.search('*test*', type='object')
- result_list = self.filter_by_name(results['results'])
- self.assert_(len(result_list) == 1, "Correct amount of search results")
- self.assert_(result_list.pop().name == self.object_name, "Correct search result name")
-
- results = self.client.search('*test*', type='object', content_type='application/text')
- result_list = self.filter_by_name(results['results'])
- self.assert_(len(result_list) == 1, "Correct amount of search results")
- self.assert_(result_list.pop().name == self.object_name, "Correct search result name")
-
- obj.delete()
- time.sleep(2)
- results = self.client.search('*test*', type='object')
- result_list = self.filter_by_name(results['results'])
- self.assert_(len(result_list) == 0, "Search returns no results")
@@ -1 +0,0 @@
-#
No changes.
@@ -1,16 +1,23 @@
-import unittest
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
from object_storage.transport import BaseAuthentication
+
class BaseAuthenticationTest(unittest.TestCase):
def test_instance_setup(self):
self.assert_(self.auth.storage_url == None, "Storage url is set correctly")
self.assert_(self.auth.auth_token == None, "auth_token set correctly")
-
+
def test_authenticate(self):
self.auth.authenticate()
self.assert_(self.auth.storage_url == 'STORAGE_URL', "storage_url set correctly")
self.assert_(self.auth.auth_token == 'AUTH_TOKEN', "auth_token set correctly")
def setUp(self):
self.auth = BaseAuthentication(auth_url='auth_url')
+
+if __name__ == "__main__":
+ unittest.main()
Oops, something went wrong.

0 comments on commit 444efe9

Please sign in to comment.