![Hervé Beraud](/assets/img/avatar_default.png)
The mock third party library was needed for mock support in py2 runtimes. Since we now only support py36 and later, we can use the standard lib unittest.mock module instead. Note that https://github.com/openstack/charms.openstack is used during tests and he need `mock`, unfortunatelly it doesn't declare `mock` in its requirements so it retrieve mock from other charm project (cross dependency). So we depend on charms.openstack first and when Ib1ed5b598a52375e29e247db9ab4786df5b6d142 will be merged then CI will pass without errors. Drop Python 3.5 testing. Rework some unit tests that use unittest.mock features not introduced until Python 3.7. Depends-On: Ib1ed5b598a52375e29e247db9ab4786df5b6d142 Change-Id: I029c77ed697620725dc040d1849a691eb10c9351
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
# Copyright 2018 Canonical Ltd
|
|
#
|
|
# 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 sys
|
|
|
|
from unittest.mock import patch
|
|
|
|
from test_utils import CharmTestCase
|
|
|
|
import fernet_rotate_and_sync as script
|
|
|
|
|
|
class FernetRotateAndSync(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(FernetRotateAndSync, self).setUp(
|
|
script, [])
|
|
|
|
@patch('charmhelpers.core.hookenv.log')
|
|
@patch('time.ctime')
|
|
@patch('builtins.print')
|
|
def test_cli_log(self, mock_print, mock_ctime, mock_ch_log):
|
|
mock_ctime.return_value = 'FAKE_TIMESTAMP'
|
|
script.cli_log('message', level='DEBUG')
|
|
mock_ch_log.assert_called_with('message', level='DEBUG')
|
|
script.cli_log('message', level='WARNING')
|
|
mock_print.assert_called_with('FAKE_TIMESTAMP: message',
|
|
file=sys.stderr)
|
|
script.cli_log('message', level='INFO')
|
|
mock_print.assert_called_with('FAKE_TIMESTAMP: message',
|
|
file=sys.stdout)
|