Esempio n. 1
0
 def test_get_container_cdn_metadata(self):
     client = self.client
     client.connection.cdn_request = Mock()
     resp = FakeResponse()
     resp.headers = [("a", "b"), ("c", "d")]
     client.connection.cdn_request.return_value = resp
     returned = client.get_container_cdn_metadata(self.cont_name)
     expected = {"a": "b", "c": "d"}
     self.assertEqual(expected, returned)
Esempio n. 2
0
 def test_get_container_cdn_metadata(self):
     client = self.client
     client.connection.cdn_request = Mock()
     resp = FakeResponse()
     resp.headers = [("a", "b"), ("c", "d")]
     client.connection.cdn_request.return_value = resp
     returned = client.get_container_cdn_metadata(self.cont_name)
     expected = {"a": "b", "c": "d"}
     self.assertEqual(expected, returned)
Esempio n. 3
0
 def test_make_private(self):
     cont = self.container
     cont.client.connection.cdn_request = Mock()
     example = "http://example.com"
     cont.cdn_uri = example
     resp = FakeResponse()
     resp.headers = [("c", "d")]
     cont.client.connection.cdn_request.return_value = resp
     cont.make_private()
     cont.client.connection.cdn_request.assert_called_with(
         "PUT", [cont.name], hdrs={"X-CDN-Enabled": "False"})
Esempio n. 4
0
 def test_make_private(self):
     cont = self.container
     cont.client.connection.cdn_request = Mock()
     example = "http://example.com"
     cont.cdn_uri = example
     resp = FakeResponse()
     resp.headers = [("c", "d")]
     cont.client.connection.cdn_request.return_value = resp
     cont.make_private()
     cont.client.connection.cdn_request.assert_called_with("PUT",
             [cont.name], hdrs={"X-CDN-Enabled": "False"})
Esempio n. 5
0
 def test_list_public_containers(self):
     client = self.client
     client.connection.cdn_request = Mock()
     resp = FakeResponse()
     resp.headers = [("a", "b"), ("c", "d")]
     resp.status = 500
     client.connection.cdn_request.return_value = resp
     self.assertRaises(exc.CDNFailed, client.list_public_containers)
     resp.status = 200
     conts = client.list_public_containers()
     client.connection.cdn_request.assert_called_with("GET", [""])
     self.assertEqual(len(conts), 2)
Esempio n. 6
0
 def test_list_public_containers(self):
     client = self.client
     client.connection.cdn_request = Mock()
     resp = FakeResponse()
     resp.headers = [("a", "b"), ("c", "d")]
     resp.status = 500
     client.connection.cdn_request.return_value = resp
     self.assertRaises(exc.CDNFailed, client.list_public_containers)
     resp.status = 200
     conts = client.list_public_containers()
     client.connection.cdn_request.assert_called_with("GET", [""])
     self.assertEqual(len(conts), 2)
Esempio n. 7
0
 def test_make_public(self, ttl=None):
     cont = self.container
     cont.cdn_uri = ""
     cont.client.connection.cdn_request = Mock()
     example = "http://example.com"
     ttl = 6666
     resp = FakeResponse()
     resp.headers = [("x-cdn-uri", example), ("c", "d")]
     cont.client.connection.cdn_request.return_value = resp
     cont.make_public(ttl)
     cont.client.connection.cdn_request.assert_called_with("PUT",
             [cont.name], hdrs={"X-TTL": str(ttl), "X-CDN-Enabled": "True"})
Esempio n. 8
0
 def test_make_public(self, ttl=None):
     cont = self.container
     cont.cdn_uri = ""
     cont.client.connection.cdn_request = Mock()
     example = "http://example.com"
     ttl = 6666
     resp = FakeResponse()
     resp.headers = [("x-cdn-uri", example), ("c", "d")]
     cont.client.connection.cdn_request.return_value = resp
     cont.make_public(ttl)
     cont.client.connection.cdn_request.assert_called_with("PUT",
             [cont.name], hdrs={"X-TTL": str(ttl), "X-CDN-Enabled": "True"})
Esempio n. 9
0
 def test_set_cdn_log_retention(self):
     client = self.client
     client.connection.head_container = Mock()
     cont = client.get_container(self.cont_name)
     client.connection.cdn_request = Mock()
     resp = FakeResponse()
     client.connection.cdn_request.return_value = resp
     resp.status = 500
     self.assertRaises(exc.CDNFailed, client.set_cdn_log_retention, cont, True)
     resp.status = 204
     client.set_cdn_log_retention(cont, True)
     self.assert_(cont.cdn_log_retention)
     client.set_cdn_log_retention(cont, False)
     self.assertFalse(cont.cdn_log_retention)
Esempio n. 10
0
 def test_set_cdn_log_retention(self):
     client = self.client
     client.connection.head_container = Mock()
     cont = client.get_container(self.cont_name)
     client.connection.cdn_request = Mock()
     resp = FakeResponse()
     client.connection.cdn_request.return_value = resp
     resp.status = 500
     self.assertRaises(exc.CDNFailed, client.set_cdn_log_retention, cont,
                       True)
     resp.status = 204
     client.set_cdn_log_retention(cont, True)
     self.assert_(cont.cdn_log_retention)
     client.set_cdn_log_retention(cont, False)
     self.assertFalse(cont.cdn_log_retention)
