예제 #1
0
 def test_put_retry(self):
     eq_(g.bucket.mock_responses, [])
     xml = "<?xml etc... ?>"
     g.bucket.add_resp("/foo.txt",
                       g.H("application/xml"),
                       xml,
                       status="500 Internal Server Error")
     g.bucket.add_resp("/foo.txt", g.H("text/plain"), "OK!")
     g.bucket.put("foo.txt", "hello")
     eq_(len(g.bucket.mock_requests), 2)
     for req in g.bucket.mock_requests:
         eq_(req.get_method(), "PUT")
         eq_(req.get_selector(), "/foo.txt")
     eq_(g.bucket.mock_responses, [])
예제 #2
0
 def test_copy_metadata(self):
     g.bucket.add_resp("/bar", g.H("application/xml"), "<ok />")
     g.bucket.copy("foo/bar", "bar", acl="public")
     req = g.bucket.mock_requests[-1]
     eq_(req.get_method(), "PUT")
     eq_(req.headers["X-amz-copy-source"], "foo/bar")
     eq_(req.headers["X-amz-metadata-directive"], "COPY")
예제 #3
0
 def test_put(self):
     g.bucket.add_resp("/foo.txt", g.H("application/xml"), "OK!")
     g.bucket["foo.txt"] = "hello"
     hdrs = set(v.lower() for v in g.bucket.mock_requests[-1].headers)
     assert "content-length" in hdrs
     assert "content-type" in hdrs
     assert "content-md5" in hdrs
     assert "authorization" in hdrs
예제 #4
0
 def test_delete_other_error(self):
     g.bucket.add_resp("/foo.txt",
                       g.H("application/xml"),
                       "<wat />",
                       status="403 What's Up?")
     try:
         g.bucket.delete("foo.txt")
     except simples3.S3Error, e:
         eq_(e.extra.get("key"), "foo.txt")
         eq_(e.code, 403)
예제 #5
0
 def test_get(self):
     dt = datetime.datetime(1990, 1, 31, 12, 34, 56)
     headers = g.H("text/plain", ("date", rfc822_fmtdate(dt)),
                   ("x-amz-meta-foo", "bar"))
     g.bucket.add_resp("/foo.txt", headers, "ohi")
     fp = g.bucket["foo.txt"]
     eq_(fp.s3_info["mimetype"], "text/plain")
     eq_(fp.s3_info["metadata"], {"foo": "bar"})
     eq_(fp.s3_info["date"], dt)
     eq_(fp.read().decode("ascii"), "ohi")
예제 #6
0
    def _put_file_contents(self, key, contents):
        g.streaming_bucket.add_resp("/%s" % key, g.H("application/xml"), "OK!")

        try:
            fp = io.StringIO()
            fp.write(contents)
            g.streaming_bucket.put_file(key, fp, size=len(contents))
        finally:
            fp.close()

        self._verify_headers(contents,
                             g.streaming_bucket.mock_requests[-1].headers)
예제 #7
0
    def test_empty_listing(self):
        xml = """
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <Name>bucket</Name>
    <Prefix></Prefix>
    <Marker></Marker>
    <MaxKeys>1000</MaxKeys>
    <IsTruncated>false</IsTruncated>
</ListBucketResult>
""".lstrip()
        g.bucket.add_resp("/", g.H("application/xml"), xml)
        eq_([], list(g.bucket.listdir()))
예제 #8
0
    def test_listdir(self):
        xml = """
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <Name>bucket</Name>
    <Prefix></Prefix>
    <Marker></Marker>
    <MaxKeys>1000</MaxKeys>
    <IsTruncated>false</IsTruncated>
    <Contents>
        <Key>my-image.jpg</Key>
        <LastModified>2009-10-12T17:50:30.000Z</LastModified>
        <ETag>&quot;fba9dede5f27731c9771645a39863328&quot;</ETag>
        <Size>434234</Size>
        <StorageClass>STANDARD</StorageClass>
        <Owner>
            <ID>0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef</ID>
            <DisplayName>johndoe</DisplayName>
        </Owner>
    </Contents>
    <Contents>
        <Key>my-third-image.jpg</Key>
        <LastModified>2009-10-12T17:50:30.000Z</LastModified>
        <ETag>&quot;1b2cf535f27731c974343645a3985328&quot;</ETag>
        <Size>64994</Size>
        <StorageClass>STANDARD</StorageClass>
        <Owner>
            <ID>0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef</ID>
            <DisplayName>johndoe</DisplayName>
        </Owner>
    </Contents>
</ListBucketResult>
""".lstrip()
        g.bucket.add_resp("/", g.H("application/xml"), xml)
        reftups = (('my-image.jpg', datetime.datetime(2009, 10, 12, 17, 50,
                                                      30),
                    '"fba9dede5f27731c9771645a39863328"', 434234),
                   ('my-third-image.jpg',
                    datetime.datetime(2009, 10, 12, 17, 50, 30),
                    '"1b2cf535f27731c974343645a3985328"', 64994))
        next_reftup = iter(reftups).next
        for tup in g.bucket.listdir():
            eq_(len(tup), 4)
            eq_(tup, next_reftup())
            key, mtype, etag, size = tup
