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_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
Example #3
0
	def __init__(self, owner):
		raise NotImplementedError
		c = Connection(SD_URI, user_name = owner.username, user_pass=owner.password)
		c.get_service_document()

		# pick the first collection within the first workspace:
		workspace_1_title, workspace_1_collections = c.workspaces[0]
		collection = workspace_1_collections[0]

		# upload "package.zip" to this collection as a new (binary) resource:
		with open("package.zip", "r") as pkg:
		    receipt = c.create(col_iri = collection.href,
		                                payload = pkg,
		                                mimetype = "application/zip",
		                                filename = "package.zip",
		                                packaging = 'http://purl.org/net/sword/package/Binary',
		                                in_progress = True)    # As the deposit isn't yet finished


		# Add a metadata record to this newly created resource (or 'container')
		from sword2 import Entry
		# Entry can be passed keyword parameters to add metadata to the entry (namespace + '_' + tagname)
		e = Entry(id="atomid", 
		          title="atom-title",
		          dcterms_abstract = "Info about the resource....",
		          )
		# to add a new namespace:
		e.register_namespace('skos', 'http://www.w3.org/2004/02/skos/core#')
		e.add_field("skos_Concept", "...")


		# Update the metadata entry to the resource:
		updated_receipt = c.update(metadata_entry = e,
		                           dr = receipt,   # use the receipt to discover the right URI to use
		                           in_progress = False)  # finish the deposit
Example #4
0
    def test_20_Multipart_POST_to_se_iri(self):
        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                          user_name="sword",
                          user_pass="******",
                          download_service_document=True)
        e = Entry(title="Foo",
                  id="asidjasidj",
                  dcterms_appendix="blah blah",
                  dcterms_title="foo bar")
        deposit_receipt = conn.create(
            payload="Multipart_POST_then_update_on_EM_IRI",
            metadata_entry=e,
            mimetype="text/plain",
            filename="readme.txt",
            packaging='http://purl.org/net/sword/package/Binary',
            col_iri=conn.sd.workspaces[0][1][0].href,
            in_progress=True)

        assert deposit_receipt.se_iri != None
        e.add_fields(dcterms_identifier="doi://multipart_update_to_SE_IRI")
        dr = conn.append(
            se_iri=deposit_receipt.se_iri,
            payload=
            "Multipart_POST_then_appending_file_on_SE_IRI  -- updated resource",
            mimetype="text/plain",
            filename="readthisextrafile.txt",
            packaging="http://purl.org/net/sword/package/Binary",
            metadata_entry=e)
        print dr.code
        assert dr.code == 201
Example #5
0
 def test_13_Metadata_POST_to_sss_altering_entry(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="******", download_service_document=True)
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
     e.add_fields(dcterms_identifier="doi://somerubbish", dcterms_foo="blah blah")
     resp = conn.create(metadata_entry = e,
                                 workspace='Main Site', 
                                 collection=conn.sd.workspaces[0][1][0].title, 
                                 in_progress=False)
     assert resp != None
Example #6
0
 def test_04_init_add_namespace(self):
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               author={
                   'name': 'Ben',
                   'email': '*****@*****.**'
               })
     e.register_namespace("mylocal", "info:localnamespace")
     assert "mylocal" in e.add_ns
Example #7
0
 def test_05_init_add_fields(self):
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               author={
                   'name': 'Ben',
                   'email': '*****@*****.**'
               })
     e.add_field("dcterms_issued", "2009")
     assert e.entry.find(NS['dcterms'] % 'issued') != None
     assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
