Skip to content

Commit

Permalink
Extended test suite to meet required coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
iAndriy committed Dec 19, 2023
1 parent c3fa036 commit 21f8ac2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,15 @@ def test_stop_trigger_terminate(app: Sanic):

app.stop(unregister=False)
app.multiplexer.terminate.assert_called_once()


def test_refresh_pass_passthru_data_to_new_instance(app: Sanic):
# arrange
passthru = {
'_inspector': 2,
'config': {'TOUCHUP': 23}
}
app = app.refresh(passthru)

assert app.inspector == 2
assert app.config.TOUCHUP == 23
10 changes: 10 additions & 0 deletions tests/test_blueprint_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ def test_bp_group_indexing(app: Sanic):
with raises(expected_exception=IndexError):
_ = group[3]

def test_bp_group_set_item_by_index(app: Sanic):
blueprint_1 = Blueprint("blueprint_1", url_prefix="/bp1")
blueprint_2 = Blueprint("blueprint_2", url_prefix="/bp2")

group = Blueprint.group(blueprint_1, blueprint_2)
group[0] = blueprint_2

assert group[0] == blueprint_2



def test_bp_group_with_additional_route_params(app: Sanic):
blueprint_1 = Blueprint("blueprint_1", url_prefix="/bp1")
Expand Down
40 changes: 40 additions & 0 deletions tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,3 +1112,43 @@ async def index(_):
app.router.finalize()

assert app.router.routes[0].path == "foo/"


def test_blueprint_copy_returns_blueprint_with_the_name_of_original_blueprint(
app: Sanic,
):
# arrange
bp = Blueprint("bp")

# act
actual = bp.copy("new_bp_name")

# assert
assert bp.name == actual.copied_from


def test_blueprint_copy_returns_blueprint_with_overwritten_properties(
app: Sanic,
):
# arrange
bp = Blueprint("bp")
to_override_attrs = expected = dict(
url_prefix="v2",
version="v2",
version_prefix="v2",
allow_route_overwrite=True,
strict_slashes=True,
)

# act
actual = bp.copy(
"new_bp_name",
**to_override_attrs,
)

# assert
assert all(
value == getattr(actual, key)
for key, value in expected.items()
if hasattr(actual, key)
)
4 changes: 2 additions & 2 deletions tests/test_websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from websockets.frames import CTRL_OPCODES, DATA_OPCODES, Frame, OP_TEXT
from websockets.frames import CTRL_OPCODES, DATA_OPCODES, OP_TEXT, Frame

from sanic.exceptions import ServerError
from sanic.server.websockets.frame import WebsocketFrameAssembler
Expand Down Expand Up @@ -210,7 +210,7 @@ async def test_ws_frame_put_message_complete(opcode):
@pytest.mark.asyncio
@pytest.mark.parametrize("opcode", DATA_OPCODES)
async def test_ws_frame_put_message_into_queue(opcode):
foo = 'foo' if (opcode == OP_TEXT) else b"foo"
foo = "foo" if (opcode == OP_TEXT) else b"foo"
assembler = WebsocketFrameAssembler(Mock())
assembler.chunks_queue = AsyncMock(spec=Queue)
assembler.message_fetched = AsyncMock()
Expand Down

0 comments on commit 21f8ac2

Please sign in to comment.