def test_replace_not_installed(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) e2 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES2) self.assertFalse(db.has_artifact(e1.artifact_descriptor)) with self.assertRaises(NotInstalledError) as context: db.replace_artifact(e2)
def test_list_all_by_metadata(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES2) db.add_artifact(e1) self.assertEqual([e1], db.list_all_by_metadata()) db.add_artifact(e2) self.assertEqual([e2, e1], db.list_all_by_metadata())
def test_list_all_by_package_descriptor(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES2) pd1 = PD('foo', '1.2.3-1') pd2 = PD('bar', '5.6.7-1') db.add_artifact(e1) self.assertEqual([pd1], db.list_all_by_package_descriptor()) db.add_artifact(e2) self.assertEqual([pd2, pd1], db.list_all_by_package_descriptor())
def test_list_all_by_descriptor_with_build_target(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES2) db.add_artifact(e1) db.add_artifact(e2) self.assertEqual([e2.artifact_descriptor], db.list_all_by_descriptor(build_target=self.LINUX_BT)) self.assertEqual([e1.artifact_descriptor], db.list_all_by_descriptor(build_target=self.MACOS_BT))
def test_replace(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) e2 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES2) self.assertFalse(db.has_artifact(e1.artifact_descriptor)) db.add_artifact(e1) self.assertTrue(db.has_artifact(e1.artifact_descriptor)) self.assertEqual([e1.artifact_descriptor], db.list_all_by_descriptor()) db.replace_artifact(e2) self.assertEqual([e2.artifact_descriptor], db.list_all_by_descriptor())
def test_add(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) adesc = e.artifact_descriptor self.assertFalse(db.has_artifact(adesc)) db.add_artifact(e) self.assertTrue(db.has_artifact(adesc))
def test_add_duplicate(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) adesc = e.artifact_descriptor self.assertFalse(db.has_artifact(adesc)) db.add_artifact(e) self.assertTrue(db.has_artifact(adesc)) with self.assertRaises(AlreadyInstalledError) as context: db.add_artifact(e)
def test_get(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) adesc = e.artifact_descriptor with self.assertRaises(NotInstalledError) as context: db.get_artifact(adesc) db.add_artifact(e) self.assertEqual(e, db.get_artifact(adesc)) db.remove_artifact(adesc) with self.assertRaises(NotInstalledError) as context: db.get_artifact(adesc)
def test_find(self): tmp_db = self._make_tmp_db_path() db = DB(tmp_db) e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release', ('x86_64', ), '', '', [], {}, self.TEST_FILES) adesc = e.artifact_descriptor self.assertEqual(None, db.find_artifact(adesc)) db.add_artifact(e) r = db.find_artifact(adesc) print('R: %s' % (str(r))) self.assertEqual(e, r) db.remove_artifact(adesc) self.assertEqual(None, db.find_artifact(adesc))