Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow для тестов #4

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ jobs:
[[ "$IS_WINDOWS" == "false" ]] && flags="$flags --redis redis://localhost:6379/0"
pytest $flags

- name: Upload coverage data
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
flags: unittests
name: py-${{ matrix.python-version }}-${{ matrix.os }}
fail_ci_if_error: true
# - name: Upload coverage data
# uses: codecov/codecov-action@v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: coverage.xml
# flags: unittests
# name: py-${{ matrix.python-version }}-${{ matrix.os }}
# fail_ci_if_error: true

pypy-tests:
strategy:
Expand Down
6 changes: 4 additions & 2 deletions aliceio/client/session/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def prepare_value( # noqa: C901
value: Any,
skill: Skill,
files: Dict[str, Any],
_dumps_json: bool = True,
_dumps_json: bool = False,
) -> Any:
"""Подготовка значения перед отправкой."""
if value is None:
Expand Down Expand Up @@ -162,7 +162,9 @@ def prepare_value( # noqa: C901
if isinstance(value, datetime.datetime):
return str(round(value.timestamp()))
if isinstance(value, Enum):
return self.prepare_value(value.value, skill=skill, files=files)
return self.prepare_value(
value.value, skill=skill, files=files, _dumps_json=True
)

if _dumps_json:
return self.json.dumps(value)
Expand Down
2 changes: 1 addition & 1 deletion aliceio/dispatcher/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async def _feed_webhook_update(
except Exception as e:
loggers.event.exception(
"Cause exception while process update "
"session=%s by skill id=%d\n%s: %s",
"session=%r by skill id=%r\n%s: %s",
update.session.session_id,
skill.id,
e.__class__.__name__,
Expand Down
2 changes: 1 addition & 1 deletion aliceio/dispatcher/middlewares/user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

EVENT_FROM_USER_KEY = "event_from_user"
EVENT_SESSION_KEY = "event_session"
EVENT_UPDATE_KEY = "update"
EVENT_UPDATE_KEY = "event_update"


class UserContextMiddleware(BaseMiddleware):
Expand Down
2 changes: 1 addition & 1 deletion aliceio/fsm/storage/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ async def get_data(
return {}
if isinstance(value, bytes):
value = value.decode("utf-8")
return cast(Dict[str, Any], self.json.dumps(value))
return cast(Dict[str, Any], self.json.loads(value))
8 changes: 8 additions & 0 deletions tests/test_dispatcher/test_middlewares/test_user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ async def test_call(self, update: Update) -> None:

assert data["event_session"] == 1
assert data["event_from_user"] == 2
assert data["event_update"] == update

data.clear()
await middleware(next_handler, update, data)

assert data["event_session"] == update.session
assert data["event_from_user"] == update.session.user
assert data["event_update"] == update

async def test_resolve_context(self) -> None:
user = User(user_id="42", access_token="24")
Expand Down
9 changes: 7 additions & 2 deletions tests/test_utils/test_mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextvars
import platform

import pytest

Expand Down Expand Up @@ -105,5 +106,9 @@ class MyClass(ContextInstanceMixin):

wrong_type_token = "wrong_type"

with pytest.raises(TypeError):
MyClass.reset_current(wrong_type_token)
if platform.python_implementation() == "PyPy":
with pytest.raises(AttributeError):
MyClass.reset_current(wrong_type_token)
else:
with pytest.raises(TypeError):
MyClass.reset_current(wrong_type_token)