コード例 #1
0
 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)
コード例 #2
0
    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)
コード例 #3
0
    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
コード例 #4
0
    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"
コード例 #5
0
    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
コード例 #6
0
 def test_17_Simple_POST_and_GET(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="******", download_service_document=True)
     col_iri = conn.sd.workspaces[0][1][0].href  # pick the first collection
     dr = conn.create(payload = "Simple_POST_and_GET", 
                                 mimetype = "text/plain", 
                                 filename = "readme.txt", 
                                 packaging = 'http://purl.org/net/sword/package/Binary',
                                 col_iri = col_iri, 
                                 in_progress=True, 
                                 metadata_entry=None)
     assert dr.code == 201
     # Now to GET that resource with no prescribed for packaging
     content_object = conn.get_resource(dr.cont_iri)
     # Can't guarantee that sss.py won't mangle submissions, so can't validate response at this moment
     assert content_object != None
コード例 #7
0
 def test_14_Invalid_Packaging_cached_receipt(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="******", download_service_document=True, honour_receipts=True)
     col_iri = conn.sd.workspaces[0][1][0].href  # pick the first collection
     dr = conn.create(payload = "Payload is just a load of text", 
                                 mimetype = "text/plain", 
                                 filename = "readme.txt", 
                                 packaging = 'http://purl.org/net/sword/package/Binary',
                                 col_iri = col_iri, 
                                 in_progress=True)
     # Now to GET that resource with invalid packaging
     try:
         content = conn.get_resource(dr.cont_iri, packaging="foofar")
         assert 1 == 0   # fail
     except PackagingFormatNotAvailable:
         # test the 'honour_receipts' flag and cached deposit 
         pass
コード例 #8
0
ファイル: test_sss.py プロジェクト: oerpub/python-sword2
 def test_17_Simple_POST_and_GET(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                       user_name="sword",
                       user_pass="******",
                       download_service_document=True)
     col_iri = conn.sd.workspaces[0][1][0].href  # pick the first collection
     dr = conn.create(payload="Simple_POST_and_GET",
                      mimetype="text/plain",
                      filename="readme.txt",
                      packaging='http://purl.org/net/sword/package/Binary',
                      col_iri=col_iri,
                      in_progress=True,
                      metadata_entry=None)
     assert dr.code == 201
     # Now to GET that resource with no prescribed for packaging
     content_object = conn.get_resource(dr.cont_iri)
     # Can't guarantee that sss.py won't mangle submissions, so can't validate response at this moment
     assert content_object != None
コード例 #9
0
ファイル: test_sss.py プロジェクト: oerpub/python-sword2
 def test_14_Invalid_Packaging_cached_receipt(self):
     conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER,
                       user_name="sword",
                       user_pass="******",
                       download_service_document=True,
                       honour_receipts=True)
     col_iri = conn.sd.workspaces[0][1][0].href  # pick the first collection
     dr = conn.create(payload="Payload is just a load of text",
                      mimetype="text/plain",
                      filename="readme.txt",
                      packaging='http://purl.org/net/sword/package/Binary',
                      col_iri=col_iri,
                      in_progress=True)
     # Now to GET that resource with invalid packaging
     try:
         content = conn.get_resource(dr.cont_iri, packaging="foofar")
         assert 1 == 0  # fail
     except PackagingFormatNotAvailable:
         # test the 'honour_receipts' flag and cached deposit
         pass
コード例 #10
0
 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"
コード例 #11
0
 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
コード例 #12
0
 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