コード例 #1
0
ファイル: test_client.py プロジェクト: daviddeng/azrael
    def test_setFragments_dae(self, client_type):
        """
        Spawn a new object and modify its geometry at runtime.
        """
        # Get the client for this test.
        client = self.clients[client_type]

        # Get a Collada fragment.
        f_dae = {'f_dae': getFragDae()}

        # Add a new template and spawn it.
        temp = getTemplate('t1', fragments=f_dae)
        assert client.addTemplates([temp]).ok

        new_obj = {'templateID': temp.aid,
                   'rbs': {'position': (1, 1, 1), 'velocityLin': (-1, -1, -1)}}
        ret = client.spawn([new_obj])
        objID = ret.data[0]
        assert ret.ok and ret.data == [objID]
        del temp, new_obj, ret

        # Query the body states to obtain the 'version' value.
        ret = client.getRigidBodies(objID)
        assert ret.ok
        version = ret.data[objID]['rbs'].version

        # Fetch-, modify-, update- and verify the geometry.
        ret = client.getFragments([objID])
        assert ret.ok
        assert ret.data[objID]['f_dae']['fragtype'] == 'DAE'

        # Change the geometry for fragment 'f_dae' to a RAW type.
        assert client.setFragments({objID: {'f_dae': getFragRaw()._asdict()}}).ok

        # Ensure the fragment is now indeed of type 'RAW'.
        ret = client.getFragments([objID])
        assert ret.ok
        assert ret.data[objID]['f_dae']['fragtype'] == 'RAW'

        # Ensure 'version' is different as well.
        ret = client.getRigidBodies(objID)
        assert ret.ok and (ret.data[objID]['rbs'].version != version)

        # Change the fragment geometry once more.
        version = ret.data[objID]['rbs'].version
        assert client.setFragments({objID: {'f_dae': getFragDae()._asdict()}}).ok

        # Ensure it now has type 'DAE' again.
        ret = client.getFragments([objID])
        assert ret.ok
        assert ret.data[objID]['f_dae']['fragtype'] == 'DAE'

        # Ensure 'version' is different as well.
        ret = client.getRigidBodies(objID)
        assert ret.ok and (ret.data[objID]['rbs'].version != version)
コード例 #2
0
ファイル: test_dibbler.py プロジェクト: daviddeng/azrael
    def test_updateFragments_partial(self):
        """
        Simliar to previous test in the sense that it spawns and updates
        fragments. However, this time some fragments will be removed
        altogether, instead of just being updated.
        """
        dibbler = self.dibbler

        # The original template has the following three fragments:
        frags_orig = {
            'f1': getFragRaw(),
            'f2': getFragDae(),
            'f3': getFragRaw()
        }
        t1 = getTemplate('t1', fragments=frags_orig)

        # The fragment update will use the following data. It translates to
        # keeping the first intact, removing the second, and modifying the
        # fragment type for the third one.
        frags_new = {
            'f2': getFragNone(),
            'f3': getFragDae(),
        }

        # Add the template, spawn one instance, and verify all fragments.
        assert dibbler.addTemplate(t1).ok
        ret = dibbler.spawnTemplate(1, t1.aid)
        assert ret.ok
        self.verifyRaw(ret.data['url_frag'], 'f1', frags_orig)
        self.verifyDae(ret.data['url_frag'], 'f2', frags_orig)
        self.verifyRaw(ret.data['url_frag'], 'f3', frags_orig)

        # Record the current number of files in Dibbler. There must be one
        # 'meta.json', two raw files (one each), 3 Collada files (dae + 2
        # textures). These files exist twice, once in the template store and
        # once in the instance store.
        file_cnt = dibbler.getNumFiles().data
        assert file_cnt == 2 * (1 + 2 * 1 + 1 * 3)

        # Update the fragments: keep first (raw, +0), delete second (dae, -3),
        # convert third from raw to dae (-1 + 3).
        assert dibbler.updateFragments(1, frags_new).ok

        # Record the current number of files in Dibbler.
        assert dibbler.getNumFiles().data == file_cnt + (0) + (-3) + (-1 + 3)

        # Verify that the first fragment is still intact, the second does not
        # exist anymore, and the third was updated.
        self.verifyRaw(ret.data['url_frag'], 'f1', frags_orig)
        with pytest.raises(AssertionError):
            self.verifyDae(ret.data['url_frag'], 'f2', frags_orig)
        self.verifyDae(ret.data['url_frag'], 'f3', frags_new)
