def test_removeosversion_outofbounds(): # Arrange os_signatures = Signatures() # Act & Assert with pytest.raises(ValueError): os_signatures.removeosbreed(1)
def test_importsignatures_unkown(): # Arrange os_signatures = Signatures() # Act & Assert with pytest.raises(ValueError): os_signatures.importsignatures(100, "")
def test_get_breed_index_by_name_not_existent(): # Arrange os_signatures = Signatures() # Act result = os_signatures.get_breed_index_by_name("redhat") # Assert assert result == -1
def test_addosbreed(): # Arrange os_signatures = Signatures() # Act os_signatures.addosbreed("Test") # Assert assert len(os_signatures.osbreeds) == 1
def test_breeds(): # Arrange os_signatures = Signatures() # Act os_signatures.osbreeds = [] # Assert assert [] == os_signatures.osbreeds
def test_get_breed_index_by_name(): # Arrange os_signatures = Signatures() name_to_get = "suse" os_signatures.addosbreed(name_to_get) # Act result = os_signatures.get_breed_index_by_name(name_to_get) # Assert assert result == 0
def test_importsignatures_string(): # Arrange signatures_text = "{\"breeds\": {}}" os_signatures = Signatures() # Act os_signatures.importsignatures(ImportTypes.STRING, signatures_text) # Assert # Currently we cannot check this any further but we will need additional checks for that. assert True
def test_importsignatures_url(): # Arrange url = "https://cobbler.github.io/signatures/latest.json" os_signatures = Signatures() # Act os_signatures.importsignatures(ImportTypes.URL, url) # Assert # Currently we cannot check this any further but we will need additional checks for that. assert True
def test_signaturesjson(input_data, result, raises): # Arrange os_signatures = Signatures() with raises: os_signatures.importsignatures(ImportTypes.STRING, input_data) # Act os_signatures.signaturesjson = input_data # Assert assert result == os_signatures.signaturesjson
def test_exportsignatures_string(): # Arrange os_signatures = Signatures() os_signatures.addosbreed("suse") expected = "{\"breeds\": {\"suse\": {}}}" # Act result = os_signatures.exportsignatures(ExportTypes.STRING) # Assert assert expected == result
def test_importsignatures_file(create_signatures_json, testpath): # Arrange testdata = "{\"breeds\": {}}" expected = {"breeds": {}} create_signatures_json(testdata) os_signatures = Signatures() # Act os_signatures.importsignatures(ImportTypes.FILE, testpath) # Assert assert expected == os_signatures.signaturesjson
def test_removeosversion(): # Arrange os_signatures = Signatures() os_signatures.addosbreed("suse") os_signatures.addosversion(0, "sles", Osversion()) # Act os_signatures.removeosversion(0, "sles") # Assert assert os_signatures.osbreeds[0].osversions == {}
def test_exportsignatures_file_nopath(): # Arrange os_signatures = Signatures() os_signatures.importsignatures(ImportTypes.STRING, "{\"breeds\": {}}") # Act & Assert with pytest.raises(ValueError): os_signatures.exportsignatures(ExportTypes.FILE)
def test_export_missing_rootkey(): # Arrange os_signatures = Signatures() os_signatures.importsignatures(ImportTypes.STRING, "{}") # Act & Assert with pytest.raises(AttributeError): os_signatures.jsontomodels()
def test_exportsignatures_unkown(): # Arrange os_signatures = Signatures() os_signatures.importsignatures(ImportTypes.STRING, "{\"breeds\": {}}") # Act & Assert with pytest.raises(ValueError): os_signatures.exportsignatures(100)
def test_jsontomodels(input_data, expected_data): # Arrange os_signatures = Signatures() os_signatures.importsignatures(ImportTypes.STRING, input_data) # Act os_signatures.jsontomodels() # Assert assert expected_data == os_signatures.osbreeds
def test_addosversion_empty(): # Arrange os_signatures = Signatures() os_signatures.addosbreed("suse") # Act os_signatures.addosversion(0, "sles", None) # Assert assert os_signatures.osbreeds[0].osversions["sles"] == Osversion()
def test_exportsignatures_file(testpath): # Arrange os_signatures = Signatures() os_signatures.addosbreed("suse") expected = "{\"breeds\": {\"suse\": {}}}" # Act os_signatures.exportsignatures(ExportTypes.FILE, testpath) with open(testpath, "r") as f: result = f.read() # Assert assert expected == result
def test_removeosbreed(): # Arrange os_signatures = Signatures() os_signatures.addosbreed("Test") len_before = len(os_signatures.osbreeds) # Act os_signatures.removeosbreed(0) len_after = len(os_signatures.osbreeds) # Assert assert len_before == 1 assert len_after == 0
def edit_menu(): """ Second level menu with the purpose to catch all functionality related to editing the current loaded information. """ global os_signatures choice_edit_menu = edit_menu_questions.ask() if choice_edit_menu == "Add Operating System Breed": result_edit_add_os_breed = edit_add_os_breed.ask() if not result_edit_add_os_breed: print("Empty Operating System Breed name is not allowed. Skipping add.") return if result_edit_add_os_breed in [version.name for version in os_signatures.osbreeds]: print("Chosen name \"%s\" already in the list of Operating System Breeds." % result_edit_add_os_breed) return os_signatures.addosbreed(result_edit_add_os_breed) print("We now have %s Operating System Breeds in this file." % len(os_signatures.osbreeds)) elif choice_edit_menu == "Remove Operating System Breed": update_choices(edit_remove_os_breed, get_os_breed_names()) result_edit_remove_os_breed = questionary.prompt(edit_remove_os_breed) name_to_find = result_edit_remove_os_breed["edit_remove_os_breed"] index = os_signatures.get_breed_index_by_name(name_to_find) if index != -1 and result_edit_remove_os_breed == os_signatures.osbreeds[index].name: os_signatures.removeosbreed(index) else: print("Operating System Breed not found. Doing nothing.") elif choice_edit_menu == "Edit the name of an Operating System Breed": update_choices(edit_name_os_breed_1, get_os_breed_names()) result_edit_name_os_breed_1 = questionary.prompt(edit_name_os_breed_1) name_to_find = result_edit_name_os_breed_1["edit_name_os_breed_1"] index = os_signatures.get_breed_index_by_name(name_to_find) if index != -1 and name_to_find == os_signatures.osbreeds[index].name: result_edit_name_os_breed_2 = edit_name_os_breed_2.ask() os_signatures.osbreeds[index].name = result_edit_name_os_breed_2 else: print("Operating System Breed not found. Doing nothing.") elif choice_edit_menu == "Add Operating System Version": update_choices(edit_add_os_version_1, get_os_breed_names()) result_edit_add_os_version_1 = questionary.prompt(edit_add_os_version_1) name_to_find = result_edit_add_os_version_1["edit_add_os_version_1"] index = os_signatures.get_breed_index_by_name(name_to_find) if index != -1 and name_to_find == os_signatures.osbreeds[index].name: result_edit_add_os_version_2 = questionary.prompt(edit_add_os_version_2) name_to_find_1 = result_edit_add_os_version_2["edit_add_os_version_2"] os_signatures.addosversion(index, name_to_find_1, None) else: print("Operating System Breed not found. Doing nothing.") elif choice_edit_menu == "Remove Operating System Version": update_choices(edit_remove_os_version_1, get_os_breed_names()) result_edit_remove_os_version_1 = questionary.prompt(edit_remove_os_version_1) name_to_find = result_edit_remove_os_version_1["edit_remove_os_version_1"] index = os_signatures.get_breed_index_by_name(name_to_find) if index != -1 and name_to_find == os_signatures.osbreeds[index].name: update_choices(edit_remove_os_version_2, get_os_version_names(name_to_find)) result_edit_remove_os_version_2 = questionary.prompt(edit_remove_os_version_2) name_to_find_1 = result_edit_remove_os_version_2["edit_remove_os_version_2"] os_signatures.removeosversion(index, name_to_find_1) else: print("Operating System Breed not found. Doing nothing.") elif choice_edit_menu == "Edit the information of an Operating System Version": edit_menu_breed_version_info() elif choice_edit_menu == "Start from scratch": os_signatures = Signatures() elif choice_edit_menu == "Go Back": return else: print("Unknown option selected. Returning to the main menu.")
""" The CLI. This CLI is interactive and may not be used in scripts. Please use the library for this purpose. This module contains no logic related to the library, it just contains logic for making it possible to edit the data managed by it. """ import questionary from libcobblersignatures import Signatures from libcobblersignatures.enums import ImportTypes, ExportTypes os_signatures = Signatures() # questions main_menu_questions = questionary.select( "What do you want to do?", choices=[ "Import", "Export", "Edit", "Exit" ]) import_menu_questions = questionary.select( "What is your desired source of input?", choices=[ "URL", "String", "File", "Go back"