def remove_entries_by_id(entries, ids): num_entries = len(ids) for econtext in entries: e = Entry(econtext) idelement = e.etree().find("{%s}id" % atompubbase.model.ATOM) if None != idelement and idelement.text in ids: info("Remove entry") h, b = e.delete() check_remove_response(h, b) num_entries -= 1 if num_entries == 0: break if num_entries == 0: success("Removed all entries that we're previously added.")
def testBasic_Media_Manipulation(self): """Add and remove an image in the collection""" info("Service Document: %s" % self.collection.context().collection) info("Count the entries in the collection") num_entries = len(list(self.collection.iter())) body = get_test_data_raw("success.gif") info("Create new media entry") slug = "".join([random.choice("abcdefghijkl") for x in range(10)]) h, b = self.collection.create(headers = { 'content-type': 'image/gif', 'slug': slug }, body = body) check_create_response(h, b) info("Count the entries in the collection after adding three.") entries = list(self.collection.iter()) num_entries_after = len(entries) if num_entries_after != num_entries + 1: warning(msg.CREATE_APPEAR_COLLECTION, "New media entry did not appear in the collection.") return else: success("Added Media Entry") entry = Entry(entries[0]) e = entry.etree() if e == None: raise StopTest # Check the slug check_entry_slug(e, slug) check_entry_links(e, ismedia=True) e.find(atompubbase.model.ATOM_TITLE).text = "Success" info("Update Media Link Entry and write back to the collection") h, b = entry.put(headers={'content-type': 'application/atom+xml'}, body = tostring(e)) check_update_response(h, b, "Media Link Entry") # Remove Entry info("Remove entry") h, b = entry.delete() check_remove_response(h, b) success("Removed Media Entry")