コード例 #3
0
ファイル: test_dibbler.py プロジェクト: daviddeng/azrael
    def test_updateFragments_all(self):
        """
        Spawn a template and update all its fragments.
        """
        dibbler = self.dibbler

        # The original template has two fragments, and we will update one of
        # them.
        frags_orig = {'o1': getFragRaw(),
                      'o2': getFragDae()}
        frags_new = {'o1': getFragDae()}
        t1 = getTemplate('t1', fragments=frags_orig)

        # Add the template and spawn two instances.
        assert dibbler.addTemplate(t1).ok
        ret_11 = dibbler.spawnTemplate(11, t1.aid)
        ret_2 = dibbler.spawnTemplate(2, t1.aid)
        assert ret_11.ok and ret_2.ok

        self.verifyRaw(ret_11.data['url_frag'], 'o1', frags_orig)
        self.verifyDae(ret_11.data['url_frag'], 'o2', frags_orig)
        self.verifyRaw(ret_2.data['url_frag'], 'o1', frags_orig)
        self.verifyDae(ret_2.data['url_frag'], 'o2', frags_orig)

        # Attempt to change the fragment of a non-existing object.
        assert not dibbler.updateFragments(20, frags_new).ok

        # Attempt to change the fragment of another non-existing object, but
        # the object ID of this one is '1', which means it is available at
        # '/somewhere/1/...'. However, an object at '/somewhere/11/...' already
        # exists, and without the trailing '/' the first would be a sub-string
        # of the latter. The update method must therefore take care to properly
        # test for existence, especially since directories, internally, do not
        # have a trailing '/'.
        assert not dibbler.updateFragments(1, frags_new).ok

        # The previous attempts to modify fragments of non-existing objectst
        # must not have modified the fragments.
        self.verifyRaw(ret_11.data['url_frag'], 'o1', frags_orig)
        self.verifyDae(ret_11.data['url_frag'], 'o2', frags_orig)
        self.verifyRaw(ret_2.data['url_frag'], 'o1', frags_orig)
        self.verifyDae(ret_2.data['url_frag'], 'o2', frags_orig)

        # Change the first fragments of the first object.
        assert dibbler.updateFragments(11, frags_new).ok

        # Verify that only the first fragment of the '11' object has changed.
        self.verifyDae(ret_11.data['url_frag'], 'o1', frags_new)
        self.verifyDae(ret_11.data['url_frag'], 'o2', frags_orig)
        self.verifyRaw(ret_2.data['url_frag'], 'o1', frags_orig)
        self.verifyDae(ret_2.data['url_frag'], 'o2', frags_orig)
コード例 #4
0
ファイル: test_types.py プロジェクト: daviddeng/azrael
    def test_Template(self):
        # Define boosters and factories.
        boosters = {
            "0": Booster(pos=(0, 1, 2), direction=(1, 0, 0), minval=0, maxval=1, force=0),
            "1": Booster(pos=(3, 4, 5), direction=(0, 1, 0), minval=0, maxval=2, force=0),
        }
        factories = {
            "0": Factory(pos=(0, 1, 2), direction=(0, 0, 1), templateID="_templateBox", exit_speed=(0, 1)),
            "1": Factory(pos=(3, 4, 5), direction=(0, 1, 0), templateID="_templateBox", exit_speed=(0, 1)),
        }

        rbs = getRigidBody(position=(1, 2, 3))

        # Define a new template with two boosters and add it to Azrael.
        temp_t = getTemplate(
            "t1", rbs=rbs, fragments={"1": getFragRaw(), "2": getFragDae()}, boosters=boosters, factories=factories
        )

        # Verify that it is JSON compatible.
        assert self.isJsonCompatible(temp_t, Template)

        # Verify that Template._asdict() method calls the _asdict() methods
        # for all collision shapes, fragments, boosters, and factories.
        temp_d = temp_t._asdict()
        fragments_d = {k: v._asdict() for (k, v) in temp_t.fragments.items()}
        boosters_d = {k: v._asdict() for (k, v) in temp_t.boosters.items()}
        factories_d = {k: v._asdict() for (k, v) in temp_t.factories.items()}
        rbs_d = rbs._asdict()
        assert temp_d["fragments"] == fragments_d
        assert temp_d["boosters"] == boosters_d
        assert temp_d["factories"] == factories_d
        assert temp_d["rbs"] == rbs_d