Esempio n. 11
0
 def test_fetch_cdn_not_found(self):
     self.client.connection.cdn_request = Mock()
     resp = FakeResponse()
     resp.status = 404
     resp.getheaders = Mock()
     test_uri = "http://example.com"
     test_ttl = "6666"
     test_ssl_uri = "http://ssl.example.com"
     test_streaming_uri = "http://streaming.example.com"
     test_log_retention = True
     resp.getheaders.return_value = []
     self.client.connection.cdn_request.return_value = resp
     # We need an actual container
     cont = Container(self.client, "realcontainer", 0, 0)
     self.assertIsNone(cont.cdn_uri)
Esempio n. 12
0
 def test_make_container_private(self):
     client = self.client
     client.connection.head_container = Mock()
     cont = client.get_container(self.cont_name)
     cont.cdn_uri = None
     client.connection.cdn_request = Mock()
     example = "http://example.com"
     resp = FakeResponse()
     resp.headers = [("x-cdn-uri", example), ("c", "d")]
     resp.status = 500
     client.connection.cdn_request.return_value = resp
     self.assertRaises(exc.CDNFailed, client.make_container_public, self.cont_name)
     resp.status = 204
     client.make_container_private(self.cont_name)
     client.connection.cdn_request.assert_called_with("PUT", [self.cont_name], hdrs={"X-CDN-Enabled": "False"})
Esempio n. 13
0
 def test_fetch_cdn_not_found(self):
     self.client.connection.cdn_request = Mock()
     resp = FakeResponse()
     resp.status = 404
     resp.getheaders = Mock()
     test_uri = "http://example.com"
     test_ttl = "6666"
     test_ssl_uri = "http://ssl.example.com"
     test_streaming_uri = "http://streaming.example.com"
     test_ios_uri = "http://ios.example.com"
     test_log_retention = True
     resp.getheaders.return_value = []
     self.client.connection.cdn_request.return_value = resp
     # We need an actual container
     cont = Container(self.client, "realcontainer", 0, 0)
     self.assertIsNone(cont.cdn_uri)
Esempio n. 14
0
 def test_make_container_private(self):
     client = self.client
     client.connection.head_container = Mock()
     cont = client.get_container(self.cont_name)
     cont.cdn_uri = None
     client.connection.cdn_request = Mock()
     example = "http://example.com"
     resp = FakeResponse()
     resp.headers = [("x-cdn-uri", example), ("c", "d")]
     resp.status = 500
     client.connection.cdn_request.return_value = resp
     self.assertRaises(exc.CDNFailed, client.make_container_public,
                       self.cont_name)
     resp.status = 204
     client.make_container_private(self.cont_name)
     client.connection.cdn_request.assert_called_with(
         "PUT", [self.cont_name], hdrs={"X-CDN-Enabled": "False"})
Esempio n. 15
0
 def test_fetch_cdn(self):
     self.client.connection.cdn_request = Mock()
     resp = FakeResponse()
     resp.status = 204
     resp.getheaders = Mock()
     test_uri = "http://example.com"
     test_ttl = "6666"
     test_ssl_uri = "http://ssl.example.com"
     test_streaming_uri = "http://streaming.example.com"
     test_log_retention = True
     resp.getheaders.return_value = [("x-cdn-uri", test_uri), ("x-ttl", test_ttl),
             ("x-cdn-ssl-uri", test_ssl_uri), ("x-cdn-streaming-uri", test_streaming_uri),
             ("x-log-retention", test_log_retention)]
     self.client.connection.cdn_request.return_value = resp
     # We need an actual container
     cont = Container(self.client, "realcontainer", 0, 0)
     self.assertEqual(cont.cdn_uri, test_uri)
Esempio n. 16
0
 def test_fetch_cdn(self):
     self.client.connection.cdn_request = Mock()
     resp = FakeResponse()
     resp.status = 204
     resp.getheaders = Mock()
     test_uri = "http://example.com"
     test_ttl = "6666"
     test_ssl_uri = "http://ssl.example.com"
     test_streaming_uri = "http://streaming.example.com"
     test_ios_uri = "http://ios.example.com"
     test_log_retention = True
     resp.getheaders.return_value = [("x-cdn-uri", test_uri),
             ("x-ttl", test_ttl), ("x-cdn-ssl-uri", test_ssl_uri),
             ("x-cdn-streaming-uri", test_streaming_uri),
             ("x-cdn-ios-uri", test_ios_uri),
             ("x-log-retention", test_log_retention)]
     self.client.connection.cdn_request.return_value = resp
     # We need an actual container
     cont = Container(self.client, "realcontainer", 0, 0)
     self.assertEqual(cont.cdn_uri, test_uri)