Skip to content
Draft
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
1 change: 1 addition & 0 deletions .azdo/ci-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ steps:
python -m pip install ./dist/microsoft_agents_hosting_fastapi*.whl
python -m pip install ./dist/microsoft_agents_storage_blob*.whl
python -m pip install ./dist/microsoft_agents_storage_cosmos*.whl
python -m pip install ./dist/microsoft_agents_testing*.whl
displayName: 'Install wheels'

- script: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
python -m pip install ./dist/microsoft_agents_hosting_fastapi*.whl
python -m pip install ./dist/microsoft_agents_storage_blob*.whl
python -m pip install ./dist/microsoft_agents_storage_cosmos*.whl
python -m pip install ./dist/microsoft_agents_testing*.whl
- name: Test with pytest
run: |
pytest -W "ignore:SelectableGroups dict interface is deprecated. Use select.:DeprecationWarning"
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from abc import abstractmethod
from typing import Protocol, Callable, Awaitable, Optional

from typing_extensions import Self

Comment thread
rodrigobr-msft marked this conversation as resolved.
from .turn_context_protocol import TurnContextProtocol
from microsoft_agents.activity import (
Activity,
Expand Down Expand Up @@ -35,7 +37,7 @@ async def delete_activity(
pass

@abstractmethod
def use(self, middleware: object) -> "ChannelAdapterProtocol":
def use(self, middleware: object) -> Self:
pass

@abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

"""Models for token status operations."""

from typing import Optional
from pydantic import Field

from .agents_model import AgentsModel
from ._type_aliases import NonEmptyString

Expand All @@ -15,18 +12,16 @@ class TokenStatus(AgentsModel):
The status of a user token.

:param channel_id: The channelId of the token status pertains to.
:type channel_id: str
:type channel_id: str | None
:param connection_name: The name of the connection the token status pertains to.
:type connection_name: str
:type connection_name: str | None
:param has_token: True if a token is stored for this ConnectionName.
:type has_token: bool
:type has_token: bool | None
:param service_provider_display_name: The display name of the service provider for which this Token belongs to.
:type service_provider_display_name: str
:type service_provider_display_name: str | None
"""

channel_id: Optional[NonEmptyString] = Field(None, alias="channelId")
connection_name: Optional[NonEmptyString] = Field(None, alias="connectionName")
has_token: Optional[bool] = Field(None, alias="hasToken")
service_provider_display_name: Optional[NonEmptyString] = Field(
None, alias="serviceProviderDisplayName"
)
channel_id: NonEmptyString | None = None
connection_name: NonEmptyString | None = None
has_token: bool | None = None
service_provider_display_name: NonEmptyString | None = None
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from __future__ import annotations

from typing_extensions import Self

Comment thread
rodrigobr-msft marked this conversation as resolved.
from abc import ABC, abstractmethod
from collections.abc import Callable
from typing import Awaitable
Expand Down Expand Up @@ -78,7 +80,7 @@ async def delete_activity(
"""
raise NotImplementedError()

def use(self, middleware: Middleware) -> ChannelAdapter:
def use(self, middleware: Middleware) -> Self:
"""
Registers a middleware handler with the adapter.

Expand Down
21 changes: 21 additions & 0 deletions libraries/microsoft-agents-testing/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
1 change: 1 addition & 0 deletions libraries/microsoft-agents-testing/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from .auth import MockUserTokenClient
from .test_adapter import TestAdapter
from .test_flow import TestFlow

__all__ = ["MockUserTokenClient", "TestAdapter", "TestFlow"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

_SERVICE_URL = "https://test.com"

_CONV_ID = "convo1"
_CONV_NAME = "Conversation 1"

_BOT_ID = "bot"
_BOT_NAME = "Bot"

_USER_ID = "user1"
_USER_NAME = "User 1"

_LOCALE = "en-US"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from .mock_user_token_client import MockUserTokenClient

__all__ = [
"MockUserTokenClient",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from dataclasses import dataclass
from typing import Any


@dataclass(frozen=True, eq=False)
class UserTokenKey:
"""A key that uniquely identifies a user token in the mock client."""

connection_name: str
user_id: str
channel_id: str

def __eq__(self, other: Any) -> bool:
return (
isinstance(other, UserTokenKey)
and self.connection_name.casefold() == other.connection_name.casefold()
and self.user_id.casefold() == other.user_id.casefold()
and self.channel_id.casefold() == other.channel_id.casefold()
)

def __hash__(self) -> int:
return hash(
(
self.connection_name.casefold(),
self.user_id.casefold(),
self.channel_id.casefold(),
)
)


@dataclass(frozen=True, eq=False)
class ExchangeableTokenKey(UserTokenKey):
"""A key that uniquely identifies an exchangeable token in the mock client."""

exchangeable_item: str

def __eq__(self, other):
return (
super().__eq__(other)
and isinstance(other, ExchangeableTokenKey)
and self.exchangeable_item.casefold() == other.exchangeable_item.casefold()
)

def __hash__(self) -> int:
return hash((super().__hash__(), self.exchangeable_item.casefold()))


@dataclass(frozen=True)
class TokenMagicCode:
"""A class that represents a magic code for a token."""

key: UserTokenKey
magic_code: str
user_token: str
Loading
Loading