コード例 #5
0
ファイル: test_aztypes.py プロジェクト: olitheolix/azrael
    def test_Template(self):
        # Define boosters and factories.
        boosters = {
            '0': Booster(position=(0, 1, 2), direction=(1, 0, 0), force=0),
            '1': Booster(position=(3, 4, 5), direction=(0, 1, 0), force=0)
        }
        factories = {
            '0': Factory(position=(0, 1, 2), direction=(0, 0, 1),
                         templateID='_templateBox', exit_speed=(0, 1)),
            '1': Factory(position=(3, 4, 5), direction=(0, 1, 0),
                         templateID='_templateBox', exit_speed=(0, 1))
        }

        rbs = getRigidBody(position=(1, 2, 3))

        # Define a new template with two boosters and add it to Azrael.
        frags = {'1': getFragRaw(), '2': getFragDae()}
        temp_t = getTemplate('t1',
                             rbs=rbs,
                             fragments=frags,
                             boosters=boosters,
                             factories=factories)

        # Verify that Template._asdict() method calls the _asdict() methods
        # for all collision shapes, fragments, boosters, and factories.
        temp_d = temp_t._asdict()
        fragments_d = {k: v._asdict() for (k, v) in temp_t.fragments.items()}
        boosters_d = {k: v._asdict() for (k, v) in temp_t.boosters.items()}
        factories_d = {k: v._asdict() for (k, v)in temp_t.factories.items()}
        rbs_d = rbs._asdict()
        assert temp_d['fragments'] == fragments_d
        assert temp_d['boosters'] == boosters_d
        assert temp_d['factories'] == factories_d
        assert temp_d['rbs'] == rbs_d
コード例 #6
0
ファイル: test_client.py プロジェクト: daviddeng/azrael
    def test_collada_model(self, client_type):
        """
        Add a template based on a Collada model, spawn it, and query its
        geometry.
        """
        # Get the client for this test.
        client = self.clients[client_type]

        # Add a valid template with Collada data and verify the upload worked.
        temp = getTemplate('foo', fragments={'f_dae': getFragDae()})
        assert client.addTemplates([temp]).ok

        # Spawn the template.
        ret = client.spawn([{'templateID': temp.aid}])
        assert ret.ok
        objID = ret.data[0]

        # Query and the geometry.
        ret = client.getFragments([objID])
        assert ret.ok

        # Verify it has the correct type ('DAE') and address.
        ret = ret.data[objID]
        assert ret['f_dae']['fragtype'] == 'DAE'
        assert ret['f_dae']['url_frag'] == (
            config.url_instances + '/' + str(objID) + '/f_dae')
コード例 #7
0
    def getTestTemplate(self, templateID='templateID'):
        """
        Return a valid template with non-trivial data. The template contains
        multiple fragments (Raw and Collada), boosters, factories, and a rigid
        body.

        This is a convenience method only.
        """
        # Define a new object with two boosters and one factory unit.
        # The 'boosters' and 'factories' arguments are a list of named
        # tuples. Their first argument is the unit ID (Azrael does not
        # automatically assign any IDs).
        boosters = {
            '0': aztypes.Booster(position=(0, 1, 2), direction=(0, 0, 1), force=0),
            '1': aztypes.Booster(position=(6, 7, 8), direction=(0, 1, 0), force=0),
        }
        factories = {
            '0': aztypes.Factory(position=(0, 0, 0), direction=(0, 0, 1),
                                 templateID='_templateBox',
                                 exit_speed=(0.1, 0.5))
        }

        # Create some fragments...
        frags = {'f1': getFragRaw(), 'f2': getFragDae()}

        # ... and a body...
        body = getRigidBody(position=(1, 2, 3))

        # ... then compile and return the template.
        return azrael.test.test.getTemplate(
            templateID,
            rbs=body,
            fragments=frags,
            boosters=boosters,
            factories=factories)
