-
Notifications
You must be signed in to change notification settings - Fork 14
[Feature] Add pytest-cov for code coverage reporting #244
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
Draft
rajan-chari
wants to merge
2
commits into
main
Choose a base branch
from
feature/add-pytest-cov
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
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
112 changes: 112 additions & 0 deletions
112
packages/api/tests/unit/test_conversation_update_directline.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,112 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
|
|
||
| Tests for ConversationUpdateActivity with Direct Line API 3.0 compatibility. | ||
| Issue #239: Direct Line sends conversationUpdate without channelData field. | ||
| """ | ||
|
|
||
| import pytest | ||
| from microsoft_teams.api.activities import ActivityTypeAdapter, ConversationUpdateActivity | ||
| from microsoft_teams.api.activities.conversation import ConversationUpdateActivityInput | ||
| from microsoft_teams.api.models import Account, ConversationAccount | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| class TestConversationUpdateDirectLine: | ||
| """Test ConversationUpdateActivity compatibility with Direct Line API 3.0.""" | ||
|
|
||
| def test_parse_conversation_update_without_channel_data(self) -> None: | ||
| """Test that ConversationUpdateActivity can be parsed without channelData field. | ||
|
|
||
| This simulates the payload sent by Direct Line API 3.0 when starting a conversation. | ||
| Direct Line automatically sends conversationUpdate activities without channelData, | ||
| which should be accepted by the SDK. | ||
| """ | ||
| # Payload simulating Direct Line conversationUpdate (no channelData) | ||
| payload = { | ||
| "type": "conversationUpdate", | ||
| "id": "Bh0ETfRaC25", | ||
| "timestamp": "2025-12-22T11:29:37.3485747Z", | ||
| "serviceUrl": "https://directline.botframework.com/", | ||
| "channelId": "directline", | ||
| "from": { | ||
| "id": "dl_aba7a98ada0ee99e7d54af5df8e00440", | ||
| "name": "Bot Tester" | ||
| }, | ||
| "conversation": { | ||
| "id": "conv123" | ||
| }, | ||
| "recipient": { | ||
| "id": "bot-id", | ||
| "name": "Test Bot" | ||
| }, | ||
| "membersAdded": [ | ||
| { | ||
| "id": "user123", | ||
| "name": "Test User" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| # This should NOT raise a validation error | ||
| activity = ActivityTypeAdapter.validate_python(payload) | ||
|
|
||
| # Verify it's a ConversationUpdateActivity | ||
| assert isinstance(activity, ConversationUpdateActivity) | ||
| assert activity.type == "conversationUpdate" | ||
| assert activity.channel_id == "directline" | ||
| assert activity.channel_data is None | ||
| assert activity.members_added is not None | ||
| assert len(activity.members_added) == 1 | ||
| assert activity.members_added[0].id == "user123" | ||
|
|
||
| def test_parse_conversation_update_with_channel_data(self) -> None: | ||
| """Test that ConversationUpdateActivity still works with channelData (Teams behavior).""" | ||
| payload = { | ||
| "type": "conversationUpdate", | ||
| "id": "test-id", | ||
| "timestamp": "2025-12-22T11:29:37.3485747Z", | ||
| "serviceUrl": "https://smba.trafficmanager.net/teams/", | ||
| "channelId": "msteams", | ||
| "from": { | ||
| "id": "bot-id", | ||
| "name": "Test Bot" | ||
| }, | ||
| "conversation": { | ||
| "id": "conv123" | ||
| }, | ||
| "recipient": { | ||
| "id": "user-id", | ||
| "name": "Test User" | ||
| }, | ||
| "channelData": { | ||
| "eventType": "channelCreated", | ||
| "tenant": { | ||
| "id": "tenant-id" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| activity = ActivityTypeAdapter.validate_python(payload) | ||
|
|
||
| assert isinstance(activity, ConversationUpdateActivity) | ||
| assert activity.type == "conversationUpdate" | ||
| assert activity.channel_id == "msteams" | ||
| assert activity.channel_data is not None | ||
| assert activity.channel_data.event_type == "channelCreated" | ||
|
|
||
| def test_conversation_update_input_without_channel_data(self) -> None: | ||
| """Test creating ConversationUpdateActivityInput without channelData.""" | ||
| # Create activity input without channel_data | ||
| activity = ConversationUpdateActivityInput( | ||
| from_=Account(id="user-id", name="User"), | ||
| conversation=ConversationAccount(id="conv-id"), | ||
| recipient=Account(id="bot-id", name="Bot"), | ||
| members_added=[Account(id="new-user", name="New User")] | ||
| ) | ||
|
|
||
| assert activity.type == "conversationUpdate" | ||
| assert activity.channel_data is None | ||
| assert activity.members_added is not None | ||
| assert len(activity.members_added) == 1 |
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
100 changes: 100 additions & 0 deletions
100
packages/apps/tests/test_conversation_update_routing.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,100 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
|
|
||
| Tests for ConversationUpdateActivity routing with optional channelData. | ||
| Issue #239: Ensure selectors handle None channelData gracefully. | ||
| """ | ||
|
|
||
| import pytest | ||
| from microsoft_teams.api.activities import ConversationUpdateActivity | ||
| from microsoft_teams.api.models import Account, ConversationAccount | ||
| from microsoft_teams.apps.routing.activity_route_configs import ACTIVITY_ROUTES | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| class TestConversationUpdateRouting: | ||
| """Test activity routing for ConversationUpdateActivity with optional channelData.""" | ||
|
|
||
| @pytest.fixture | ||
| def conversation_update_without_channel_data(self) -> ConversationUpdateActivity: | ||
| """Create a ConversationUpdateActivity without channelData (simulates Direct Line).""" | ||
| return ConversationUpdateActivity( | ||
| type="conversationUpdate", | ||
| id="test-id", | ||
| channel_id="directline", | ||
| service_url="https://directline.botframework.com/", | ||
| from_=Account(id="user-id", name="User"), | ||
| conversation=ConversationAccount(id="conv-id"), | ||
| recipient=Account(id="bot-id", name="Bot"), | ||
| members_added=[Account(id="new-user", name="New User")], | ||
| channel_data=None | ||
| ) | ||
|
|
||
| @pytest.fixture | ||
| def conversation_update_with_channel_data(self) -> ConversationUpdateActivity: | ||
| """Create a ConversationUpdateActivity with channelData (simulates Teams).""" | ||
| from microsoft_teams.api.activities.conversation import ConversationChannelData | ||
|
|
||
| return ConversationUpdateActivity( | ||
| type="conversationUpdate", | ||
| id="test-id", | ||
| channel_id="msteams", | ||
| service_url="https://smba.trafficmanager.net/teams/", | ||
| from_=Account(id="user-id", name="User"), | ||
| conversation=ConversationAccount(id="conv-id"), | ||
| recipient=Account(id="bot-id", name="Bot"), | ||
| channel_data=ConversationChannelData(event_type="channelCreated") | ||
| ) | ||
|
|
||
| def test_conversation_update_selector_matches_without_channel_data( | ||
| self, conversation_update_without_channel_data: ConversationUpdateActivity | ||
| ) -> None: | ||
| """Test that conversation_update selector matches activities without channelData.""" | ||
| config = ACTIVITY_ROUTES["conversation_update"] | ||
| assert config.selector(conversation_update_without_channel_data) is True | ||
|
|
||
| def test_conversation_update_selector_matches_with_channel_data( | ||
| self, conversation_update_with_channel_data: ConversationUpdateActivity | ||
| ) -> None: | ||
| """Test that conversation_update selector still matches activities with channelData.""" | ||
| config = ACTIVITY_ROUTES["conversation_update"] | ||
| assert config.selector(conversation_update_with_channel_data) is True | ||
|
|
||
| def test_channel_created_selector_rejects_without_channel_data( | ||
| self, conversation_update_without_channel_data: ConversationUpdateActivity | ||
| ) -> None: | ||
| """Test that event-specific selectors reject activities without channelData.""" | ||
| config = ACTIVITY_ROUTES["channel_created"] | ||
| # Should not match because channel_data is None | ||
| assert config.selector(conversation_update_without_channel_data) is False | ||
|
|
||
| def test_channel_created_selector_matches_with_correct_event( | ||
| self, conversation_update_with_channel_data: ConversationUpdateActivity | ||
| ) -> None: | ||
| """Test that event-specific selectors match when channelData has correct event_type.""" | ||
| config = ACTIVITY_ROUTES["channel_created"] | ||
| assert config.selector(conversation_update_with_channel_data) is True | ||
|
|
||
| def test_all_conversation_event_selectors_handle_none_channel_data( | ||
| self, conversation_update_without_channel_data: ConversationUpdateActivity | ||
| ) -> None: | ||
| """Test that all conversation event selectors gracefully handle None channelData.""" | ||
| # These selectors should all return False (not match) without raising errors | ||
| event_routes = [ | ||
| "channel_created", | ||
| "channel_deleted", | ||
| "channel_renamed", | ||
| "channel_restored", | ||
| "team_archived", | ||
| "team_deleted", | ||
| "team_hard_deleted", | ||
| "team_renamed", | ||
| "team_restored", | ||
| "team_unarchived", | ||
| ] | ||
|
|
||
| for route_name in event_routes: | ||
| config = ACTIVITY_ROUTES[route_name] | ||
| # Should not match, but should not raise an error | ||
| assert config.selector(conversation_update_without_channel_data) is False |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern for excluding
if __name__ == \"__main__\":blocks is incorrect. The pattern uses literal dots instead of escaped quotes, which won't match the actual Python idiom. Change.__main__.to\"__main__\"or'__main__'.