def test_success_fq_sigset(self): src_sigset = tempname(10) sig_dir = f"{self.mpath}/signatures/sigset/{src_sigset}" os.makedirs(sig_dir) self.sigdirs.append(sig_dir) f = open(f"{sig_dir}/sig", "w") f.write("A sigset file") f.close() dst_name = tempname(10) self.sigdirs.append(f"{self.mpath}/signatures/sigset/{dst_name}") dst = dst_name + "@" + self.mapset_name ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, dst, self.mapset_name) self.assertFalse(ret) ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, src_sigset, self.mapset_name) self.assertTrue(ret) ret = I_signatures_rename( I_SIGFILE_TYPE_SIGSET, src_sigset + "@" + self.mapset_name, dst, ) self.assertEqual(ret, 0) ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, dst, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) self.assertTrue( os.path.isfile(f"{self.mpath}/signatures/sigset/{dst_name}/sig"))
def test_remove_nonexisting_sigset(self): # Set up files and mark for clean-up sig_name1 = tempname(10) sig_dir1 = f"{self.mpath}/signatures/sigset/{sig_name1}" os.makedirs(sig_dir1) self.sigdirs.append(sig_dir1) sigfile_name1 = f"{sig_dir1}/sig" open(sigfile_name1, "a").close() sig_name2 = tempname(10) # Do not create sig_name2 matching file sig_name3 = tempname(10) sig_dir3 = f"{self.mpath}/signatures/sig/{sig_name3}" os.makedirs(sig_dir3) self.sigdirs.append(sig_dir3) sigfile_name3 = f"{sig_dir3}/sig" open(sigfile_name3, "a").close() # Now remove one (should fail as file doesn't exist) ret = I_signatures_remove(I_SIGFILE_TYPE_SIGSET, sig_name2) self.assertEqual(ret, 1) # removed should be still absent ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, sig_name2, self.mapset_name) self.assertFalse(ret) # All others should remain ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, sig_name1, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) ret = I_find_signature(I_SIGFILE_TYPE_SIG, sig_name3, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name)
def test_remove_existing_sigset(self): # Set up files and mark for clean-up sig_name1 = tempname(10) sig_dir1 = f"{self.mpath}/signatures/sigset/{sig_name1}" os.makedirs(sig_dir1) self.sigdirs.append(sig_dir1) sigfile_name1 = f"{sig_dir1}/sig" open(sigfile_name1, "a").close() sig_name2 = tempname(10) sig_dir2 = f"{self.mpath}/signatures/sigset/{sig_name2}" os.makedirs(sig_dir2) self.sigdirs.append(sig_dir2) sigfile_name2 = f"{sig_dir2}/sig" open(sigfile_name2, "a").close() sig_name3 = tempname(10) sig_dir3 = f"{self.mpath}/signatures/sig/{sig_name3}" os.makedirs(sig_dir3) self.sigdirs.append(sig_dir3) sigfile_name3 = f"{sig_dir3}/sig" open(sigfile_name3, "a").close() # Try to remove with wrong type ret = I_signatures_remove(I_SIGFILE_TYPE_SIG, sig_name2) self.assertEqual(ret, 1) # Try to remove with wrong mapset ret = I_signatures_remove(I_SIGFILE_TYPE_SIGSET, f"{sig_name2}@PERMANENT") self.assertEqual(ret, 1) # Should be still present ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, sig_name2, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) # Now remove with correct type ret = I_signatures_remove(I_SIGFILE_TYPE_SIGSET, sig_name2) self.assertEqual(ret, 0) # removed should be gone ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, sig_name2, self.mapset_name) self.assertFalse(ret) # Others should remain ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, sig_name1, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) ret = I_find_signature(I_SIGFILE_TYPE_SIG, sig_name3, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name)
def test_success_unqualified_sigset(self): dst = tempname(10) ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, dst, self.mapset_name) self.assertFalse(ret) ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, self.src_sigset, self.src_mapset_name) self.assertTrue(ret) ret = I_signatures_copy(I_SIGFILE_TYPE_SIGSET, self.src_sigset, self.src_mapset_name, dst) self.sigdirs.append(f"{self.mpath}/signatures/sigset/{dst}") self.assertEqual(ret, 0) ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, dst, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) self.assertTrue( os.path.isfile(f"{self.mpath}/signatures/sigset/{dst}/sig"))
def test_find_sigset(self): # Non existing without a mapset ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, tempname(10), None) self.assertFalse(ret) # Non existing with a mapset ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, tempname(10), self.mapset_name) self.assertFalse(ret) # Sig with sigset type should equal non existing ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, self.sig_name2, self.mapset_name) self.assertFalse(ret) # Existing without a mapset ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, self.sig_name1, None) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) # Existing with a mapset ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, self.sig_name1, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) # Existing in a different mapset should fail ret = I_find_signature(I_SIGFILE_TYPE_SIGSET, self.sig_name1, "PERMANENT") self.assertFalse(ret)
def test_success_unqualified_sig(self): src_sig = tempname(10) sig_dir = f"{self.mpath}/signatures/sig/{src_sig}" os.makedirs(sig_dir) self.sigdirs.append(sig_dir) f = open(f"{sig_dir}/sig", "w") f.write("A sig file") f.close() dst = tempname(10) self.sigdirs.append(f"{self.mpath}/signatures/sig/{dst}") ret = I_find_signature(I_SIGFILE_TYPE_SIG, dst, self.mapset_name) self.assertFalse(ret) ret = I_find_signature(I_SIGFILE_TYPE_SIG, src_sig, self.mapset_name) self.assertTrue(ret) ret = I_signatures_rename(I_SIGFILE_TYPE_SIG, src_sig, dst) self.assertEqual(ret, 0) ret = I_find_signature(I_SIGFILE_TYPE_SIG, dst, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) self.assertTrue( os.path.isfile(f"{self.mpath}/signatures/sig/{dst}/sig"))
def test_success_fq_sig(self): dst_name = tempname(10) self.sigdirs.append(f"{self.mpath}/signatures/sig/{dst_name}") dst = dst_name + "@" + self.mapset_name ret = I_find_signature(I_SIGFILE_TYPE_SIG, dst, self.mapset_name) self.assertFalse(ret) ret = I_find_signature(I_SIGFILE_TYPE_SIG, self.src_sig, self.src_mapset_name) self.assertTrue(ret) ret = I_signatures_copy( I_SIGFILE_TYPE_SIG, self.src_sig + "@" + self.src_mapset_name, self.src_mapset_name, dst, ) self.assertEqual(ret, 0) ret = I_find_signature(I_SIGFILE_TYPE_SIG, dst, self.mapset_name) self.assertTrue(ret) ms = utils.decode(ret) self.assertEqual(ms, self.mapset_name) self.assertTrue( os.path.isfile(f"{self.mpath}/signatures/sig/{dst_name}/sig"))