Example #8
0
 def test_06_init_add_fields(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     e.add_fields(dcterms_issued="2009",
                  updated="2010",
                  dcterms_description="A verbose and new description")
     
     assert e.entry.find(NS['atom'] % 'updated') != None
     assert e.entry.find(NS['atom'] % 'updated').text == "2010"
     assert e.entry.find(NS['dcterms'] % 'issued') != None
     assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
     assert e.entry.find(NS['dcterms'] % 'description') != None
     assert e.entry.find(NS['dcterms'] % 'description').text == "A verbose and new description"
 def test_06_init_add_fields(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     e.add_fields(dcterms_issued="2009",
                  updated="2010",
                  dcterms_description="A verbose and new description")
     
     assert e.entry.find(NS['atom'] % 'updated') != None
     assert e.entry.find(NS['atom'] % 'updated').text == "2010"
     assert e.entry.find(NS['dcterms'] % 'issued') != None
     assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
     assert e.entry.find(NS['dcterms'] % 'description') != None
     assert e.entry.find(NS['dcterms'] % 'description').text == "A verbose and new description"
Example #10
0
 def test_08_init_add_new_ns_fields(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     e.register_namespace("mylocal", "info:localnamespace")
     e.add_fields(mylocal_foobar="2009",
                  updated="2010",
                  mylocal_description="A verbose and new description")
     
     assert e.entry.find(NS['atom'] % 'updated') != None
     assert e.entry.find(NS['atom'] % 'updated').text == "2010"
     assert e.entry.find(NS['mylocal'] % 'foobar') != None
     assert e.entry.find(NS['mylocal'] % 'foobar').text == "2009"
     assert e.entry.find(NS['mylocal'] % 'description') != None
     assert e.entry.find(NS['mylocal'] % 'description').text == "A verbose and new description"
Example #11
0
 def test_11_Multipart_POST_then_update_metadata_on_Edit_IRI(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="******", download_service_document=True)
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
     deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
                                 metadata_entry = e, 
                                 mimetype = "text/plain", 
                                 filename = "readme.txt", 
                                 packaging = 'http://purl.org/net/sword/package/Binary',
                                 col_iri = conn.sd.workspaces[0][1][0].href, 
                                 in_progress=True)
     assert deposit_receipt.code == 201    # new resource
     
     e.add_fields(dcterms_newfield = "blah de blah")
     dr = conn.update_metadata_for_resource(edit_iri = deposit_receipt.edit,
                                                     metadata_entry = e)
     assert (dr.code == 200 or dr.code == 204)
Example #12
0
 def test_03_init_with_author(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     assert e.entry.find(NS['atom'] % 'title') != None
     assert e.entry.find(NS['atom'] % 'title').text == "Foo"
     a = e.entry.find(NS['atom'] % 'author')
     name = a.find(NS['atom'] % 'name')
     assert name.text == "Ben"
    def test_36_check_md5(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',
                md5sum="123456789"
            )  # pass in a known md5 (even though it is wrong)
        statement = conn.get_ore_sword_statement(receipt.ore_statement_iri)

        # need to try and extract the md5 from the dom
        count = 0
        for element in statement.dom.findall(
                "{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description/{http://vocab.ox.ac.uk/dataset/schema#}hasMD5"
        ):
            count += 1
            assert element.text.strip() == "123456789"

        assert count == 1
Example #14
0
    def preflight_submission(self):
        opener = self.get_opener()

        conn = Connection(self.sword2_sd_url,
                          error_response_raises_exceptions=False,
                          http_impl=UrlLib2Layer(opener))
        logger.debug("Retrieving the service document")
        conn.get_service_document()

        logger.debug("Retrieved the service document")

        self.assertIsNotNone(conn.sd)
        self.assertIsNotNone(conn.sd.workspaces)
        self.assertNotEqual(len(conn.sd.workspaces), 0)

        workspace = conn.sd.workspaces[0][1]

        # we require there to be at least one collection
        self.assertNotEqual(len(workspace), 0)
        col = workspace[0]

        testid = "testid_" + str(uuid.uuid4())
        logger.debug("col iri = " + str(col.href))

        e = Entry(id=testid,
                  title="test title",
                  dcterms_abstract="test description")
        print str(e)
        receipt = conn.create(col_iri=col.href,
                              metadata_entry=e,
                              suggested_identifier=testid)
        #col.href=http://192.168.2.237/swordv2/silo/test-silo
        self.assertIsNotNone(receipt)
        self.assertEquals(receipt.code, 201)
        return receipt.location
Example #15
0
    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
Example #16
0
 def test_13_Metadata_POST_to_sss_altering_entry(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                       user_name="sword",
                       user_pass="******",
                       download_service_document=True)
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               dcterms_title="foo bar")
     e.add_fields(dcterms_identifier="doi://somerubbish",
                  dcterms_foo="blah blah")
     resp = conn.create(metadata_entry=e,
                        workspace='Main Site',
                        collection=conn.sd.workspaces[0][1][0].title,
                        in_progress=False)
     assert resp != None
Example #17
0
    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)
Example #18
0
 def test_10_Multipart_POST_then_update_on_EM_IRI(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                       user_name="sword",
                       user_pass="******",
                       download_service_document=True)
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               dcterms_title="foo bar")
     deposit_receipt = conn.create(
         payload="Multipart_POST_then_update_on_EM_IRI",
         metadata_entry=e,
         mimetype="text/plain",
         filename="readme.txt",
         packaging='http://purl.org/net/sword/package/Binary',
         col_iri=conn.workspaces[0][1][0].href,
         in_progress=True)
     assert deposit_receipt.edit_media != None
     dr = conn.update(
         payload="Multipart_POST_then_update_on_EM_IRI  -- updated resource",
         mimetype="text/plain",
         filename="readthis.txt",
         packaging="http://purl.org/net/sword/package/Binary",
         edit_media_iri=deposit_receipt.edit_media)
     assert dr.code == 204  # empty response
    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
