def test_set_external_hostname(self):
    bucket_name = ('test-bucket-%s' % short_uid())
    key = 'test.file'
    hostname_before = config.HOSTNAME_EXTERNAL
    config.HOSTNAME_EXTERNAL = 'foobar'
    try:
        content = 'test content 123'
        acl = 'public-read'
        self.s3_client.create_bucket(Bucket=bucket_name)
        response = self._perform_multipart_upload(bucket=bucket_name, key=key, data=content, acl=acl)
        expected_url = ('%s://%s:%s/%s/%s' % (get_service_protocol(), config.HOSTNAME_EXTERNAL, config.PORT_S3, bucket_name, key))
        self.assertEqual(expected_url, response['Location'])
        self.s3_client.put_object_acl(Bucket=bucket_name, Key=key, ACL=acl)
        downloaded_object = self.s3_client.get_object(Bucket=bucket_name, Key=key)
        self.assertEqual(to_str(downloaded_object['Body'].read()), content)
        download_url = response['Location'].replace(('%s:' % config.HOSTNAME_EXTERNAL), 'localhost:')
        response = safe_requests.get(download_url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(to_str(response.content), content)
    finally:
        config.HOSTNAME_EXTERNAL = hostname_before
def test_set_external_hostname(self):
    bucket_name = ('test-bucket-%s' % short_uid())
    key = 'test.file'
    hostname_before = config.HOSTNAME_EXTERNAL
    config.HOSTNAME_EXTERNAL = 'foobar'
    try:
        content = 'test content 123'
        acl = 'public-read'
        self.s3_client.create_bucket(Bucket=bucket_name)
        response = self._perform_multipart_upload(bucket=bucket_name, key=key, data=content, acl=acl)
        expected_url = ('%s://%s:%s/%s/%s' % (get_service_protocol(), config.HOSTNAME_EXTERNAL, config.PORT_S3, bucket_name, key))
        self.assertEqual(expected_url, response['Location'])
        self.s3_client.put_object_acl(Bucket=bucket_name, Key=key, ACL=acl)
        downloaded_object = self.s3_client.get_object(Bucket=bucket_name, Key=key)
        self.assertEqual(to_str(downloaded_object['Body'].read()), content)
        download_url = response['Location'].replace(('%s:' % config.HOSTNAME_EXTERNAL), 'localhost:')
        response = safe_requests.get(download_url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(to_str(response.content), content)
    finally:
        config.HOSTNAME_EXTERNAL = hostname_before