コード例 #8
0
ファイル: test_client.py プロジェクト: daviddeng/azrael
    def test_remove_fragments(self, client_type):
        """
        Remove a fragment. This test is basically the integration test for
        'test_dibbler.test_updateFragments_partial'.
        """
        # Get the client for this test.
        client = self.clients[client_type]

        # Convenience.
        objID = 1

        # The original template has the following three fragments:
        frags_orig = {
            'fname_1': getFragRaw(),
            'fname_2': getFragDae(),
            'fname_3': getFragRaw(),
        }
        t1 = getTemplate('t1', fragments=frags_orig)

        # Add a new template and spawn it.
        assert client.addTemplates([t1]).ok
        new_obj = {'templateID': t1.aid,
                   'rbs': {'position': (1, 1, 1), 'velocityLin': (-1, -1, -1)}}
        assert client.spawn([new_obj]) == (True, None, [objID])

        # Query the fragment geometries and Body State to verify that both
        # report three fragments.
        ret = client.getFragments([objID])
        assert ret.ok and len(ret.data[objID]) == 3
        ret = client.getObjectStates(objID)
        assert ret.ok and len(ret.data[objID]['frag']) == 3

        # Update the fragments as follows: keep the first intact, remove the
        # second, and modify the third one.
        frags_new = {
            'fname_2': getFragNone()._asdict(),
            'fname_3': getFragDae()._asdict()
        }
        assert client.setFragments({objID: frags_new}).ok

        # After the last update there must now only be two fragments.
        ret = client.getFragments([objID])
        assert ret.ok and len(ret.data[objID]) == 2
        ret = client.getObjectStates(objID)
        assert ret.ok and len(ret.data[objID]['frag']) == 2
コード例 #9
0
ファイル: test_web.py プロジェクト: QuantumUniverse777/azrael
    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)
コード例 #10
0
ファイル: test_web.py プロジェクト: daviddeng/azrael
    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)
コード例 #11
0
ファイル: test_web.py プロジェクト: QuantumUniverse777/azrael
    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)
コード例 #12
0
ファイル: test_dibbler.py プロジェクト: daviddeng/azrael
    def test_addDaeTemplate(self):
        """
        Add a Collada template and fetch the individual files again afterwards.
        """
        dibbler = self.dibbler

        # Define a template for this test.
        frag = {'foo': getFragDae()}
        t_dae = getTemplate('_templateEmpty', fragments=frag)

        # Create a Dibbler instance and flush all data.
        assert dibbler.getNumFiles() == (True, None, 0)

        # Add the first template and verify that the database now contains
        # extactly fourc files (a meta file, the DAE file, and two textures).
        ret = dibbler.addTemplate(t_dae)
        assert dibbler.getNumFiles() == (True, None, 4)

        # Fetch- and verify the model.
        self.verifyDae(ret.data['url_frag'], 'foo', frag)
コード例 #13
0
ファイル: test_dibbler.py プロジェクト: daviddeng/azrael
    def test_spawnTemplate(self):
        """
        Add two templates, then spawn the first one twice and the second
        one once.
        """
        dibbler = self.dibbler

        # Define two templates.
        frag_raw = {'fraw': getFragRaw()}
        frag_dae = {'fdae': getFragDae()}
        t_raw = getTemplate('t_name_raw', fragments=frag_raw)
        t_dae = getTemplate('t_name_dae', fragments=frag_dae)

        # Add the templates and verify there are 6 files in the DB now. The
        # first template has two files (1 meta.json plus 1 for the raw data)
        # and the second has 4 files (1 meta.json plus 3 for the Collada data).
        dibbler.addTemplate(t_raw)
        dibbler.addTemplate(t_dae)
        assert dibbler.getNumFiles() == (True, None, 2 + 4)

        # Spawn some instances.
        ret_1 = dibbler.spawnTemplate(1, t_raw.aid)
        ret_2 = dibbler.spawnTemplate(2, t_raw.aid)
        ret_3 = dibbler.spawnTemplate(3, t_dae.aid)
        assert ret_1.ok and ret_2.ok and ret_3.ok

        # Dibbler must now hold the original 6 files plus an additional 8 files
        # (2x2 for the two Raw instances, and another 4 for the one Collada
        # instance).
        assert dibbler.getNumFiles() == (True, None, (2 + 4) + (2 * 2 + 1 * 4))

        # Verify that all files are correct.
        self.verifyRaw(ret_1.data['url_frag'], 'fraw', frag_raw)
        self.verifyRaw(ret_2.data['url_frag'], 'fraw', frag_raw)
        self.verifyDae(ret_3.data['url_frag'], 'fdae', frag_dae)

        # Attempt to spawn a non-existing template. This must fail and the
        # number of files in Dibbler must not change.
        assert not dibbler.spawnTemplate(10, 'blah').ok
        assert dibbler.getNumFiles() == (True, None, (2 + 4) + (2 * 2 + 1 * 4))
