From eba9033cc9a2c85a75007b1a21e51464265fab59 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Sun, 24 Jan 2016 17:13:32 -0500 Subject: [PATCH] cleanup flask paths with trailing slashes. --- moto/core/utils.py | 4 ++++ .../test_bucket_path_server.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/moto/core/utils.py b/moto/core/utils.py index 65f0f457..c72cb643 100644 --- a/moto/core/utils.py +++ b/moto/core/utils.py @@ -74,6 +74,10 @@ def convert_regex_to_flask_path(url_path): return ''.format(match_pattern, match_name) url_path = re.sub("\(\?P<(.*?)>(.*?)\)", caller, url_path) + + if url_path.endswith("/?"): + # Flask does own handling of trailing slashes + url_path = url_path.rstrip("/?") return url_path diff --git a/tests/test_s3bucket_path/test_bucket_path_server.py b/tests/test_s3bucket_path/test_bucket_path_server.py index d639c4ce..4434c02f 100644 --- a/tests/test_s3bucket_path/test_bucket_path_server.py +++ b/tests/test_s3bucket_path/test_bucket_path_server.py @@ -21,23 +21,23 @@ def test_s3_server_bucket_create(): backend = server.create_backend_app("s3bucket_path") test_client = backend.test_client() - res = test_client.put('/foobar/', 'http://localhost:5000') + res = test_client.put('/foobar', 'http://localhost:5000') res.status_code.should.equal(200) res = test_client.get('/') res.data.should.contain(b'foobar') - res = test_client.get('/foobar/', 'http://localhost:5000') + res = test_client.get('/foobar', 'http://localhost:5000') res.status_code.should.equal(200) res.data.should.contain(b"ListBucketResult") - res = test_client.get('/missing-bucket/', 'http://localhost:5000') + res = test_client.get('/missing-bucket', 'http://localhost:5000') res.status_code.should.equal(404) - res = test_client.put('/foobar/bar/', 'http://localhost:5000', data='test value') + res = test_client.put('/foobar/bar', 'http://localhost:5000', data='test value') res.status_code.should.equal(200) - res = test_client.get('/foobar/bar/', 'http://localhost:5000') + res = test_client.get('/foobar/bar', 'http://localhost:5000') res.status_code.should.equal(200) res.data.should.equal(b"test value") @@ -46,14 +46,14 @@ def test_s3_server_post_to_bucket(): backend = server.create_backend_app("s3bucket_path") test_client = backend.test_client() - res = test_client.put('/foobar2/', 'http://localhost:5000/') + res = test_client.put('/foobar2', 'http://localhost:5000/') res.status_code.should.equal(200) - test_client.post('/foobar2/', "https://localhost:5000/", data={ + test_client.post('/foobar2', "https://localhost:5000/", data={ 'key': 'the-key', 'file': 'nothing' }) - res = test_client.get('/foobar2/the-key/', 'http://localhost:5000/') + res = test_client.get('/foobar2/the-key', 'http://localhost:5000/') res.status_code.should.equal(200) res.data.should.equal(b"nothing")