def test_patch_package_code_with_state(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" assert msi_patch.patch_package_code(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')) != -1 pos, id_ = msi_patch.load_state_file(p) assert pos == 4 assert id_ == uuid # prepare test file shutil.copy(str(src), str(dst)) # patch 2, patching failed p = conf_dir / "msi_state.yml" assert not msi_patch.patch_package_code( f_name=dst, mask="asdyebdvdbee", 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')) == -1 yaml_content = p.read_bytes() state = yaml.safe_load(yaml_content) assert state is not None pos, id_ = msi_patch.load_state_file(p) assert pos == -1 assert id_ == ""
def test_patch_package_code(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() marker = msi_patch.TRADITIONAL_UUID.encode('ascii') # prepare test file dst = conf_dir / fname shutil.copy(str(src), str(dst)) base_content = dst.read_bytes() pos = base_content.find(marker) assert pos != -1 # patch 1, default assert msi_patch.patch_package_code(f_name=dst, mask="", package_code=uuid) new_content = dst.read_bytes() check_content(new_content=new_content, base_content=base_content, pos=pos, uuid=uuid, marker=marker) # prepare test file shutil.copy(str(src), str(dst)) # patch 2 uuid = msi_patch.generate_uuid() assert msi_patch.patch_package_code(f_name=dst, mask=msi_patch.TRADITIONAL_UUID, package_code=uuid) new_content = dst.read_bytes() check_content(new_content=new_content, base_content=base_content, pos=pos, uuid=uuid, marker=marker) # prepare test file shutil.copy(str(src), str(dst)) # patch 3, mask is absent assert not msi_patch.patch_package_code(f_name=dst, mask="Cant/Be/Found/In") new_content = dst.read_bytes() assert new_content.find(marker) != -1
def test_patch_package_code(conf_dir): # prepare file to tests fname = "test_bin.tst" src = _get_test_file(fname=fname) uuid = msi_patch.generate_uuid() marker = msi_patch.TRADITIONAL_UUID.encode("ascii") # prepare test file dst = conf_dir / fname shutil.copy(str(src), str(dst)) base_content = dst.read_bytes() pos = base_content.find(marker) assert pos != -1 # patch 1, default assert msi_patch.patch_package_code(f_name=dst, mask="", package_code=uuid) new_content = dst.read_bytes() check_content(new_content=new_content, base_content=base_content, pos=pos, uuid=uuid, marker=marker) # prepare test file shutil.copy(str(src), str(dst)) # patch 2 uuid = msi_patch.generate_uuid() assert msi_patch.patch_package_code(f_name=dst, mask=msi_patch.TRADITIONAL_UUID, package_code=uuid) new_content = dst.read_bytes() check_content(new_content=new_content, base_content=base_content, pos=pos, uuid=uuid, marker=marker) # prepare test file shutil.copy(str(src), str(dst)) # patch 3, mask is absent assert not msi_patch.patch_package_code(f_name=dst, mask="Cant/Be/Found/In") new_content = dst.read_bytes() assert new_content.find(marker) != -1
def test_patch_package_code_with_state(conf_dir): # prepare file to tests fname = "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" assert msi_patch.patch_package_code(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")) != -1 _pos, _id = msi_patch.load_state_file(p) assert _pos == 4 assert _id == uuid # prepare test file shutil.copy(str(src), str(dst)) # patch 2, patching failed p = conf_dir / "msi_state.yml" assert not msi_patch.patch_package_code( f_name=dst, mask="asdyebdvdbee", 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")) == -1 yaml_content = p.read_bytes() state = yaml.safe_load(yaml_content) assert state is not None _pos, _id = msi_patch.load_state_file(p) assert _pos == -1 assert _id == ""