예제 #9
0
class InfoTests(S3BucketTestCase):
    headers = g.H("text/plain", ("x-amz-meta-foo", "bar"),
                  ("last-modified", "Mon, 06 Sep 2010 19:34:18 GMT"),
                  ("content-length", "1234"))

    def test_info(self):
        g.bucket.add_resp("/foo.txt", self.headers, "")
        info = g.bucket.info("foo.txt")
        eq_(info["mimetype"], "text/plain")
        eq_(info["metadata"], {"foo": "bar"})

    def test_mapping(self):
        g.bucket.add_resp("/foo.txt", self.headers, "")
        assert "foo.txt" in g.bucket

    def test_mapping_not(self):
        g.bucket.add_resp("/foobar.txt", self.headers, "", status="404 Blah")
        assert "foobar.txt" not in g.bucket
예제 #10
0
 def test_get_not_found(self):
     xml = ('<?xml version="1.0" encoding="UTF-8"?>\n'
            '<Error><Code>NoSuchKey</Code>'
            '<Message>The specified key does not exist.</Message>'
            '<Key>foo.txt</Key>'
            '<RequestId>abcdef</RequestId>'
            '<HostId>abcdef</HostId>'
            '</Error>')
     g.bucket.add_resp("/foo.txt",
                       g.H("application/xml"),
                       xml,
                       status="404 Not Found")
     try:
         g.bucket.get("foo.txt")
     except simples3.KeyNotFound, e:
         eq_(e.key, "foo.txt")
         eq_(
             str(e), "The specified key does not exist. (code=404, "
             "key='foo.txt', filename='http://johnsmith.s3."
             "amazonaws.com/foo.txt')")
예제 #11
0
 def test_copy_replace_metadata(self):
     g.bucket.add_resp("/bar", g.H("application/xml"), "<ok />")
     g.bucket.copy("foo/bar", "bar", metadata={}, acl="public")
     req = g.bucket.mock_requests[-1]
     eq_(req.headers["X-amz-metadata-directive"], "REPLACE")
예제 #12
0
 def test_delete_not_found(self):
     g.bucket.add_resp("/foo.txt",
                       g.H("application/xml"),
                       "<notfound />",
                       status="404 Not Found")
     assert not g.bucket.delete("foo.txt")
예제 #13
0
 def test_bucket_delete(self):
     g.bucket.add_resp("/", g.H("application/xml"), "<ok />")
     g.bucket.delete_bucket()
     req = g.bucket.mock_requests[-1]
     eq_(req.get_method(), "DELETE")
예제 #14
0
 def test_put_s3file(self):
     g.bucket.add_resp("/foo.txt", g.H("application/xml"), "OK!")
     g.bucket["foo.txt"] = simples3.S3File("hello")
     data = g.bucket.mock_requests[-1].get_data()
     eq_(data.decode("ascii"), "hello")
예제 #15
0
 def test_bucket_put(self):
     g.bucket.add_resp("/", g.H("application/xml"), "<ok />")
     g.bucket.put_bucket(acl="private")
     req = g.bucket.mock_requests[-1]
     eq_(req.get_method(), "PUT")
     eq_(req.headers["X-amz-acl"], "private")
예제 #16
0
 def test_bucket_put_conf(self):
     g.bucket.add_resp("/", g.H("application/xml"), "<ok />")
     g.bucket.put_bucket("<etc>etc</etc>", acl="public")
     req = g.bucket.mock_requests[-1]
     eq_(req.get_method(), "PUT")
     eq_(req.headers["X-amz-acl"], "public")
예제 #17
0
 def test_delete(self):
     g.bucket.add_resp("/foo.txt", g.H("application/xml"), "<ok />")
     assert g.bucket.delete("foo.txt")
     req = g.bucket.mock_requests[-1]
     eq_(req.get_method(), "DELETE")
예제 #18
0
 def test_delete_multi_object(self):
     expected = ('<?xml version="1.0" encoding="UTF-8"?>\n'
                 '<DeleteResult xmlns="http://s3.amazonaws.com/doc/2006-'
                 '03-01/"></DeleteResult>')
     g.bucket.add_resp("/?delete", g.H("application/xml"), expected)
     assert g.bucket.delete("foo.txt", "bar.txt", "baz.txt")
예제 #19
0
 def _put_contents(self, key, contents):
     g.bucket.add_resp("/%s" % key, g.H("application/xml"), "OK!")
     g.bucket[key] = contents
     self._verify_headers(contents, g.bucket.mock_requests[-1].headers)