def get_container(self, container): cname = self._resolve_name(container) if not cname: raise exc.MissingName("No container name specified") cont = self._container_cache.get(cname) if not cont: hdrs = self.connection.head_container(cname) cont = Container(self, name=cname, object_count=hdrs.get("x-container-object-count"), total_bytes=hdrs.get("x-container-bytes-used")) self._container_cache[cname] = cont return cont
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)
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)
def get_all_containers(self, limit=None, marker=None, **parms): hdrs, conts = self.connection.get_container("") ret = [Container(self, name=cont["name"], object_count=cont["count"], total_bytes=cont["bytes"]) for cont in conts] return ret