def test_31_delete_container(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, error_response_raises_exceptions=False) conn.get_service_document() col = conn.sd.workspaces[0][1][0] #e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, #metadata_entry = e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) edit_iri = receipt.location receipt = conn.get_deposit_receipt(edit_iri) # delete the container new_receipt = conn.delete_container(dr=receipt) assert new_receipt.code == 204 assert new_receipt.dom is None # the next check is that this 404s appropriately now another_receipt = conn.get_deposit_receipt(edit_iri)
def test_31_delete_container(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, error_response_raises_exceptions=False, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, metadata_entry=e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) edit_iri = receipt.location receipt = conn.get_deposit_receipt(edit_iri) # delete the container new_receipt = conn.delete_container(dr=receipt) assert new_receipt.code == 204 assert new_receipt.dom is None # the next check is that this 404s appropriately now another_receipt = conn.get_deposit_receipt(edit_iri)
def complete_submission(self, edit_uri): opener = self.get_opener() conn = Connection(self.sword2_sd_url, error_response_raises_exceptions=False, http_impl=UrlLib2Layer(opener)) receipt = None try: receipt = conn.get_deposit_receipt(edit_uri) except urllib2.URLError as e: # The sword2 client does not catch network errors like this one, # which indicates that the url couldn't be reached at all # don't do anything about it here - we'll try again in a moment # and then error out appropriately later pass # at this stage we need to ensure that we actually got back a deposit # receipt i = 0 while (receipt is None or receipt.code >= 400) and i < self.retry_limit: err = None if receipt is None: err = "<unable to reach server>" else: err = str(receipt.code) logger.debug( "Attempt to retrieve Entry Document failed with error " + str(err) + " ... trying again in " + str(self.retry_delay) + " seconds") i += 1 time.sleep(self.retry_delay) try: receipt = conn.get_deposit_receipt(edit_uri) except urllib2.URLError as e: # The sword2 client does not catch network errors like this one, # which indicates that the url couldn't be reached at all # just try again up to the retry_limit continue self.assertIsNotNone(receipt) self.assertEquals(receipt.code, 200) # if we get to here we can go ahead with the deposit for real with open(self.zipFileName, "rb") as data: new_receipt = conn.update( dr=receipt, payload=data, mimetype="application/zip", filename=self.dataset_identifier + ".zip", packaging='http://dataflow.ox.ac.uk/package/DataBankBagIt') self.assertIsNotNone(new_receipt) self.assertEquals(new_receipt.code, 204) return
def complete_submission(self,edit_uri): opener = self.get_opener() conn = Connection(self.sword2_sd_url, error_response_raises_exceptions=False, http_impl=UrlLib2Layer(opener)) receipt = None try: receipt = conn.get_deposit_receipt(edit_uri) except urllib2.URLError as e: # The sword2 client does not catch network errors like this one, # which indicates that the url couldn't be reached at all # don't do anything about it here - we'll try again in a moment # and then error out appropriately later pass # at this stage we need to ensure that we actually got back a deposit # receipt i = 0 while (receipt is None or receipt.code >= 400) and i < self.retry_limit: err = None if receipt is None: err = "<unable to reach server>" else: err = str(receipt.code) logger.debug("Attempt to retrieve Entry Document failed with error " + str(err) + " ... trying again in " + str(self.retry_delay) + " seconds") i += 1 time.sleep(self.retry_delay) try: receipt = conn.get_deposit_receipt(edit_uri) except urllib2.URLError as e: # The sword2 client does not catch network errors like this one, # which indicates that the url couldn't be reached at all # just try again up to the retry_limit continue self.assertIsNotNone(receipt) self.assertEquals(receipt.code,200) # if we get to here we can go ahead with the deposit for real with open( self.zipFileName, "rb") as data: new_receipt = conn.update(dr = receipt, payload=data, mimetype="application/zip", filename=self.dataset_identifier + ".zip", packaging='http://dataflow.ox.ac.uk/package/DataBankBagIt') self.assertIsNotNone(new_receipt) self.assertEquals(new_receipt.code,204) return
def test_01_massive_file(self): http = UrlLib2Layer() conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="scalability testing", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri=col.href, metadata_entry=e) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace with open(PACKAGE) as pkg: new_receipt = conn.update( dr=receipt, payload=pkg, mimetype=PACKAGE_MIME, filename="massive_file.zip", packaging='http://purl.org/net/sword/package/Binary') assert new_receipt.code == 204
def test_13_advanced_retrieve_content_em_iri(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) packaging = 'http://purl.org/net/sword/package/SimpleZip' if receipt.packaging is not None and len(receipt.packaging) > 0: packaging = receipt.packaging[0] resource = conn.get_resource(content_iri=receipt.edit_media, packaging=packaging, on_behalf_of=SSS_OBO) assert resource.code == 200 assert resource.content is not None
def test_19_advanced_replace_metadata(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri=col.href, metadata_entry=e) # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/") new_receipt = conn.update(dr=receipt, metadata_entry=ne, in_progress=True) assert new_receipt.code == 204 or new_receipt.code == 200 if new_receipt.code == 204: assert new_receipt.dom is None if new_receipt.code == 200: assert new_receipt.parsed == True assert new_receipt.valid == True
def test_34_complete_deposit(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title") with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, metadata_entry=e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip', in_progress=True, suggested_identifier="zyxwvutsrq") # ensure that we have a receipt (the server may not give us one # by default) edit_iri = receipt.location receipt = conn.get_deposit_receipt(edit_iri) response = conn.complete_deposit(dr=receipt) assert response.code == 200
def test_26_advanced_add_content_to_resource_package(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') receipt = conn.get_deposit_receipt(receipt.location) with open(PACKAGE) as pkg: new_receipt = conn.add_file_to_resource( receipt.edit_media, pkg, "addition.zip", mimetype=PACKAGE_MIME, packaging="http://purl.org/net/sword/package/SimpleZip", metadata_relevant=True) assert new_receipt.code >= 200 and new_receipt.code < 400 assert new_receipt.location is not None assert new_receipt.location == receipt.edit_media
def test_15_retrieve_content_em_iri_as_feed(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # we're going to work with the edit_media_feed iri assert receipt.edit_media_feed is not None response = conn.get_resource(content_iri=receipt.edit_media_feed) assert response.code == 200 assert response.content is not None # the response should be an xml document, so let's see if we can parse # it. This should give us an exception which will fail the test if not dom = etree.fromstring(response.content)
def test_17_advanced_replace_file_content(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace with open(PACKAGE) as pkg: new_receipt = conn.update( dr=receipt, payload=pkg, mimetype=PACKAGE_MIME, filename="update.zip", packaging='http://purl.org/net/sword/package/SimpleZip', metadata_relevant=True) assert new_receipt.code == 204 assert new_receipt.dom is None
def test_15_retrieve_content_em_iri_as_feed(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # we're going to work with the edit_media_feed iri assert receipt.edit_media_feed is not None response = conn.get_resource(content_iri=receipt.edit_media_feed) assert response.code == 200 assert response.content is not None # the response should be an xml document, so let's see if we can parse # it. This should give us an exception which will fail the test if not dom = etree.fromstring(response.content)
def test_14_error_retrieve_content_em_iri(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, error_response_raises_exceptions=False, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) error = 'http://purl.org/net/sword/package/IJustMadeThisUp' response = conn.get_resource(content_iri=receipt.edit_media, packaging=error) assert response.code == 406 assert isinstance(response, Error_Document) assert response.error_href == "http://purl.org/net/sword/error/ErrorContent"
def test_22_delete_content(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, metadata_entry=e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now delete the content but not the container new_receipt = conn.delete_content_of_resource(dr=receipt) assert new_receipt.code == 204 assert new_receipt.dom is None
def test_11_basic_retrieve_content_cont_iri(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # we're going to work with the cont_iri assert receipt.cont_iri is not None resource = conn.get_resource(content_iri=receipt.cont_iri) assert resource.code == 200 assert resource.content is not None
def test_28_advanced_add_metadata(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, metadata_entry=e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/", dcterms_creator="Me!", dcterms_rights="CC0") new_receipt = conn.append(dr=receipt, metadata_entry=ne, in_progress=True) assert new_receipt.code == 200
def test_30_advanced_add_multipart(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, metadata_entry = e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/", dcterms_creator="Me!", dcterms_rights="CC0") with open(PACKAGE) as pkg: new_receipt = conn.append(dr=receipt, metadata_entry=ne, payload=pkg, filename="addition.zip", mimetype=PACKAGE_MIME, packaging="http://purl.org/net/sword/package/SimpleZip", in_progress=True, metadata_relevant=True) assert new_receipt.code >= 200 and new_receipt.code < 400
def test_17_advanced_replace_file_content(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri=col.href, metadata_entry=e) # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace with open(PACKAGE) as pkg: new_receipt = conn.update( dr=receipt, payload=pkg, mimetype=PACKAGE_MIME, filename="update.zip", packaging='http://purl.org/net/sword/package/SimpleZip', metadata_relevant=True) assert new_receipt.code == 204 assert new_receipt.dom is None
def test_17_advanced_replace_file_content(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace with open(PACKAGE) as pkg: new_receipt = conn.update(dr = receipt, payload=pkg, mimetype=PACKAGE_MIME, filename="update.zip", packaging='http://purl.org/net/sword/package/SimpleZip', metadata_relevant=True) assert new_receipt.code == 204 assert new_receipt.dom is None
def test_21_advanced_replace_with_multipart(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, metadata_entry = e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/") with open(PACKAGE) as pkg: new_receipt = conn.update(dr = receipt, metadata_entry = ne, payload=pkg, mimetype=PACKAGE_MIME, filename="update.zip", packaging='http://purl.org/net/sword/package/SimpleZip', in_progress=True) assert new_receipt.code == 204 or new_receipt.code == 200 if new_receipt.code == 204: assert new_receipt.dom is None if new_receipt.code == 200: assert new_receipt.parsed == True assert new_receipt.valid == True
def test_33_get_ore_statement(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, metadata_entry=e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) edit_iri = receipt.location receipt = conn.get_deposit_receipt(edit_iri) assert receipt.ore_statement_iri is not None # get the statement statement = conn.get_ore_sword_statement(receipt.ore_statement_iri) assert isinstance(statement, Ore_Sword_Statement)
def test_10_advanced_retrieve_deposit_receipt(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip', in_progress=True, suggested_identifier="0987654321") # we're going to work with the location assert receipt.location != None new_receipt = conn.get_deposit_receipt(receipt.location) assert new_receipt.code == 200 assert new_receipt.parsed == True assert new_receipt.valid == True
def test_10_advanced_retrieve_deposit_receipt(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] suggested_id = str(uuid.uuid4()) e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri=col.href, metadata_entry=e, in_progress=True, suggested_identifier=suggested_id) # we're going to work with the location assert receipt.location != None new_receipt = conn.get_deposit_receipt(receipt.location) assert new_receipt.code == 200 assert new_receipt.parsed == True assert new_receipt.valid == True print new_receipt.to_xml() # Here are some more things we can know about the receipt # 1 - the links will all contain the suggested identifier # 2 - the links will all contain the name of the silo # 3 - the packaging will contain DataBankBagIt # 4 - the DC metadata will be reflected back at us # 5 - the atom metadata will be populated in some way for rel, links in new_receipt.links.iteritems(): for link in links: assert suggested_id in link['href'] assert col.title in link['href'] assert "http://dataflow.ox.ac.uk/package/DataBankBagIt" in new_receipt.packaging # check the atom metadata assert new_receipt.title == "An entry only deposit" assert new_receipt.summary == "abstract" # check the DC metadata assert "An entry only deposit" in new_receipt.metadata["dcterms_title"] assert "abstract" in new_receipt.metadata["dcterms_abstract"] assert "http://whatever/" in new_receipt.metadata["dcterms_identifier"]
def test_09_basic_retrieve_deposit_receipt(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri = col.href, metadata_entry = e) # we're going to work with the location assert receipt.location != None new_receipt = conn.get_deposit_receipt(receipt.location) assert new_receipt.code == 200 assert new_receipt.parsed == True assert new_receipt.valid == True
def test_09_basic_retrieve_deposit_receipt(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri = col.href, metadata_entry = e) # we're going to work with the location assert receipt.location != None new_receipt = conn.get_deposit_receipt(receipt.location) assert new_receipt.code == 200 assert new_receipt.parsed == True assert new_receipt.valid == True
def _check_dataset(self, dataset_submission): retry_counter = 0 exception = None while retry_counter < SwordStatementCheckThread.retry_count: try: # logger.info("Checking state of dataset at " + dataset_submission.remote_url) opener = openers.get_opener(dataset_submission.repository, dataset_submission.submitting_user) conn = Connection(error_response_raises_exceptions=False, http_impl=UrlLib2Layer(opener)) receipt = conn.get_deposit_receipt( dataset_submission.remote_url) statement = conn.get_ore_sword_statement( receipt.ore_statement_iri) for state_uri, state_desc in statement.states: logger.info("Dataset has state URI: " + state_uri) if state_uri in ERROR_STATES: dataset_submission.status = 'error' logger.info( "URI: " + state_uri + " is an error state ... setting 'error' state on submission record" ) break dataset_submission.last_accessed = datetime.datetime.now() dataset_submission.save() time.sleep(SwordStatementCheckThread.throttle) except urllib2.URLError as e: # if we get an exception, try again up to the limit logger.info( "Got error connecting to the server ... retrying " + str(retry_counter + 1) + " of " + str(SwordStatementCheckThread.retry_count)) retry_counter += 1 exception = e time.sleep(SwordStatementCheckThread.retry_delay) continue else: # if we don't get an exception, we're done return # if we don't return from the else statement above, it means the retries # all failed, and we have a problem. Raise the last thrown exception. raise exception
def test_21_advanced_replace_with_multipart(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, metadata_entry=e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/") with open(PACKAGE) as pkg: new_receipt = conn.update( dr=receipt, metadata_entry=ne, payload=pkg, mimetype=PACKAGE_MIME, filename="update.zip", packaging='http://purl.org/net/sword/package/SimpleZip', in_progress=True) assert new_receipt.code == 204 or new_receipt.code == 200 if new_receipt.code == 204: assert new_receipt.dom is None if new_receipt.code == 200: assert new_receipt.parsed == True assert new_receipt.valid == True
def test_01_massive_file(self): http = UrlLib2Layer() conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, http_impl=http) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="scalability testing", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri = col.href, metadata_entry = e) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace with open(PACKAGE) as pkg: new_receipt = conn.update(dr = receipt, payload=pkg, mimetype=PACKAGE_MIME, filename="massive_file.zip", packaging='http://purl.org/net/sword/package/Binary') assert new_receipt.code == 204
def test_23_basic_add_content_to_resource_single_file(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip') receipt = conn.get_deposit_receipt(receipt.location) with open(PACKAGE) as pkg: new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip", mimetype=PACKAGE_MIME) assert new_receipt.code >= 200 and new_receipt.code < 400 assert new_receipt.location is not None assert new_receipt.location != receipt.edit_media
def test_10_advanced_retrieve_deposit_receipt(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] suggested_id = str(uuid.uuid4()) e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri = col.href, metadata_entry = e, in_progress = True, suggested_identifier = suggested_id) # we're going to work with the location assert receipt.location != None new_receipt = conn.get_deposit_receipt(receipt.location) assert new_receipt.code == 200 assert new_receipt.parsed == True assert new_receipt.valid == True print new_receipt.to_xml() # Here are some more things we can know about the receipt # 1 - the links will all contain the suggested identifier # 2 - the links will all contain the name of the silo # 3 - the packaging will contain DataBankBagIt # 4 - the DC metadata will be reflected back at us # 5 - the atom metadata will be populated in some way for rel, links in new_receipt.links.iteritems(): for link in links: assert suggested_id in link['href'] assert col.title in link['href'] assert "http://dataflow.ox.ac.uk/package/DataBankBagIt" in new_receipt.packaging # check the atom metadata assert new_receipt.title == "An entry only deposit" assert new_receipt.summary == "abstract" # check the DC metadata assert "An entry only deposit" in new_receipt.metadata["dcterms_title"] assert "abstract" in new_receipt.metadata["dcterms_abstract"] assert "http://whatever/" in new_receipt.metadata["dcterms_identifier"]
def test_09_basic_retrieve_deposit_receipt(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip') # we're going to work with the location assert receipt.location != None new_receipt = conn.get_deposit_receipt(receipt.location) assert new_receipt.code == 200 assert new_receipt.parsed == True assert new_receipt.valid == True
def test_09_basic_retrieve_deposit_receipt(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # we're going to work with the location assert receipt.location != None new_receipt = conn.get_deposit_receipt(receipt.location) assert new_receipt.code == 200 assert new_receipt.parsed == True assert new_receipt.valid == True
def test_19_advanced_replace_metadata(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri = col.href, metadata_entry = e) # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/") new_receipt = conn.update(dr=receipt, metadata_entry=ne, in_progress=True) assert new_receipt.code == 204 or new_receipt.code == 200 if new_receipt.code == 204: assert new_receipt.dom is None if new_receipt.code == 200: assert new_receipt.parsed == True assert new_receipt.valid == True
def test_14_error_retrieve_content_em_iri(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, error_response_raises_exceptions=False) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) error = 'http://purl.org/net/sword/package/IJustMadeThisUp' response = conn.get_resource(content_iri=receipt.edit_media, packaging=error) assert response.code == 406 assert isinstance(response, Error_Document) assert response.error_href == "http://purl.org/net/sword/error/ErrorContent"
def test_12_basic_retrieve_content_em_iri(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # we're going to work with the edit_media iri assert receipt.edit_media is not None resource = conn.get_resource(content_iri=receipt.edit_media) assert resource.code == 200 assert resource.content is not None
def test_10_advanced_retrieve_deposit_receipt(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip', in_progress = True, suggested_identifier = "0987654321") # we're going to work with the location assert receipt.location != None new_receipt = conn.get_deposit_receipt(receipt.location) assert new_receipt.code == 200 assert new_receipt.parsed == True assert new_receipt.valid == True
def test_16_basic_replace_file_content(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri = col.href, metadata_entry = e) # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now do the replace with open(PACKAGE) as pkg: new_receipt = conn.update(dr = receipt, payload=pkg, mimetype=PACKAGE_MIME, filename="update.zip", packaging='http://purl.org/net/sword/package/SimpleZip') assert new_receipt.code == 204 assert new_receipt.dom is None
def test_22_delete_content(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] #e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, #metadata_entry = e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) # now delete the content but not the container new_receipt = conn.delete_content_of_resource(dr=receipt) assert new_receipt.code == 204 assert new_receipt.dom is None
def test_26_advanced_add_content_to_resource_package(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip', in_progress=True) receipt = conn.get_deposit_receipt(receipt.location) with open(PACKAGE) as pkg: new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip", mimetype=PACKAGE_MIME, packaging="http://purl.org/net/sword/package/SimpleZip", metadata_relevant=True) assert new_receipt.code >= 200 and new_receipt.code < 400 assert new_receipt.location is not None assert new_receipt.location == receipt.edit_media
def test_13_advanced_retrieve_content_em_iri(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) packaging = 'http://purl.org/net/sword/package/SimpleZip' if receipt.packaging is not None and len(receipt.packaging) > 0: packaging = receipt.packaging[0] resource = conn.get_resource(content_iri=receipt.edit_media, packaging=packaging, on_behalf_of=SSS_OBO) assert resource.code == 200 assert resource.content is not None
def test_27_basic_add_metadata(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") #with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, metadata_entry = e #, #payload=pkg, #mimetype=PACKAGE_MIME, #filename="example.zip", #packaging = 'http://purl.org/net/sword/package/SimpleZip' ) # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/", dcterms_creator="Me!", dcterms_rights="CC0") new_receipt = conn.append(dr=receipt, metadata_entry=ne) assert new_receipt.code == 200
def test_23_basic_add_content_to_resource_single_file(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] with open(PACKAGE) as pkg: receipt = conn.create( col_iri=col.href, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging='http://purl.org/net/sword/package/SimpleZip', in_progress=True) receipt = conn.get_deposit_receipt(receipt.location) with open(PACKAGE) as pkg: new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip", mimetype=PACKAGE_MIME) assert new_receipt.code >= 200 and new_receipt.code < 400 assert new_receipt.location is not None assert new_receipt.location != receipt.edit_media
def test_34_complete_deposit(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] #e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title") with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, #metadata_entry = e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip', in_progress = True, suggested_identifier = "zyxwvutsrq") # ensure that we have a receipt (the server may not give us one # by default) edit_iri = receipt.location receipt = conn.get_deposit_receipt(edit_iri) response = conn.complete_deposit(dr=receipt) assert response.code == 200
def _check_dataset(self, dataset_submission): retry_counter = 0 exception = None while retry_counter < SwordStatementCheckThread.retry_count: try: # logger.info("Checking state of dataset at " + dataset_submission.remote_url) opener = openers.get_opener(dataset_submission.repository, dataset_submission.submitting_user) conn = Connection(error_response_raises_exceptions=False, http_impl=UrlLib2Layer(opener)) receipt = conn.get_deposit_receipt(dataset_submission.remote_url) statement = conn.get_ore_sword_statement(receipt.ore_statement_iri) for state_uri, state_desc in statement.states: logger.info("Dataset has state URI: " + state_uri) if state_uri in ERROR_STATES: dataset_submission.status = 'error' logger.info("URI: " + state_uri + " is an error state ... setting 'error' state on submission record") break dataset_submission.last_accessed = datetime.datetime.now() dataset_submission.save() time.sleep(SwordStatementCheckThread.throttle) except urllib2.URLError as e: # if we get an exception, try again up to the limit logger.info("Got error connecting to the server ... retrying " + str(retry_counter + 1) + " of " + str(SwordStatementCheckThread.retry_count)) retry_counter += 1 exception = e time.sleep(SwordStatementCheckThread.retry_delay) continue else: # if we don't get an exception, we're done return # if we don't return from the else statement above, it means the retries # all failed, and we have a problem. Raise the last thrown exception. raise exception
def test_33_get_ore_statement(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO) conn.get_service_document() col = conn.sd.workspaces[0][1][0] #e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") with open(PACKAGE) as pkg: receipt = conn.create(col_iri = col.href, #metadata_entry = e, payload=pkg, mimetype=PACKAGE_MIME, filename="example.zip", packaging = 'http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) edit_iri = receipt.location receipt = conn.get_deposit_receipt(edit_iri) assert receipt.ore_statement_iri is not None # get the statement statement = conn.get_ore_sword_statement(receipt.ore_statement_iri) assert isinstance(statement, Ore_Sword_Statement)
def complete_submission(self, dataset, opener, dataset_submission, filename, retry_limit=3, retry_delay=2): logger.debug("Carrying out complete submission") # create a connection repository = dataset_submission.repository conn = Connection(repository.sword2_sd_url, error_response_raises_exceptions=False, http_impl=UrlLib2Layer(opener)) conn.get_service_document() # we require there to be at least one workspace if conn.sd is None: raise SwordServiceError("did not successfully retrieve a service document") if conn.sd.workspaces is None: raise SwordServiceError("no workspaces defined in service document") if len(conn.sd.workspaces) == 0: raise SwordServiceError("no workspaces defined in service document") # get hold of a copy of the deposit reciept edit_uri = dataset_submission.remote_url receipt = None try: receipt = conn.get_deposit_receipt(edit_uri) except urllib2.URLError as e: # The sword2 client does not catch network errors like this one, # which indicates that the url couldn't be reached at all # don't do anything about it here - we'll try again in a moment # and then error out appropriately later pass # at this stage we need to ensure that we actually got back a deposit # receipt i = 0 while (receipt is None or receipt.code >= 400) and i < retry_limit: err = None if receipt is None: err = "<unable to reach server>" else: err = str(receipt.code) logger.debug("Attempt to retrieve Entry Document failed with error " + str(err) + " ... trying again in " + str(retry_delay) + " seconds") i += 1 time.sleep(retry_delay) try: receipt = conn.get_deposit_receipt(edit_uri) except urllib2.URLError as e: # The sword2 client does not catch network errors like this one, # which indicates that the url couldn't be reached at all # just try again up to the retry_limit continue # if we get to here, and the receipt code is still an error, we give # up and re-set the item status if receipt is None or receipt.code >= 400: return self._set_error(dataset_submission, "error", "Attempt to retrieve Entry Document failed " + str(retry_limit + 1) + " times ... giving up") logger.debug("Entry Document retrieved ... continuing to full package deposit") # if we get to here we can go ahead with the deposit for real try: with open(filename, "rb") as data: new_receipt = conn.update(dr = receipt, payload=data, metadata_relevant = True, mimetype="application/zip", filename=dataset.identifier + ".zip", packaging='http://dataflow.ox.ac.uk/package/DataBankBagIt') if new_receipt.code >= 400: return self._set_error(dataset_submission, "error", "Attempt to deposit content failed") except urllib2.URLError as e: # The sword2 client does not catch network errors like this one, # which indicates that the url couldn't be reached at all return self._set_error(dataset_submission, "error", "Attempt to deposit content failed")
def test_33_get_ore_statement(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri = col.href, metadata_entry = e) with open(PACKAGE) as pkg: new_receipt = conn.update(dr = receipt, payload=pkg, mimetype=PACKAGE_MIME, filename="update.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) assert receipt.ore_statement_iri is not None # get the statement statement = conn.get_ore_sword_statement(receipt.ore_statement_iri) assert isinstance(statement, Ore_Sword_Statement) # some specific things that we can assert about the Statement # 1 - it should have the original deposits listed # 2 - it should have the aggregated resources listed # 3 - it should have the correct state # 4 - the dom should contain all the relevant metadata # check the original deposits od_uri = None assert len(statement.original_deposits) == 1 for od in statement.original_deposits: assert "update.zip" in od.uri assert od.is_original_deposit assert od.deposited_on is not None # assert od.deposited_by == SSS_UN # FIXME: this may not work until we get auth sorted out assert od.deposited_on_behalf_of is None od_uri = od.uri # check the aggregated resources assert len(statement.resources) == 1 for ar in statement.resources: # should be the same resource assert od_uri == ar.uri # check the states assert len(statement.states) == 1 assert statement.states[0][0] == "http://databank.ox.ac.uk/state/ZipFileAdded" print etree.tostring(statement.dom, pretty_print=True) # check the metadata md_count = 0 for e in statement.dom.findall(RDF + "Description"): for element in e.getchildren(): if element.tag == DC + "title": assert element.text.strip() == "An entry only deposit" md_count += 1 elif element.tag == DC + "abstract": assert element.text.strip() == "abstract" md_count += 1 elif element.tag == DC + "identifier": resource = element.attrib.get(RDF + "resource", None) if resource is not None: # because we know that there is going to be more than one identifier assert element.attrib.get(RDF + "resource") == "http://whatever/" md_count += 1 print "Metadata Count: " + str(md_count) assert md_count == 3
def test_33_get_ore_statement(self): conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) conn.get_service_document() col = conn.sd.workspaces[0][1][0] e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/") receipt = conn.create(col_iri=col.href, metadata_entry=e) with open(PACKAGE) as pkg: new_receipt = conn.update( dr=receipt, payload=pkg, mimetype=PACKAGE_MIME, filename="update.zip", packaging='http://purl.org/net/sword/package/SimpleZip') # ensure that we have a receipt (the server may not give us one # by default) receipt = conn.get_deposit_receipt(receipt.location) assert receipt.ore_statement_iri is not None # get the statement statement = conn.get_ore_sword_statement(receipt.ore_statement_iri) assert isinstance(statement, Ore_Sword_Statement) # some specific things that we can assert about the Statement # 1 - it should have the original deposits listed # 2 - it should have the aggregated resources listed # 3 - it should have the correct state # 4 - the dom should contain all the relevant metadata # check the original deposits od_uri = None assert len(statement.original_deposits) == 1 for od in statement.original_deposits: assert "update.zip" in od.uri assert od.is_original_deposit assert od.deposited_on is not None # assert od.deposited_by == SSS_UN # FIXME: this may not work until we get auth sorted out assert od.deposited_on_behalf_of is None od_uri = od.uri # check the aggregated resources assert len(statement.resources) == 1 for ar in statement.resources: # should be the same resource assert od_uri == ar.uri # check the states assert len(statement.states) == 1 assert statement.states[0][ 0] == "http://databank.ox.ac.uk/state/ZipFileAdded" print etree.tostring(statement.dom, pretty_print=True) # check the metadata md_count = 0 for e in statement.dom.findall(RDF + "Description"): for element in e.getchildren(): if element.tag == DC + "title": assert element.text.strip() == "An entry only deposit" md_count += 1 elif element.tag == DC + "abstract": assert element.text.strip() == "abstract" md_count += 1 elif element.tag == DC + "identifier": resource = element.attrib.get(RDF + "resource", None) if resource is not None: # because we know that there is going to be more than one identifier assert element.attrib.get( RDF + "resource") == "http://whatever/" md_count += 1 print "Metadata Count: " + str(md_count) assert md_count == 3