def test_serialize(input_collection_type, input_collection, mocker): # Arrange stub = mocker.stub() mocker.patch("cobbler.modules.serializers.file.serialize_item", new=stub) if input_collection_type == "settings": mock = Settings() else: mocker.patch( "cobbler.cobbler_collections.collection.Collection.collection_types", return_value=input_collection_type) mocker.patch( "cobbler.cobbler_collections.collection.Collection.collection_type", return_value="") mock = Collection(MagicMock()) mock.listing["test"] = input_collection # Act file.serialize(mock) # Assert if input_collection_type == "settings": assert not stub.called else: assert stub.called stub.assert_called_with(mock, input_collection)
def test_to_dict(self): # Arrange test_settings = Settings() # Act result = test_settings.to_dict() # Assert assert result == test_settings.__dict__
def test_from_dict(self, parameter, expected_exception, expected_result): # Arrange test_settings = Settings() # Act with expected_exception: test_settings.from_dict(parameter) # Assert assert test_settings.server == expected_result
def test_set(self, test_name, test_value, expected_exception, expected_result): # Arrange test_settings = Settings() # Act with expected_exception: test_settings.set(test_name, test_value) # Assert assert test_settings.__dict__[test_name] == expected_result
def test_to_string(self): # Arrange test_settings = Settings() # Act result = test_settings.to_string() # Assert result_list = result.split("\n") assert len(result_list) == 3 assert result_list[1] == "kernel options : {}"
def test_settingsfile_migration_content(tmpdir: pathlib.Path): # Arrange src = "/test_dir/tests/test_data/settings_old" dst = os.path.join(tmpdir, "settings") shutil.copyfile(src, dst) # Act result_settings = settings.read_settings_file(filepath=dst) settings_obj = Settings().from_dict(result_settings) clean_settings = settings.validate_settings(settings_obj.to_dict()) # Assert assert isinstance(clean_settings, dict) assert "include" in result_settings
def settings(self) -> Settings: """ Get the application configuration. :return: Settings object. """ self.__xmlrpc_setup() return Settings().from_dict(self.remote.get_settings())
def test_link_distro(): # Arrange test_api = CobblerAPI() test_distro = Distro(test_api) # Act utils.link_distro(Settings(), test_distro) # Assert assert False
def test_find_distro_path(create_testfile, tmp_path): # Arrange test_api = CobblerAPI() fk_kernel = "vmlinuz1" create_testfile(fk_kernel) test_distro = Distro(test_api) test_distro.kernel = os.path.join(tmp_path, fk_kernel) # Act result = utils.find_distro_path(Settings(), test_distro) # Assert assert result == tmp_path.as_posix()
def test_deserialize(input_collection_type, input_collection, input_topological, expected_result, mocker): # Arrange mocker.patch("cobbler.modules.serializers.file.deserialize_raw", return_value=input_collection) if input_collection_type == "settings": stub_from = mocker.stub(name="from_dict_stub") mocker.patch.object(Settings, "from_dict", new=stub_from) mock = Settings() else: stub_from = mocker.stub(name="from_list_stub") mocker.patch.object(Collection, "from_list", new=stub_from) mock = Collection(MagicMock()) mocker.patch( "cobbler.cobbler_collections.collection.Collection.collection_types", return_value=input_collection_type) # Act file.deserialize(mock, input_topological) # Assert assert stub_from.called stub_from.assert_called_with(expected_result)