-
Notifications
You must be signed in to change notification settings - Fork 6
Add signin/failure invoke activity support #206
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
Merged
+116
−5
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
df4206b
Initial plan
Copilot 4c1e716
Add signin/failure invoke activity support
Copilot ce7c1e7
Remove trailing comment marker from failure.py
Copilot cc7ba6f
Address PR feedback: reorder __all__, refactor tests to use fixtures
Copilot 399fcd3
Refactor test_fixtures to use pytest parameterization
Copilot d17b7d2
Remove test_signin_failure_activity.py file
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/api/src/microsoft/teams/api/activities/invoke/sign_in/failure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| from typing import Literal | ||
|
|
||
| from ....models import SignInFailure | ||
| from ...invoke_activity import InvokeActivity | ||
|
|
||
|
|
||
| class SignInFailureInvokeActivity(InvokeActivity): | ||
| """ | ||
| Sign-in failure invoke activity for signin/failure invokes. | ||
|
|
||
| Represents an invoke activity when a sign-in operation fails | ||
| during the authentication process. | ||
| """ | ||
|
|
||
| name: Literal["signin/failure"] = "signin/failure" | ||
| """The name of the operation associated with an invoke or event activity.""" | ||
|
|
||
| value: SignInFailure | ||
| """A value that is associated with the activity.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/api/src/microsoft/teams/api/models/sign_in/failure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from ..custom_base_model import CustomBaseModel | ||
|
|
||
|
|
||
| class SignInFailure(CustomBaseModel): | ||
| """ | ||
| Sign-in failure information. | ||
|
|
||
| Represents the details of a sign-in failure including | ||
| an error code and message. | ||
| """ | ||
|
|
||
| code: Optional[str] = None | ||
| """ | ||
| The error code for the sign-in failure | ||
| """ | ||
| message: Optional[str] = None | ||
| """ | ||
| The error message for the sign-in failure | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| import pytest | ||
| from microsoft.teams.api.activities.invoke.sign_in import SignInFailureInvokeActivity | ||
| from microsoft.teams.api.models import Account, ConversationAccount, SignInFailure | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| class TestSignInFailureInvokeActivity: | ||
| """Unit tests for SignInFailureInvokeActivity class.""" | ||
|
|
||
| def test_should_create_signin_failure_activity(self) -> None: | ||
heyitsaamir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Test creating a signin failure activity with code and message.""" | ||
| failure = SignInFailure(code="resourcematchfailed", message="Resource match failed") | ||
| user = Account(id="user-1", name="Test User") | ||
| bot = Account(id="bot-1", name="Test Bot") | ||
| conversation = ConversationAccount(id="conv-1") | ||
|
|
||
| activity = SignInFailureInvokeActivity( | ||
| id="activity-1", | ||
| name="signin/failure", | ||
| value=failure, | ||
| from_=user, | ||
| conversation=conversation, | ||
| recipient=bot, | ||
| ) | ||
|
|
||
| assert activity.name == "signin/failure" | ||
| assert activity.type == "invoke" | ||
| assert activity.value.code == "resourcematchfailed" | ||
| assert activity.value.message == "Resource match failed" | ||
|
|
||
| def test_should_deserialize_signin_failure_activity(self) -> None: | ||
heyitsaamir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Test deserializing a signin failure activity from JSON-like dict.""" | ||
| activity_dict = { | ||
| "id": "activity-1", | ||
| "name": "signin/failure", | ||
| "type": "invoke", | ||
| "from": {"id": "user-1", "name": "Test User"}, | ||
| "conversation": {"id": "conv-1"}, | ||
| "recipient": {"id": "bot-1", "name": "Test Bot"}, | ||
| "value": {"code": "resourcematchfailed", "message": "Resource match failed"}, | ||
| } | ||
|
|
||
| activity = SignInFailureInvokeActivity.model_validate(activity_dict) | ||
|
|
||
| assert activity.name == "signin/failure" | ||
| assert activity.type == "invoke" | ||
| assert activity.value.code == "resourcematchfailed" | ||
| assert activity.value.message == "Resource match failed" | ||
|
|
||
| def test_should_serialize_signin_failure_activity(self) -> None: | ||
heyitsaamir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Test serializing a signin failure activity to dict.""" | ||
| failure = SignInFailure(code="unauthorized", message="Unauthorized access") | ||
| user = Account(id="user-1", name="Test User") | ||
| bot = Account(id="bot-1", name="Test Bot") | ||
| conversation = ConversationAccount(id="conv-1") | ||
|
|
||
| activity = SignInFailureInvokeActivity( | ||
| id="activity-1", | ||
| name="signin/failure", | ||
| value=failure, | ||
| from_=user, | ||
| conversation=conversation, | ||
| recipient=bot, | ||
| ) | ||
|
|
||
| serialized = activity.model_dump() | ||
|
|
||
| assert serialized["name"] == "signin/failure" | ||
| assert serialized["type"] == "invoke" | ||
| assert serialized["value"]["code"] == "unauthorized" | ||
| assert serialized["value"]["message"] == "Unauthorized access" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.