Techdebt: Replace sure with regular assertions in s3bucket_path (#6601)

This commit is contained in:
kbalk 2023-08-04 17:52:10 -04:00 committed by GitHub
parent fc53fd6950
commit 7a17e0f89d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 34 deletions

View File

@ -1,16 +1,13 @@
from sure import expect
from moto.s3bucket_path.utils import bucket_name_from_url
def test_base_url():
expect(bucket_name_from_url("https://s3.amazonaws.com/")).should.equal(None)
assert bucket_name_from_url("https://s3.amazonaws.com/") is None
def test_localhost_bucket():
expect(bucket_name_from_url("https://localhost:5000/wfoobar/abc")).should.equal(
"wfoobar"
)
assert bucket_name_from_url("https://localhost:5000/wfoobar/abc") == "wfoobar"
def test_localhost_without_bucket():
expect(bucket_name_from_url("https://www.localhost:5000")).should.equal(None)
assert bucket_name_from_url("https://www.localhost:5000") is None

View File

@ -1,12 +1,7 @@
import sure # noqa # pylint: disable=unused-import
"""Test the different server responses."""
from flask.testing import FlaskClient
import moto.server as server
"""
Test the different server responses
"""
class AuthenticatedClient(FlaskClient):
def open(self, *args, **kwargs):
@ -27,48 +22,48 @@ def test_s3_server_get():
res = test_client.get("/")
res.data.should.contain(b"ListAllMyBucketsResult")
assert b"ListAllMyBucketsResult" in res.data
def test_s3_server_bucket_create():
test_client = authenticated_client()
res = test_client.put("/foobar", "http://localhost:5000")
res.status_code.should.equal(200)
assert res.status_code == 200
res = test_client.get("/")
res.data.should.contain(b"<Name>foobar</Name>")
assert b"<Name>foobar</Name>" in res.data
res = test_client.get("/foobar", "http://localhost:5000")
res.status_code.should.equal(200)
res.data.should.contain(b"ListBucketResult")
assert res.status_code == 200
assert b"ListBucketResult" in res.data
res = test_client.put("/foobar2/", "http://localhost:5000")
res.status_code.should.equal(200)
assert res.status_code == 200
res = test_client.get("/")
res.data.should.contain(b"<Name>foobar2</Name>")
assert b"<Name>foobar2</Name>" in res.data
res = test_client.get("/foobar2/", "http://localhost:5000")
res.status_code.should.equal(200)
res.data.should.contain(b"ListBucketResult")
assert res.status_code == 200
assert b"ListBucketResult" in res.data
res = test_client.get("/missing-bucket", "http://localhost:5000")
res.status_code.should.equal(404)
assert res.status_code == 404
res = test_client.put("/foobar/bar", "http://localhost:5000", data="test value")
res.status_code.should.equal(200)
assert res.status_code == 200
res = test_client.get("/foobar/bar", "http://localhost:5000")
res.status_code.should.equal(200)
res.data.should.equal(b"test value")
assert res.status_code == 200
assert res.data == b"test value"
def test_s3_server_post_to_bucket():
test_client = authenticated_client()
res = test_client.put("/foobar2", "http://localhost:5000/")
res.status_code.should.equal(200)
assert res.status_code == 200
test_client.post(
"/foobar2",
@ -77,30 +72,30 @@ def test_s3_server_post_to_bucket():
)
res = test_client.get("/foobar2/the-key", "http://localhost:5000/")
res.status_code.should.equal(200)
res.data.should.equal(b"nothing")
assert res.status_code == 200
assert res.data == b"nothing"
def test_s3_server_put_ipv6():
test_client = authenticated_client()
res = test_client.put("/foobar2", "http://[::]:5000/")
res.status_code.should.equal(200)
assert res.status_code == 200
test_client.post(
"/foobar2", "https://[::]:5000/", data={"key": "the-key", "file": "nothing"}
)
res = test_client.get("/foobar2/the-key", "http://[::]:5000/")
res.status_code.should.equal(200)
res.data.should.equal(b"nothing")
assert res.status_code == 200
assert res.data == b"nothing"
def test_s3_server_put_ipv4():
test_client = authenticated_client()
res = test_client.put("/foobar2", "http://127.0.0.1:5000/")
res.status_code.should.equal(200)
assert res.status_code == 200
test_client.post(
"/foobar2",
@ -109,5 +104,5 @@ def test_s3_server_put_ipv4():
)
res = test_client.get("/foobar2/the-key", "http://127.0.0.1:5000/")
res.status_code.should.equal(200)
res.data.should.equal(b"nothing")
assert res.status_code == 200
assert res.data == b"nothing"