Example #20
0
    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
Example #21
0
    def test_05_basic_create_resource_with_multipart(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]
        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')

        assert receipt.code == 201
        assert receipt.location != None

        # these last two assertions are contingent on if we actually get a
        # receipt back from the server (which we might not legitimately get)
        assert receipt.dom is None or receipt.parsed == True
        assert receipt.dom is None or receipt.valid == True
Example #22
0
    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)
Example #23
0
    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
Example #24
0
 def test_24_get_sword_statement(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                       user_name="sword",
                       user_pass="******",
                       download_service_document=True)
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               dcterms_title="foo bar")
     deposit_receipt = conn.create(
         payload="Multipart_POST_then_update_on_EM_IRI",
         metadata_entry=e,
         mimetype="text/plain",
         filename="readme.txt",
         packaging='http://purl.org/net/sword/package/Binary',
         col_iri=conn.sd.workspaces[0][1][0].href,
         in_progress=True)
     ss_iri = None
     for item_dict in deposit_receipt.links[
             'http://purl.org/net/sword/terms/statement']:
         if item_dict.has_key('type') and item_dict.get(
                 'type', None) == "application/atom+xml;type=feed":
             ss_iri = item_dict.get('href')
     assert ss_iri != None
     ss = conn.get_atom_sword_statement(ss_iri)
     assert ss != None
     assert ss.entries[0].metadata.get('sword_depositedBy') == 'sword'
Example #25
0
 def test_18_Metadata_POST_to_se_iri(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="******", download_service_document=True)
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
     deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
                                 metadata_entry = e, 
                                 mimetype = "text/plain", 
                                 filename = "readme.txt", 
                                 packaging = 'http://purl.org/net/sword/package/Binary',
                                 col_iri = conn.sd.workspaces[0][1][0].href, 
                                 in_progress=True)
                                 
     assert deposit_receipt.se_iri != None
     e.add_fields(dcterms_identifier="doi://somerubbish", dcterms_foo="blah blah")
     dr = conn.append(se_iri = deposit_receipt.se_iri,
                                           metadata_entry = e,
                                           in_progress=False)
     assert dr.code == 200    
Example #26
0
    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
Example #27
0
 def test_02_init_without_author(self):
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               dcterms_title="foo bar")
     assert e.entry.find(NS['atom'] % 'title') != None
     assert e.entry.find(NS['dcterms'] % 'appendix') != None
     assert e.entry.find(NS['dcterms'] % 'nonexistant_term') == None
