def test_patch_package_code_by_state_file(conf_dir, cmk_dir): # prepare file to tests if not cmk_dir.exists(): pytest.skip("cmk_dir is not good") fname = u"test_bin.tst" src = cmk_dir / u"agents/wnx/test_files/msibuild/msi" / fname if not src.exists(): pytest.skip("Path with MSI doesn't exist") uuid = msi_patch.generate_uuid() # prepare test file dst = conf_dir / fname shutil.copy(str(src), str(dst)) base_content = dst.read_bytes() assert base_content.find(msi_patch.TRADITIONAL_UUID.encode('ascii')) != -1 # patch 1, patching is successful p = conf_dir / "msi_state.yml" msi_patch.write_state_file(p, 4, msi_patch.TRADITIONAL_UUID) assert msi_patch.patch_package_code_by_state_file(f_name=dst, package_code=uuid, state_file=p) assert dst.stat().st_size == src.stat().st_size new_content = dst.read_bytes() assert new_content.find(uuid.encode('ascii')) == 4
def test_low_level_functions(conf_dir): assert msi_patch.MSI_PACKAGE_CODE_OFFSET == 20 assert msi_patch.MSI_PACKAGE_CODE_MARKER == "Intel;1033" assert msi_patch.generate_uuid() != msi_patch.generate_uuid() assert len(msi_patch.generate_uuid()) == 38 p = conf_dir / "msi_state.yml" msi_patch.write_state_file(p, 12, "12") _pos, _id = msi_patch.load_state_file(p) assert _pos == 12 assert _id == "12"
def test_patch_package_code_by_state_file(conf_dir): # prepare file to tests fname = u"test_bin.tst" src = _get_test_file(fname=fname) uuid = msi_patch.generate_uuid() # prepare test file dst = conf_dir / fname shutil.copy(str(src), str(dst)) base_content = dst.read_bytes() assert base_content.find(msi_patch.TRADITIONAL_UUID.encode('ascii')) != -1 # patch 1, patching is successful p = conf_dir / "msi_state.yml" msi_patch.write_state_file(p, 4, msi_patch.TRADITIONAL_UUID) assert msi_patch.patch_package_code_by_state_file(f_name=dst, package_code=uuid, state_file=p) assert dst.stat().st_size == src.stat().st_size new_content = dst.read_bytes() assert new_content.find(uuid.encode('ascii')) == 4