def test_write_config_when_config_is_list_should_raise_type_error(mocker): # setup mockbase = MockBase("resources") mockbase.setup(resources) config_file = mockbase.get_tmpdir() + "/config.yml" config = ["test"] mocked_config_file = _mock_get_config_file(mocker, config_file) # run and assert try: resources.write_config(config) assert False except TypeError: assert True mocked_config_file.assert_called_once()
def test_write_config_when_valid_config(mocker): # setup mockbase = MockBase("resources") mockbase.setup(resources, create_tmpdir=True) config_file = mockbase.get_tmpdir() + "/config.yml" config = {"connord": ["value", "too", {"test": "value"}]} mocked_config_file = _mock_get_config_file(mocker, config_file) # run resources.write_config(config) # assert import os mocked_config_file.assert_called_once() assert os.path.exists(config_file) # tear down mockbase.tear_down()
def test_write_config_when_error_message(mocker): # setup mockbase = MockBase("resources") mockbase.setup(resources) config_file = mockbase.get_tmpdir() + "/config.yml" config = ["test"] mocked_config_file = _mock_get_config_file(mocker, config_file) # run and assert try: resources.write_config(config) assert False except TypeError as error: assert str( error # pylint: disable=line-too-long ) == "Could not write to {!r}: Invalid type: Found <class 'list'> but expected <class 'dict'>.".format( config_file) mocked_config_file.assert_called_once()
def test_write_stats_when_valid_dict(mocker): # setup mockbase = MockBase("resources") mockbase.mock_user_is_root(mocker, True) mockbase.setup(resources, create_tmpdir=True) stats_file = mockbase.get_tmpdir() + "/stats" stats = {"connord": ["value", "too", {"test": "value"}]} mocked_stats_file = _mock_get_stats_file(mocker, stats_file) # run resources.write_stats(stats) # assert import os mocked_stats_file.assert_called_once() assert os.path.exists(stats_file) # tear down mockbase.tear_down()