storlets/tests/unit/StorletSamples/test_simple.py
Kota Tsuyuzaki 0200b993cc Move FakeStorletFile* from tests to stolets/tools
This is prep for the fundamentaly dry-run supports in ipython extension.

The classes FakeStorletFile* in the unit test cases should be useful to run
in local environment so move them under the packaging directry (i.e.
storlets/tools/testtools.py), and then let's use them in our python
storlet local environment.

And add some unit tests to get them into the storlets package!

Change-Id: Id6e8db79fe63031fd1d499f88ea832c5fb4a0363
2017-02-07 03:07:48 -08:00

43 lines
1.5 KiB
Python

# 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 storlet_samples.simple.simple import SimpleStorlet
from storlets.tools.testtools import FakeStorletFileIn, FakeStorletFileOut
from tests.unit import FakeLogger
import unittest
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)
if __name__ == '__main__':
unittest.main()