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)
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)