コード例 #14
0
    def test_Template(self):
        # Define boosters and factories.
        boosters = {
            '0': Booster(position=(0, 1, 2), direction=(1, 0, 0), force=0),
            '1': Booster(position=(3, 4, 5), direction=(0, 1, 0), force=0)
        }
        factories = {
            '0':
            Factory(position=(0, 1, 2),
                    direction=(0, 0, 1),
                    templateID='_templateBox',
                    exit_speed=(0, 1)),
            '1':
            Factory(position=(3, 4, 5),
                    direction=(0, 1, 0),
                    templateID='_templateBox',
                    exit_speed=(0, 1))
        }

        rbs = getRigidBody(position=(1, 2, 3))

        # Define a new template with two boosters and add it to Azrael.
        frags = {'1': getFragRaw(), '2': getFragDae()}
        temp_t = getTemplate('t1',
                             rbs=rbs,
                             fragments=frags,
                             boosters=boosters,
                             factories=factories)

        # Verify that Template._asdict() method calls the _asdict() methods
        # for all collision shapes, fragments, boosters, and factories.
        temp_d = temp_t._asdict()
        fragments_d = {k: v._asdict() for (k, v) in temp_t.fragments.items()}
        boosters_d = {k: v._asdict() for (k, v) in temp_t.boosters.items()}
        factories_d = {k: v._asdict() for (k, v) in temp_t.factories.items()}
        rbs_d = rbs._asdict()
        assert temp_d['fragments'] == fragments_d
        assert temp_d['boosters'] == boosters_d
        assert temp_d['factories'] == factories_d
        assert temp_d['rbs'] == rbs_d
コード例 #15
0
ファイル: test_dibbler.py プロジェクト: daviddeng/azrael
    def test_deleteInstance(self):
        """
        Add and remove an instance.
        """
        dibbler = self.dibbler

        # Define two templates.
        frag_raw = {'foo': getFragRaw()}
        frag_dae = {'bar': getFragDae()}
        t_raw = getTemplate('temp_raw', fragments=frag_raw)
        t_dae = getTemplate('temp_dae', fragments=frag_dae)

        # Verify that Dibbler is empty.
        assert dibbler.getNumFiles() == (True, None, 0)

        # Add- and verify a Raw- and Collada template. The raw template 2 files
        # (meta.json plus model.json) whereas the Collada template has 4 files
        # (meta.json plus 1 dae file plus 2 textures).
        ret = dibbler.addTemplate(t_raw)
        assert dibbler.getNumFiles() == (True, None, 2)
        self.verifyRaw(ret.data['url_frag'], 'foo', frag_raw)
        ret = dibbler.addTemplate(t_dae)
        assert dibbler.getNumFiles() == (True, None, 2 + 4)
        self.verifyDae(ret.data['url_frag'], 'bar', frag_dae)

        # Spawn some instances.
        assert dibbler.spawnTemplate(1, 'temp_raw').ok
        assert dibbler.spawnTemplate(2, 'temp_dae').ok
        assert dibbler.spawnTemplate(3, 'temp_raw').ok
        self.verifyRaw('{}/1'.format(config.url_instances), 'foo', frag_raw)
        self.verifyDae('{}/2'.format(config.url_instances), 'bar', frag_dae)
        self.verifyRaw('{}/3'.format(config.url_instances), 'foo', frag_raw)
        base_cnt = (2 + 4) + 2 * 2 + 1 * 4
        assert dibbler.getNumFiles() == (True, None, base_cnt)

        # Remove a non-existing object. This must succeed but Dibbler must not
        # have removed any files.
        assert dibbler.deleteInstance(10) == (True, None, 0)
        assert dibbler.getNumFiles() == (True, None, base_cnt)

        # Remove the first Raw object. This must remove two files and leave the
        # other two instances intact.
        assert dibbler.deleteInstance(1) == (True, None, 2)
        base_cnt -= 2
        assert dibbler.getNumFiles() == (True, None, base_cnt)
        with pytest.raises(AssertionError):
            self.verifyRaw('{}/1'.format(config.url_instances), 'foo', frag_raw)
        self.verifyDae('{}/2'.format(config.url_instances), 'bar', frag_dae)
        self.verifyRaw('{}/3'.format(config.url_instances), 'foo', frag_raw)

        # Remove the same instance again. This must succeed but Dibbler must
        # not remove any files.
        assert dibbler.deleteInstance(1) == (True, None, 0)

        # Remove the Collada instance. This must delete four files (meta.json +
        # dae + 2 textures).
        assert dibbler.deleteInstance(2) == (True, None, 4)
        base_cnt -= 4
        assert dibbler.getNumFiles() == (True, None, base_cnt)
        with pytest.raises(AssertionError):
            self.verifyRaw('{}/1'.format(config.url_instances), 'foo', frag_raw)
        with pytest.raises(AssertionError):
            self.verifyDae('{}/2'.format(config.url_instances), 'bar', frag_dae)
        self.verifyRaw('{}/3'.format(config.url_instances), 'foo', frag_raw)

        # Remove the second Raw instance.
        assert dibbler.deleteInstance(3) == (True, None, 2)
        base_cnt -= 2
        assert dibbler.getNumFiles() == (True, None, base_cnt)
        with pytest.raises(AssertionError):
            self.verifyRaw('{}/1'.format(config.url_instances), 'foo', frag_raw)
        with pytest.raises(AssertionError):
            self.verifyDae('{}/2'.format(config.url_instances), 'bar', frag_dae)
        with pytest.raises(AssertionError):
            self.verifyRaw('{}/3'.format(config.url_instances), 'foo', frag_raw)
