def test_load_all_specs(self): pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_specs() self.assertEqual(len(pool.get_items((1,))), 2) self.assertTrue(not pool.get_item(self.Car.get_id()) is None) self.assertTrue(not pool.get_item(self.Vehicle.get_id()) is None)
def test_load_related(self): pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_artifact(self.lightningMcQueen.get_id()) lightningMcQueen = pool.get_item(self.lightningMcQueen.get_id()) self.assertTrue(not pool.get_item(self.Car.get_id()) is None) self.assertTrue(not pool.get_item(self.Vehicle.get_id()) is None)
def test_delete_unmodified(self): pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_artifact(self.lightningMcQueen.get_id()) lightningMcQueen = pool.get_item(self.lightningMcQueen.get_id()) dbp.delete(lightningMcQueen, 'me', 'deleted stuff', '127.0.0.1') self.assertTrue(pool.get_item(lightningMcQueen.get_id()) is None) pool2 = InstancePool() dbp2 = DBPool(self.env, pool2) self.assertRaises(ValueError, dbp2.load_artifact, self.lightningMcQueen.get_id()) self.assertTrue(pool2.get_item(self.lightningMcQueen.get_id()) is None)
def test_delete_changed(self): pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_artifact(self.lightningMcQueen.get_id()) lightningMcQueen = pool.get_item(self.lightningMcQueen.get_id()) self.lightningMcQueen.set_value('Wheels', ['front middle wheel', 'rear left wheel', 'front right wheel']) dbp.delete(lightningMcQueen, 'me', 'deleted stuff', '127.0.0.1') self.assertTrue(pool.get_item(lightningMcQueen.get_id()) is None) self.assertEqual(2, len(dbp.pool.get_items((0,1)))) pool2 = InstancePool() dbp2 = DBPool(self.env, pool2) self.assertRaises(ValueError, dbp2.load_artifact, self.lightningMcQueen.get_id()) self.assertTrue(pool2.get_item(self.lightningMcQueen.get_id()) is None)
def test_load_one(self): pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_artifact(self.lightningMcQueen.get_id()) lightningMcQueen = pool.get_item(self.lightningMcQueen.get_id()) self.assertEqual(lightningMcQueen.get_id(), self.lightningMcQueen.get_id()) self.assertEqual(len(lightningMcQueen.get_value("Wheels")), 4)
def test_retrieve_history(self): # make change pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_artifact(self.lightningMcQueen.get_id()) lm = pool.get_item(self.lightningMcQueen.get_id()) lm.set_value('License', 'GO-42-42') dbp.save('me', 'added license information', '127.0.0.1') # reload and inspect pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_artifact(self.lightningMcQueen.get_id()) lm = pool.get_item(self.lightningMcQueen.get_id()) h = [(version, timestamp, author, ipnr, comment) for version, timestamp, author, ipnr, comment in dbp.get_history(lm)] self.assertEqual(len(h), 2)
def test_load_artifacts_of_spec(self): # add a couple more instances pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_specs() car1 = self.Car(values={"License": "GO-42-42"}) plane2 = self.Vehicle(values={"License": "GO-55-55"}) pool.add(car1) pool.add(plane2) dbp.save('me', 'a couple more instances', '127.0.0.1') # load cars only pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_artifacts_of(self.Car.get_name()) self.assertEqual(len(pool.get_items((0,))), 2) self.assertTrue(not pool.get_item(self.lightningMcQueen.get_id()) is None) self.assertTrue(not pool.get_item(car1.get_id()) is None)
def _get_link(self, href, artifact_id, label=None, art_attr=None): try: pool = InstancePool() dbp = DBPool(self.env, pool) dbp.load_artifact(id=artifact_id) artifact = pool.get_item(id=artifact_id) spec_name = artifact.__class__.get_name() if not artifact.__class__ is Instance else None if not art_attr is None: label = artifact.get_value(art_attr) if label is None: return inline_system_message(u"Error: The attribute '{0}' was not found.".format(art_attr)) if label is None: label = str(artifact) if spec_name is None: title = "Custom Software Artifact '%s'" % (label,) else: title = "Custom Software Artifact '%s' of type '%s'" % (label, spec_name) except ValueError: title = "Custom Software Artifact with ID '%s' does not exist" % (artifact_id,) return tag.a(label, href=href.customartifacts('artifact', artifact_id), class_="asa-link", title=title)