Add unittest entry point for python strolet app
With this change, we are able to run the app unit tests via tox command. This one also adds a simple unit test for StorletSamples. Change-Id: I24be75dfb10aaae8db7345e7f89ddc36e93a24fa
This commit is contained in:
parent
1e5bc9afb7
commit
e4787c17c8
|
@ -20,7 +20,7 @@ from tests.functional import StorletFunctionalTest, PATH_TO_STORLETS
|
|||
class StorletPythonFunctionalTest(StorletFunctionalTest):
|
||||
def setUp(self, storlet_dir, storlet_name, storlet_main,
|
||||
container, storlet_file, dep_names=None, headers=None):
|
||||
storlet_dir = os.path.join('python', storlet_dir)
|
||||
storlet_dir = os.path.join('python', 'storlet_samples', storlet_dir)
|
||||
path_to_bundle = os.path.join(PATH_TO_STORLETS, storlet_dir)
|
||||
super(StorletPythonFunctionalTest, self).setUp('Python',
|
||||
path_to_bundle,
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
# Copyright (c) 2015, 2016 OpenStack Foundation.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from unittest import TestCase
|
||||
from cStringIO import StringIO
|
||||
|
||||
from storlet_samples.simple.simple import SimpleStorlet
|
||||
|
||||
from tests.unit import FakeLogger
|
||||
|
||||
|
||||
class FakeStorletFile(object):
|
||||
def __init__(self):
|
||||
self._call_closed = False
|
||||
|
||||
def close(self):
|
||||
self._call_closed = True
|
||||
|
||||
@property
|
||||
def closed(self):
|
||||
return self._call_closed
|
||||
|
||||
|
||||
class FakeStorletFileIn(FakeStorletFile):
|
||||
def __init__(self, input_string, metadata):
|
||||
super(FakeStorletFileIn, self).__init__()
|
||||
self._input_string = StringIO(input_string)
|
||||
self._metadata = metadata
|
||||
self._pos = 0
|
||||
|
||||
def read(self, size=-1):
|
||||
return self._input_string.read(size)
|
||||
|
||||
def get_metadata(self):
|
||||
return self._metadata
|
||||
|
||||
|
||||
class FakeStorletFileOut(FakeStorletFile):
|
||||
def __init__(self):
|
||||
super(FakeStorletFileOut, self).__init__()
|
||||
self._output_string = []
|
||||
self._metadata = None
|
||||
|
||||
def write(self, data):
|
||||
self._output_string.append(data)
|
||||
|
||||
def set_metadata(self, metadata):
|
||||
if self._metadata is None:
|
||||
self._metadata = {}
|
||||
self._metadata.update(metadata)
|
||||
|
||||
def read(self):
|
||||
return ''.join(self._output_string)
|
||||
|
||||
|
||||
class TestSimpleStorlet(TestCase):
|
||||
def setUp(self):
|
||||
self.logger = FakeLogger()
|
||||
|
||||
def test_simple_storlet(self):
|
||||
simple_storlet = SimpleStorlet(self.logger)
|
||||
input_string = 'abcdefghijklmonp'
|
||||
store_in = [FakeStorletFileIn(input_string, {})]
|
||||
store_out = [FakeStorletFileOut()]
|
||||
params = {}
|
||||
self.assertIsNone(simple_storlet(store_in, store_out, params))
|
||||
# SimpleStorlet sets metadata {'test': 'simple'}
|
||||
self.assertEqual({'test': 'simple'}, store_out[0]._metadata)
|
||||
self.assertEqual(input_string, store_out[0].read())
|
||||
self.assertTrue(store_in[0].closed)
|
||||
self.assertTrue(store_out[0].closed)
|
Loading…
Reference in New Issue