Example #28
0
    def preflight_submission(self, dataset, opener, repository, silo ):
        logger.debug("Carrying out pre-flight submission")
        
        # verify that we can get a service document, and that there
        # is at least one silo and that we can authenticate
        
        if repository.sword2_sd_url is None:
            raise SwordServiceError("No sword2 service-document URL for repository configuration")
            
        # get the service document (for which we must be authenticated)
        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")
        
        workspace = conn.sd.workspaces[0][1]
        
        # we require there to be at least one collection
        if len(workspace) == 0:
            raise SwordServiceError("no collections defined in workspace")
            
        # FIXME: we don't currently have a mechanism to make decisions about
        # which collection to put stuff in, so we just put stuff in the first
        # one for the time being
        col = workspace[0]
        silohref = repository.homepage + "swordv2/silo/" + silo

        # assemble the entry ready for deposit, using the basic metadata
        # FIXME: is there anything further we need to do about the metadata here?
        e = Entry(id=dataset.identifier, title=dataset.title, dcterms_abstract=dataset.description)
        
        # create the item using the metadata-only approach (suppress errors along the way,
        # we'll check for them below)
        #receipt = conn.create(col_iri=col.href, metadata_entry=e, suggested_identifier=dataset.identifier)
        logger.debug( "Deposit is being created" )
        receipt = conn.create(col_iri=silohref, metadata_entry=e, suggested_identifier=dataset.identifier)
        logger.debug( "Deposit created" )
        # check for errors
        if receipt.code >= 400:
            # this is an error
            logger.debug("Received error message from server: " + receipt.to_xml())
            if receipt.error_href == "http://databank.ox.ac.uk/errors/DatasetConflict":
                raise SwordSlugRejected()
            raise SwordDepositError(receipt)
        
        logger.debug("Deposit carried out to: " + receipt.location)
        # return receipt.location
        return (receipt.alternate,receipt.location)
    def test_34_check_metadata_only_state(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)
        statement = conn.get_ore_sword_statement(receipt.ore_statement_iri)

        assert len(statement.states) == 1
        assert statement.states[0][0] == "http://databank.ox.ac.uk/state/EmptyContainer"
    def test_08_advanced_create_resource_with_entry(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/")
        e.register_namespace("oxds", "http://databank.ox.ac.uk/terms/")
        e.add_field("oxds_whatever", "whatever")

        receipt = conn.create(col_iri=col.href,
                              metadata_entry=e,
                              in_progress=True,
                              suggested_identifier=str(uuid.uuid4()))

        assert receipt.code == 201
        assert receipt.location != None

        # these last two assertions are contingent on if we actually get a
        # receipt back from the server (which we might not legitimately get)
        assert receipt.dom is None or receipt.parsed == True
        assert receipt.dom is None or receipt.valid == True
Example #31
0
 def test_09_Multipart_POST_to_sss_w_coliri(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                       user_name="sword",
                       user_pass="******",
                       download_service_document=True)
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               dcterms_title="foo bar")
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               dcterms_title="foo bar")
     resp = conn.create(
         payload="Multipart payload here",
         metadata_entry=e,
         mimetype="text/plain",
         filename="readme.txt",
         packaging='http://purl.org/net/sword/package/Binary',
         col_iri=conn.sd.workspaces[0][1][0].href,
         in_progress=True)
     assert resp != None
 def test_08_advanced_create_resource_with_entry(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/")
     e.register_namespace("oxds", "http://databank.ox.ac.uk/terms/")
     e.add_field("oxds_whatever", "whatever")
     
     receipt = conn.create(col_iri = col.href,
                 metadata_entry = e,
                 in_progress = True,
                 suggested_identifier = str(uuid.uuid4()))
     
     assert receipt.code == 201
     assert receipt.location != None
     
     # these last two assertions are contingent on if we actually get a 
     # receipt back from the server (which we might not legitimately get)
     assert receipt.dom is None or receipt.parsed == True
     assert receipt.dom is None or receipt.valid == True
Example #33
0
 def test_15_Metadata_POST_to_sss_w_coliri(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                       user_name="sword",
                       user_pass="******",
                       download_service_document=True)
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               dcterms_title="foo bar")
     dr = conn.create(metadata_entry=e,
                      col_iri=conn.sd.workspaces[0][1][0].href,
                      in_progress=True)
     assert dr.code == 201
    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"]
Example #35
0
    def test_11_Multipart_POST_then_update_metadata_on_Edit_IRI(self):
        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                          user_name="sword",
                          user_pass="******",
                          download_service_document=True)
        e = Entry(title="Foo",
                  id="asidjasidj",
                  dcterms_appendix="blah blah",
                  dcterms_title="foo bar")
        deposit_receipt = conn.create(
            payload="Multipart_POST_then_update_on_EM_IRI",
            metadata_entry=e,
            mimetype="text/plain",
            filename="readme.txt",
            packaging='http://purl.org/net/sword/package/Binary',
            col_iri=conn.sd.workspaces[0][1][0].href,
            in_progress=True)
        assert deposit_receipt.code == 201  # new resource

        e.add_fields(dcterms_newfield="blah de blah")
        dr = conn.update_metadata_for_resource(edit_iri=deposit_receipt.edit,
                                               metadata_entry=e)
        assert (dr.code == 200 or dr.code == 204)
 def test_07_basic_create_resource_with_entry(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)
                     
     assert receipt.code == 201
     assert receipt.location != None
     
     # these last two assertions are contingent on if we actually get a 
     # receipt back from the server (which we might not legitimately get)
     assert receipt.dom is None or receipt.parsed == True
     assert receipt.dom is None or 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
Example #38
0
 def test_04_init_add_namespace(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     e.register_namespace("mylocal", "info:localnamespace")
     assert "mylocal" in e.add_ns
Example #39
0
 def test_05_init_add_fields(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     e.add_field("dcterms_issued", "2009")
     assert e.entry.find(NS['dcterms'] % 'issued') != None
     assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
Example #40
0
 def test_07_init_add_new_ns_field(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     e.register_namespace("mylocal", "info:localnamespace")
     e.add_field("mylocal_issued", "2003")
     assert e.entry.find(NS['mylocal'] % 'issued') != None
     assert e.entry.find(NS['mylocal'] % 'issued').text == "2003"
 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