Resolve some more tests
This commit is contained in:
		| @@ -3,6 +3,7 @@ import os | ||||
|  | ||||
| import pytest | ||||
|  | ||||
| from sanic import Sanic | ||||
| from sanic.blueprints import Blueprint | ||||
|  | ||||
|  | ||||
| @@ -26,9 +27,15 @@ def get_file_content(static_file_directory, file_name): | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize( | ||||
|     "file_name", ["test.file", "decode me.txt", "python.png"] | ||||
|     "file_name", | ||||
|     [ | ||||
|         "test.file", | ||||
|         "decode me.txt", | ||||
|         "python.png", | ||||
|     ], | ||||
| ) | ||||
| def test_static_file(app, static_file_directory, file_name): | ||||
| def test_static_file(static_file_directory, file_name): | ||||
|     app = Sanic("qq") | ||||
|     app.static( | ||||
|         "/testing.file", get_file_path(static_file_directory, file_name) | ||||
|     ) | ||||
| @@ -38,6 +45,8 @@ def test_static_file(app, static_file_directory, file_name): | ||||
|         name="testing_file", | ||||
|     ) | ||||
|  | ||||
|     app.router.finalize() | ||||
|  | ||||
|     uri = app.url_for("static") | ||||
|     uri2 = app.url_for("static", filename="any") | ||||
|     uri3 = app.url_for("static", name="static", filename="any") | ||||
| @@ -46,10 +55,14 @@ def test_static_file(app, static_file_directory, file_name): | ||||
|     assert uri == uri2 | ||||
|     assert uri2 == uri3 | ||||
|  | ||||
|     app.router.reset() | ||||
|  | ||||
|     request, response = app.test_client.get(uri) | ||||
|     assert response.status == 200 | ||||
|     assert response.body == get_file_content(static_file_directory, file_name) | ||||
|  | ||||
|     app.router.reset() | ||||
|  | ||||
|     bp = Blueprint("test_bp_static", url_prefix="/bp") | ||||
|  | ||||
|     bp.static("/testing.file", get_file_path(static_file_directory, file_name)) | ||||
| @@ -61,19 +74,14 @@ def test_static_file(app, static_file_directory, file_name): | ||||
|  | ||||
|     app.blueprint(bp) | ||||
|  | ||||
|     uri = app.url_for("static", name="test_bp_static.static") | ||||
|     uri2 = app.url_for("static", name="test_bp_static.static", filename="any") | ||||
|     uri3 = app.url_for("test_bp_static.static") | ||||
|     uri4 = app.url_for("test_bp_static.static", name="any") | ||||
|     uri5 = app.url_for("test_bp_static.static", filename="any") | ||||
|     uri6 = app.url_for("test_bp_static.static", name="any", filename="any") | ||||
|     uris = [ | ||||
|         app.url_for("static", name="test_bp_static.static"), | ||||
|         app.url_for("static", name="test_bp_static.static", filename="any"), | ||||
|         app.url_for("test_bp_static.static"), | ||||
|         app.url_for("test_bp_static.static", filename="any"), | ||||
|     ] | ||||
|  | ||||
|     assert uri == "/bp/testing.file" | ||||
|     assert uri == uri2 | ||||
|     assert uri2 == uri3 | ||||
|     assert uri3 == uri4 | ||||
|     assert uri4 == uri5 | ||||
|     assert uri5 == uri6 | ||||
|     assert all(uri == "/bp/testing.file" for uri in uris) | ||||
|  | ||||
|     request, response = app.test_client.get(uri) | ||||
|     assert response.status == 200 | ||||
| @@ -112,7 +120,9 @@ def test_static_file(app, static_file_directory, file_name): | ||||
|  | ||||
| @pytest.mark.parametrize("file_name", ["test.file", "decode me.txt"]) | ||||
| @pytest.mark.parametrize("base_uri", ["/static", "", "/dir"]) | ||||
| def test_static_directory(app, file_name, base_uri, static_file_directory): | ||||
| def test_static_directory(file_name, base_uri, static_file_directory): | ||||
|     app = Sanic("base") | ||||
|  | ||||
|     app.static(base_uri, static_file_directory) | ||||
|     base_uri2 = base_uri + "/2" | ||||
|     app.static(base_uri2, static_file_directory, name="uploads") | ||||
| @@ -141,6 +151,8 @@ def test_static_directory(app, file_name, base_uri, static_file_directory): | ||||
|  | ||||
|     bp.static(base_uri, static_file_directory) | ||||
|     bp.static(base_uri2, static_file_directory, name="uploads") | ||||
|  | ||||
|     app.router.reset() | ||||
|     app.blueprint(bp) | ||||
|  | ||||
|     uri = app.url_for( | ||||
| @@ -169,7 +181,8 @@ def test_static_directory(app, file_name, base_uri, static_file_directory): | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("file_name", ["test.file", "decode me.txt"]) | ||||
| def test_static_head_request(app, file_name, static_file_directory): | ||||
| def test_static_head_request(file_name, static_file_directory): | ||||
|     app = Sanic("base") | ||||
|     app.static( | ||||
|         "/testing.file", | ||||
|         get_file_path(static_file_directory, file_name), | ||||
| @@ -214,7 +227,8 @@ def test_static_head_request(app, file_name, static_file_directory): | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("file_name", ["test.file", "decode me.txt"]) | ||||
| def test_static_content_range_correct(app, file_name, static_file_directory): | ||||
| def test_static_content_range_correct(file_name, static_file_directory): | ||||
|     app = Sanic("base") | ||||
|     app.static( | ||||
|         "/testing.file", | ||||
|         get_file_path(static_file_directory, file_name), | ||||
| @@ -252,11 +266,6 @@ def test_static_content_range_correct(app, file_name, static_file_directory): | ||||
|         "static", name="test_bp_static.static", filename="any" | ||||
|     ) | ||||
|     assert uri == app.url_for("test_bp_static.static") | ||||
|     assert uri == app.url_for("test_bp_static.static", name="any") | ||||
|     assert uri == app.url_for("test_bp_static.static", filename="any") | ||||
|     assert uri == app.url_for( | ||||
|         "test_bp_static.static", name="any", filename="any" | ||||
|     ) | ||||
|  | ||||
|     request, response = app.test_client.get(uri, headers=headers) | ||||
|     assert response.status == 206 | ||||
| @@ -270,7 +279,8 @@ def test_static_content_range_correct(app, file_name, static_file_directory): | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("file_name", ["test.file", "decode me.txt"]) | ||||
| def test_static_content_range_front(app, file_name, static_file_directory): | ||||
| def test_static_content_range_front(file_name, static_file_directory): | ||||
|     app = Sanic("base") | ||||
|     app.static( | ||||
|         "/testing.file", | ||||
|         get_file_path(static_file_directory, file_name), | ||||
| @@ -308,11 +318,7 @@ def test_static_content_range_front(app, file_name, static_file_directory): | ||||
|         "static", name="test_bp_static.static", filename="any" | ||||
|     ) | ||||
|     assert uri == app.url_for("test_bp_static.static") | ||||
|     assert uri == app.url_for("test_bp_static.static", name="any") | ||||
|     assert uri == app.url_for("test_bp_static.static", filename="any") | ||||
|     assert uri == app.url_for( | ||||
|         "test_bp_static.static", name="any", filename="any" | ||||
|     ) | ||||
|  | ||||
|     request, response = app.test_client.get(uri, headers=headers) | ||||
|     assert response.status == 206 | ||||
| @@ -326,7 +332,8 @@ def test_static_content_range_front(app, file_name, static_file_directory): | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("file_name", ["test.file", "decode me.txt"]) | ||||
| def test_static_content_range_back(app, file_name, static_file_directory): | ||||
| def test_static_content_range_back(file_name, static_file_directory): | ||||
|     app = Sanic("base") | ||||
|     app.static( | ||||
|         "/testing.file", | ||||
|         get_file_path(static_file_directory, file_name), | ||||
| @@ -364,11 +371,7 @@ def test_static_content_range_back(app, file_name, static_file_directory): | ||||
|         "static", name="test_bp_static.static", filename="any" | ||||
|     ) | ||||
|     assert uri == app.url_for("test_bp_static.static") | ||||
|     assert uri == app.url_for("test_bp_static.static", name="any") | ||||
|     assert uri == app.url_for("test_bp_static.static", filename="any") | ||||
|     assert uri == app.url_for( | ||||
|         "test_bp_static.static", name="any", filename="any" | ||||
|     ) | ||||
|  | ||||
|     request, response = app.test_client.get(uri, headers=headers) | ||||
|     assert response.status == 206 | ||||
| @@ -382,7 +385,8 @@ def test_static_content_range_back(app, file_name, static_file_directory): | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("file_name", ["test.file", "decode me.txt"]) | ||||
| def test_static_content_range_empty(app, file_name, static_file_directory): | ||||
| def test_static_content_range_empty(file_name, static_file_directory): | ||||
|     app = Sanic("base") | ||||
|     app.static( | ||||
|         "/testing.file", | ||||
|         get_file_path(static_file_directory, file_name), | ||||
| @@ -420,11 +424,7 @@ def test_static_content_range_empty(app, file_name, static_file_directory): | ||||
|         "static", name="test_bp_static.static", filename="any" | ||||
|     ) | ||||
|     assert uri == app.url_for("test_bp_static.static") | ||||
|     assert uri == app.url_for("test_bp_static.static", name="any") | ||||
|     assert uri == app.url_for("test_bp_static.static", filename="any") | ||||
|     assert uri == app.url_for( | ||||
|         "test_bp_static.static", name="any", filename="any" | ||||
|     ) | ||||
|  | ||||
|     request, response = app.test_client.get(uri) | ||||
|     assert response.status == 200 | ||||
| @@ -440,6 +440,7 @@ def test_static_content_range_empty(app, file_name, static_file_directory): | ||||
|  | ||||
| @pytest.mark.parametrize("file_name", ["test.file", "decode me.txt"]) | ||||
| def test_static_content_range_error(app, file_name, static_file_directory): | ||||
|     app = Sanic("base") | ||||
|     app.static( | ||||
|         "/testing.file", | ||||
|         get_file_path(static_file_directory, file_name), | ||||
| @@ -475,11 +476,7 @@ def test_static_content_range_error(app, file_name, static_file_directory): | ||||
|         "static", name="test_bp_static.static", filename="any" | ||||
|     ) | ||||
|     assert uri == app.url_for("test_bp_static.static") | ||||
|     assert uri == app.url_for("test_bp_static.static", name="any") | ||||
|     assert uri == app.url_for("test_bp_static.static", filename="any") | ||||
|     assert uri == app.url_for( | ||||
|         "test_bp_static.static", name="any", filename="any" | ||||
|     ) | ||||
|  | ||||
|     request, response = app.test_client.get(uri, headers=headers) | ||||
|     assert response.status == 416 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Adam Hopkins
					Adam Hopkins