Add a test for swift path computation

This commit is contained in:
Jake Moshenko 2016-01-15 11:15:40 -05:00
parent c6d7eba98d
commit 909e7d45b7
7 changed files with 74 additions and 27 deletions

42
test/test_swift.py Normal file
View file

@ -0,0 +1,42 @@
import unittest
from storage.swift import SwiftStorage
from mock import MagicMock
class TestSwiftStorage(SwiftStorage):
def __init__(self, *args, **kwargs):
super(TestSwiftStorage, self).__init__(*args, **kwargs)
self._connection = MagicMock()
def _get_connection(self):
return self._connection
class SwiftTests(unittest.TestCase):
base_args = {
'metric_queue': None,
'swift_container': 'container-name',
'storage_path': '/basepath',
'auth_url': 'https://auth.com',
'swift_user': 'root',
'swift_password': 'password',
}
def test_fixed_path_concat(self):
swift = TestSwiftStorage(**self.base_args)
swift.exists('object/path')
swift._get_connection().head_object.assert_called_with('container-name', 'basepath/object/path')
def test_simple_path_concat(self):
simple_concat_args = dict(self.base_args)
simple_concat_args['simple_path_concat'] = True
swift = TestSwiftStorage(**simple_concat_args)
swift.exists('object/path')
swift._get_connection().head_object.assert_called_with('container-name', 'basepathobject/path')
if __name__ == '__main__':
unittest.main()