def test_modity_empty(self): request = ModifyRequest() transaction = ModifyTransaction() # Make sure that prepare and commit do not throw an exception. transaction.prepare(request) transaction.commit(self._trie, self._get_blessed_version(), self._store)
def test_modify_no_name_change(self): """Do not allow changing token names.""" request = ModifyRequest(updates=[]) # pickle gets maximum recursion depth exceeded when traversing # the trie, probably a bug in pickle. Setting the recursion limit # to a high number fixes it. sys.setrecursionlimit(10000) trie_before = pickle.dumps(self._trie) token = copy.copy(self._trie['/some_dir/some_token_0']) token.name = '/some_other_dir/some_token_0' request.updates.append(token) transaction = ModifyTransaction() transaction.prepare(request) self.assertRaises(TokenMasterException, transaction.commit, self._trie, self._get_blessed_version(), self._store) trie_after = pickle.dumps(self._trie) self.assertEqual(trie_before, trie_after)
def test_modify_deletes(self): request = ModifyRequest(deletes=[]) n_tokens_before = len(self._trie) some_token = copy.copy(self._trie['/some_dir/some_token_0']) request.deletes.append(some_token) some_other_token = copy.copy( self._trie['/some_dir/some_token_0/some_other_token_0']) request.deletes.append(some_other_token) transaction = ModifyTransaction() transaction.prepare(request) transaction.commit(self._trie, self._get_blessed_version(), self._store) n_tokens_after = len(self._trie) # We deleted two things from self._trie. self.assertEqual(n_tokens_before - 2, n_tokens_after) self._check_version_uniqueness()
def test_modify_deletes_and_updates(self): """Updates and deletes in a single request.""" request = ModifyRequest(updates=[], deletes=[]) n_tokens_before = len(self._trie) delete_token = copy.copy(self._trie['/some_dir/some_token_0']) request.deletes.append(delete_token) update_token = copy.copy(self._trie['/some_dir/some_token_1']) update_token.data = 'some other data' request.updates.append(update_token) transaction = ModifyTransaction() transaction.prepare(request) response = transaction.commit(self._trie, self._get_blessed_version(), self._store) self.assertEqual(1, len(response.updates)) n_tokens_after = len(self._trie) self.assertEqual(n_tokens_before - 1, n_tokens_after) self._check_version_uniqueness()
def test_modify_updates(self): request = ModifyRequest(updates=[]) n_tokens_before = len(self._trie) token = copy.copy(self._trie['/some_dir/some_token_0']) token.data = 'some other data' request.updates.append(token) new_token = Token(name='/some_other_dir/some_token', data='some data') request.updates.append(new_token) transaction = ModifyTransaction() transaction.prepare(request) response = transaction.commit(self._trie, self._get_blessed_version(), self._store) self.assertEqual(2, len(response.updates)) self.assertNotEqual(token.version, response.updates[0].version) self.assertEqual(token.name, response.updates[0].name) self.assertEqual(token.data, response.updates[0].data) self.assertLess(0, response.updates[1].version) self.assertEqual(new_token.name, response.updates[1].name) self.assertEqual(new_token.data, response.updates[1].data) n_tokens_after = len(self._trie) self.assertEqual(n_tokens_before + 1, n_tokens_after) self._check_version_uniqueness()