Ejemplo n.º 1
0
 def test_default_creation(self):
     query = client.Query(action="PUT")
     self.assertEquals(query.bucket, None)
     self.assertEquals(query.object_name, None)
     self.assertEquals(query.data, "")
     self.assertEquals(query.content_type, None)
     self.assertEquals(query.metadata, {})
Ejemplo n.º 2
0
    def test_object_query(self):
        """
        Test that a request addressing an object is created correctly.
        """
        DATA = "objectData"
        DIGEST = "zhdB6gwvocWv/ourYUWMxA=="

        request = client.Query(action="PUT",
                               bucket="somebucket",
                               object_name="object/name/here",
                               data=DATA,
                               content_type="text/plain",
                               metadata={"foo": "bar"},
                               amz_headers={"acl": "public-read"},
                               creds=self.creds,
                               endpoint=self.endpoint)
        request.sign = lambda headers: "TESTINGSIG="
        self.assertEqual(request.action, "PUT")
        headers = request.get_headers()
        self.assertNotEqual(headers.pop("Date"), "")
        self.assertEqual(
            headers, {
                "Authorization": "AWS fookeyid:TESTINGSIG=",
                "Content-Type": "text/plain",
                "Content-Length": len(DATA),
                "Content-MD5": DIGEST,
                "x-amz-meta-foo": "bar",
                "x-amz-acl": "public-read"
            })
        self.assertEqual(request.data, "objectData")
Ejemplo n.º 3
0
 def test_set_content_type_with_content_type_already_set(self):
     query = client.Query(action="PUT",
                          object_name="data.txt",
                          content_type="text/csv")
     query.set_content_type()
     self.assertNotEquals(query.content_type, "text/plain")
     self.assertEquals(query.content_type, "text/csv")
Ejemplo n.º 4
0
    def test_authentication(self):
        query = client.Query(action="GET",
                             creds=self.creds,
                             endpoint=self.endpoint)
        query.sign = lambda headers: "TESTINGSIG="
        query.date = "Wed, 28 Mar 2007 01:29:59 +0000"

        headers = query.get_headers()
        self.assertEqual(headers["Authorization"], "AWS fookeyid:TESTINGSIG=")
Ejemplo n.º 5
0
 def test_get_headers_with_data(self):
     query = client.Query(
         action="GET", creds=self.creds, bucket="mystuff",
         object_name="/images/thing.jpg", data="BINARY IMAGE DATA")
     headers = query.get_headers()
     self.assertEquals(headers.get("Content-Type"), "image/jpeg")
     self.assertEquals(headers.get("Content-Length"), 17)
     self.assertTrue(len(headers.get("Date")) > 25)
     self.assertTrue(
         headers.get("Authorization").startswith("AWS fookeyid:"))
     self.assertTrue(len(headers.get("Authorization")) > 40)
Ejemplo n.º 6
0
 def test_get_canonicalized_amz_headers(self):
     query = client.Query(
         action="SomeThing", metadata={"a": 1, "b": 2, "c": 3})
     headers = query.get_headers()
     self.assertEquals(
         sorted(headers.keys()),
         ["Content-Length", "Content-MD5", "Date", "x-amz-meta-a",
          "x-amz-meta-b", "x-amz-meta-c"])
     amz_headers = query.get_canonicalized_amz_headers(headers)
     self.assertEquals(
         amz_headers,
         "x-amz-meta-a:1\nx-amz-meta-b:2\nx-amz-meta-c:3\n")
Ejemplo n.º 7
0
 def test_get_headers(self):
     query = client.Query(
         action="GET", creds=self.creds, bucket="mystuff",
         object_name="/images/thing.jpg")
     headers = query.get_headers()
     self.assertEquals(headers.get("Content-Type"), "image/jpeg")
     self.assertEquals(headers.get("Content-Length"), 0)
     self.assertEquals(
         headers.get("Content-MD5"), "1B2M2Y8AsgTpgAmY7PhCfg==")
     self.assertTrue(len(headers.get("Date")) > 25)
     self.assertTrue(
         headers.get("Authorization").startswith("AWS fookeyid:"))
     self.assertTrue(len(headers.get("Authorization")) > 40)
Ejemplo n.º 8
0
    def test_bucket_query(self):
        """
        Test that a request addressing a bucket is created correctly.
        """
        DIGEST = "1B2M2Y8AsgTpgAmY7PhCfg=="

        query = client.Query(
            action="GET", bucket="somebucket", creds=self.creds,
            endpoint=self.endpoint)
        query.sign = lambda headers: "TESTINGSIG="
        self.assertEqual(query.action, "GET")
        headers = query.get_headers()
        self.assertNotEqual(headers.pop("Date"), "")
        self.assertEqual(
            headers, {
            "Authorization": "AWS fookeyid:TESTINGSIG=",
            "Content-Length": 0,
            "Content-MD5": DIGEST})
        self.assertEqual(query.data, "")
Ejemplo n.º 9
0
 def test_sign(self):
     query = client.Query(action="PUT", creds=self.creds)
     signed = query.sign({})
     self.assertEquals(signed, "H6UJCNHizzXZCGPl7wM6nL6tQdo=")
Ejemplo n.º 10
0
 def test_get_canonicalized_resource_with_slashed_object_name(self):
     query = client.Query(
         action="PUT", bucket="images", object_name="/advicedog.jpg")
     result = query.get_canonicalized_resource()
     self.assertEquals(result, "/images/advicedog.jpg")
Ejemplo n.º 11
0
 def test_get_canonicalized_resource(self):
     query = client.Query(action="PUT", bucket="images")
     result = query.get_canonicalized_resource()
     self.assertEquals(result, "/images/")
Ejemplo n.º 12
0
 def test_set_content_type(self):
     query = client.Query(action="PUT", object_name="advicedog.jpg")
     query.set_content_type()
     self.assertEquals(query.content_type, "image/jpeg")
Ejemplo n.º 13
0
 def test_set_content_type_no_object_name(self):
     query = client.Query(action="PUT")
     query.set_content_type()
     self.assertEquals(query.content_type, None)
Ejemplo n.º 14
0
 def test_default_endpoint(self):
     query = client.Query(action="PUT")
     self.assertEquals(self.endpoint.host, "choopy.s3.amazonaws.com")
     self.assertEquals(query.endpoint.host, "s3.amazonaws.com")
     self.assertEquals(self.endpoint.method, "GET")
     self.assertEquals(query.endpoint.method, "PUT")