def test_to_string(): # Arrange test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) titem = Item(test_collection_mgr) # Act titem.to_string() # Assert assert False
def test_check_for_invalid_imports(): # Arrange test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) test_templar = Templar(test_collection_mgr) testdata = "#import json" # Act & Assert with pytest.raises(CX): test_templar.check_for_invalid_imports(testdata)
def test_cheetah_macros(): # Arrange test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) templar = Templar(test_collection_mgr) # Act result = templar.render_cheetah("$myMethodInMacros(5)", {}) # Assert assert result == "Text in method: 5\n"
def test_render_cheetah(): # Arrange test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) test_templar = Templar(test_collection_mgr) # Act result = test_templar.render_cheetah("$test", {"test": 5}) # Assert assert result == '5'
def test_set_breed(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testdistro = Distro(test_manager) # Act utils.set_breed(testdistro, "redhat") # Assert assert testdistro.breed == "redhat"
def test_render(): # Arrange test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) test_templar = Templar(test_collection_mgr) # Act result = test_templar.render("", {}, None, template_type="cheetah") # Assert assert result == ""
def test_set_repo_breed(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testrepo = Repo(test_manager) # Act utils.set_repo_breed(testrepo, "yum") # Assert assert testrepo.breed == "yum"
def test_to_string_from_fields(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_distro = Distro(test_manager) # Act result = utils.to_string_from_fields(test_distro.__dict__, test_distro.get_fields()) # Assert - This test is specific to a Distro object assert len(result.splitlines()) == 19
def test_set_virt_ram(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_system = System(test_manager) # Act utils.set_virt_ram(test_system, 1024) # Assert assert test_system.virt_ram == 1024
def test_set_virt_bridge(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_system = System(test_manager) # Act utils.set_virt_bridge(test_system, "testbridge") # Assert assert test_system.virt_bridge == "testbridge"
def test_set_virt_cpus(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_system = System(test_manager) # Act -> These are develishly bad tests. Please spare me the lecture and let my joke in here. utils.set_virt_cpus(test_system, 666) # Assert assert test_system.virt_cpus == 666
def test_set_serial_baud_rate(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_system = System(test_manager) # Act utils.set_serial_baud_rate(test_system, 9600) # Assert assert test_system.serial_baud_rate == 9600
def test_link_distro(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_distro = Distro(test_manager) # Act utils.link_distro(test_manager.settings(), test_distro) # Assert assert False
def test_get_setter_methods_from_fields(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_distro = Distro(test_manager) # Act result = utils.get_setter_methods_from_fields(test_distro, test_distro.get_fields()) # Assert assert isinstance(result, dict)
def test_set_repos(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testprofile = Profile(test_manager) # Act # TODO: Test this also with the bypass check utils.set_repos(testprofile, "testrepo1 testrepo2", bypass_check=True) # Assert assert testprofile.repos == ["testrepo1", "testrepo2"]
def test_set_serial_device(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_system = System(test_manager) # Act result = utils.set_serial_device(test_system, 0) # Assert assert result assert test_system.serial_device == 0
def test_set_arch(test_architecture, test_raise): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testdistro = Distro(test_manager) # Act with test_raise: utils.set_arch(testdistro, test_architecture) # Assert assert testdistro.arch == test_architecture
def test_find_distro_path(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_distro = Distro(test_manager) test_distro.kernel = "/dev/shm/fakekernelfile" # Act result = utils.find_distro_path(test_manager.settings(), test_distro) # Assert assert result == "/dev/shm"
def test_set_virt_disk_driver(test_driver, expected_result, test_raise): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testprofile = Profile(test_manager) # Act with test_raise: utils.set_virt_disk_driver(testprofile, test_driver) # Assert assert testprofile.virt_disk_driver == expected_result
def test_set_virt_path(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_system = System(test_manager) test_location = "/somerandomfakelocation" # Act utils.set_virt_path(test_system, test_location) # Assert assert test_system.virt_path == test_location
def test_render_jinja2(): # Arrange test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) test_templar = Templar(test_collection_mgr) # Act result = test_templar.render_jinja2("{{ foo }}", {"foo": "Test successful"}) # Assert assert result == "Test successful"
def test_set_virt_pxe_boot(test_input, expected_exception): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_system = System(test_manager) # Act with expected_exception: result = utils.set_virt_pxe_boot(test_system, test_input) # Assert assert test_system.virt_pxe_boot == 0 or test_system.virt_pxe_boot == 1
def test_set_repo_os_version(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testrepo = Repo(test_manager) testrepo.set_breed("yum") # Act utils.set_repo_os_version(testrepo, "rhel4") # Assert assert testrepo.breed == "yum" assert testrepo.os_version == "rhel4"
def test_set_os_version(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testdistro = Distro(test_manager) testdistro.set_breed("redhat") # Act utils.set_os_version(testdistro, "rhel4") # Assert assert testdistro.breed == "redhat" assert testdistro.os_version == "rhel4"
def test_set_virt_file_size(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testprofile = Profile(test_manager) # Act # TODO: Test multiple disks via comma separation utils.set_virt_file_size(testprofile, "8") # Assert assert isinstance(testprofile.virt_file_size, int) assert testprofile.virt_file_size == 8
def test_set_virt_auto_boot(test_autoboot, expectation): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) testprofile = Profile(test_manager) # Act with expectation: utils.set_virt_auto_boot(testprofile, test_autoboot) # Assert assert isinstance(testprofile.virt_auto_boot, bool) assert testprofile.virt_auto_boot is True or testprofile.virt_auto_boot is False
def test_to_dict(): # Arrange test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) titem = Distro(test_collection_mgr) # Act result = titem.to_dict() # Assert assert isinstance(result, dict) assert "autoinstall_meta" in result assert "ks_meta" in result
def test_copy_single_distro_file(): # Instantiate TFTPGen class with collection_mgr parameter test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) generator = tftpgen.TFTPGen(test_collection_mgr) # Arrange distro_file = "/code/tests/test_data/dummy_initramfs" distro_dir = "/srv/tftpboot/images/" symlink_ok = True initramfs_dst_path = "/srv/tftpboot/images/dummy_initramfs" # Act generator.copy_single_distro_file(distro_file, distro_dir, symlink_ok) # Assert assert os.path.isfile(initramfs_dst_path)
def test_kopts_overwrite(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_distro = Distro(test_manager) test_distro.set_breed("suse") test_distro.name = "kopts_test_distro" test_profile = Profile(test_manager) test_profile.distro = test_distro.name test_system = System(test_manager) test_system.name = "kopts_test_system" kopts = {"textmode": False, "text": True} # Act utils.kopts_overwrite(test_system, test_distro, kopts, test_api.settings()) # Assert assert "textmode" in kopts assert "info" in kopts
def test_copy_bootloaders(tmpdir): # Instantiate TFTPGen class with collection_mgr parameter test_api = CobblerAPI() test_collection_mgr = CollectionManager(test_api) generator = tftpgen.TFTPGen(test_collection_mgr) # Arrange ## Create temporary bootloader files using tmpdir fixture file_contents = "I am a bootloader" sub_path = tmpdir.mkdir("loaders") sub_path.join("bootloader1").write(file_contents) sub_path.join("bootloader2").write(file_contents) ## Copy temporary bootloader files from tmpdir to expected source directory for file in glob.glob(str(sub_path + "/*")): bootloader_src = "/var/lib/cobbler/loaders/" shutil.copy(file, bootloader_src + file.split("/")[-1]) # Act generator.copy_bootloaders("/srv/tftpboot") # Assert assert os.path.isfile("/srv/tftpboot/bootloader1") assert os.path.isfile("/srv/tftpboot/bootloader2")