コード例 #16
0
ファイル: test_dibbler.py プロジェクト: daviddeng/azrael
    def test_deleteTemplate(self):
        """
        Add two templates and then delete them. This functions also tests some
        corner cases where the delete-request is a substring of another
        template.
        """
        dibbler = self.dibbler

        # Define two templates.
        frag_raw = {'foo': getFragRaw()}
        frag_dae = {'bar': getFragDae()}
        t1 = getTemplate('name1', fragments=frag_dae)
        t11 = getTemplate('name11', fragments=frag_raw)

        # Verify that Dibbler's database is pristine.
        assert dibbler.getNumFiles() == (True, None, 0)

        # Add- and verify the Raw template.
        ret = dibbler.addTemplate(t11)
        assert dibbler.getNumFiles() == (True, None, 2)
        self.verifyRaw(ret.data['url_frag'], 'foo', frag_raw)

        # Remove the Raw template and ensure it does not exist anymore.
        assert dibbler.deleteTemplate('name11').ok
        assert dibbler.getNumFiles() == (True, None, 0)
        with pytest.raises(AssertionError):
            self.verifyRaw(ret.data['url_frag'], 'foo', frag_raw)

        # Attempt to remove the Raw template once more. Dibbler must not delete
        # any files, albeit the call itself must succeed.
        assert dibbler.deleteTemplate('blah').ok
        assert dibbler.getNumFiles() == (True, None, 0)

        # Add- and verify the Raw- and Collada templates.
        del ret
        ret_raw = dibbler.addTemplate(t11)
        ret_dae = dibbler.addTemplate(t1)
        assert dibbler.getNumFiles() == (True, None, 6)
        self.verifyRaw(ret_raw.data['url_frag'], 'foo', frag_raw)
        self.verifyDae(ret_dae.data['url_frag'], 'bar', frag_dae)

        # Remove the Collada template whose name is a substring of the first.
        assert dibbler.deleteTemplate('name1') == (True, None, 4)
        assert dibbler.getNumFiles() == (True, None, 2)
        self.verifyRaw(ret_raw.data['url_frag'], 'foo', frag_raw)
        with pytest.raises(AssertionError):
            self.verifyRaw(ret_dae.data['url_frag'], 'bar', frag_dae)

        # Remove the Collada template again. No files must be deleted this
        # time.
        assert dibbler.deleteTemplate('name1') == (True, None, 0)
        assert dibbler.getNumFiles() == (True, None, 2)

        # Attempt to remove a non-existing template. The call must succeed but
        # Dibbler must not delete any files.
        assert dibbler.deleteTemplate('blah') == (True, None, 0)
        assert dibbler.getNumFiles() == (True, None, 2)

        # Delete the one remaining template (Raw template) and verify that
        # Dibbler does not hold any files anymore whatsoever afterwards.
        assert dibbler.deleteTemplate('name11') == (True, None, 2)
        assert dibbler.getNumFiles() == (True, None, 0)
        with pytest.raises(AssertionError):
            self.verifyRaw(ret_raw.data['url_frag'], 'foo', frag_raw)
        with pytest.raises(AssertionError):
            self.verifyRaw(ret_dae.data['url_frag'], 'bar', frag_dae)