def test_deleteInstance(self): """ Add/remove an instance from Dibbler via Clerk and verify via WebServer. """ self.dibbler.reset() azrael.datastore.init(flush=True) clerk = azrael.clerk.Clerk() # Create a Template. frags = {'name1': getFragRaw()} t1 = getTemplate('t1', fragments=frags) # Add-, spawn-, and verify the template. assert clerk.addTemplates([t1]).ok self.verifyTemplate('{}/t1'.format(config.url_templates), t1.fragments) ret = clerk.spawn([{'templateID': 't1', 'rbs': {'imass': 1}}]) assert ret.data == ['1'] # Verify that the instance exists. url_inst = config.url_instances self.verifyTemplate('{}/{}'.format(url_inst, 1), frags) # Delete the instance and verify it is now gone. cnt = self.dibbler.getNumFiles().data assert clerk.removeObjects(['1']) == (True, None, None) self.dibbler.getNumFiles().data == cnt - 2 with pytest.raises(AssertionError): self.verifyTemplate('{}/{}'.format(url_inst, 1), frags)
def test_addTemplates(self): """ Add and query a template with one Raw fragment. """ self.dibbler.reset() azrael.datastore.init(flush=True) clerk = azrael.clerk.Clerk() # Create two Templates. The first has only one Raw- and two # Collada geometries, the other has it the other way around. frags_t1 = {'foo1': getFragRaw(), 'bar2': getFragDae(), 'bar3': getFragDae()} frags_t2 = {'foo4': getFragRaw(), 'foo5': getFragRaw(), 'bar6': getFragDae()} body_a = getRigidBody(cshapes={'cssphere': getCSSphere()}) body_b = getRigidBody(cshapes={'csbox': getCSBox()}) t1 = getTemplate('t1', rbs=body_a, fragments=frags_t1) t2 = getTemplate('t2', rbs=body_b, fragments=frags_t2) del frags_t1, frags_t2 # Add the first template. assert clerk.addTemplates([t1]) == (True, None, {'t1': True}) # Attempt to add the same template a second time. This must not do # anything. assert clerk.addTemplates([t1]) == (True, None, {'t1': False}) # Verify the first template is available for download via WebServer. url_template = config.url_templates self.verifyTemplate('{}/t1'.format(url_template), t1.fragments) # Add the second template and verify both are available for download # via WebServer. assert clerk.addTemplates([t2]).ok self.verifyTemplate('{}/t1'.format(url_template), t1.fragments) self.verifyTemplate('{}/t2'.format(url_template), t2.fragments)
def test_spawnTemplates(self): """ Spawn a template and verify it is available via WebServer. """ self.dibbler.reset() azrael.datastore.init(flush=True) clerk = azrael.clerk.Clerk() # # Create two Templates. The first has only one Raw- and two # # Collada geometries, the other has it the other way around. frags_t1 = {'raw1': getFragRaw(), 'dae2': getFragDae(), 'dae3': getFragDae()} frags_t2 = {'raw4': getFragRaw(), 'raw5': getFragRaw(), 'dae6': getFragDae()} body_t1 = getRigidBody(cshapes={'cssphere': getCSSphere()}) body_t2 = getRigidBody(cshapes={'csbox': getCSBox()}) t1 = getTemplate('t1', rbs=body_t1, fragments=frags_t1) t2 = getTemplate('t2', rbs=body_t2, fragments=frags_t2) del frags_t1, frags_t2 # Add both templates and verify they are available. assert clerk.addTemplates([t1, t2]).ok self.verifyTemplate('{}/t1'.format(config.url_templates), t1.fragments) self.verifyTemplate('{}/t2'.format(config.url_templates), t2.fragments) # No object instance with ID=1 must exist yet. url_inst = config.url_instances with pytest.raises(AssertionError): self.verifyTemplate('{}/{}'.format(url_inst, 1), t1.fragments) # Spawn the first template (it must get objID=1). ret = clerk.spawn([{'templateID': 't1', 'rbs': {'imass': 1}}]) assert ret.data == ['1'] self.verifyTemplate('{}/{}'.format(url_inst, 1), t1.fragments) # Spawn two more templates and very their instance models. new_objs = [{'templateID': 't2', 'rbs': {'imass': 1}}, {'templateID': 't1', 'rbs': {'imass': 1}}] ret = clerk.spawn(new_objs) assert ret.data == ['2', '3'] self.verifyTemplate('{}/{}'.format(url_inst, 2), t2.fragments) self.verifyTemplate('{}/{}'.format(url_inst, 3), t1.fragments)
def setup_method(self, method): # Reset the database. azrael.database.init() # Flush the model database. self.dibbler.reset() # Insert default objects. None of them has an actual geometry but # their collision shapes are: none, sphere, box. clerk = azrael.clerk.Clerk() frag = {'NoName': getFragRaw()} rbs_empty = getRigidBody(cshapes={'csempty': getCSEmpty()}) rbs_sphere = getRigidBody(cshapes={'cssphere': getCSSphere()}) rbs_box = getRigidBody(cshapes={'csbox': getCSBox()}) t1 = getTemplate('_templateEmpty', rbs=rbs_empty, fragments=frag) t2 = getTemplate('_templateSphere', rbs=rbs_sphere, fragments=frag) t3 = getTemplate('_templateBox', rbs=rbs_box, fragments=frag) ret = clerk.addTemplates([t1, t2, t3]) assert ret.ok
def test_updateFragments(self): """ Modify the fragments of a spawned object. """ self.dibbler.reset() azrael.database.init() clerk = azrael.clerk.Clerk() # Create two Templates. The first has only one Raw- and two # Collada geometries, the other has it the other way around. frags_old = {'name1': getFragRaw(), 'name2': getFragDae(), 'name3': getFragDae()} frags_new = {'name1': getFragDae(), 'name2': getFragDae(), 'name3': getFragRaw()} t1 = getTemplate('t1', fragments=frags_old) # Add-, spawn-, and verify the template. assert clerk.addTemplates([t1]).ok self.verifyTemplate('{}/t1'.format(config.url_templates), t1.fragments) ret = clerk.spawn([{'templateID': 't1', 'rbs': {'imass': 1}}]) objID = 1 assert ret.data == (objID, ) # Verify that the instance has the old fragments, not the new ones. url_inst = config.url_instances self.verifyTemplate('{}/{}'.format(url_inst, 1), frags_old) with pytest.raises(AssertionError): self.verifyTemplate('{}/{}'.format(url_inst, 1), frags_new) # Update the fragments. tmp = {k: v._asdict() for (k, v) in frags_new.items()} clerk.setFragments({objID: tmp}) # Verify that the instance now has the new fragments, but not the old # ones anymore. self.verifyTemplate('{}/{}'.format(url_inst, 1), frags_new) with pytest.raises(AssertionError): self.verifyTemplate('{}/{}'.format(url_inst, 1), frags_old)