-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add invoice_payload filtering
#4005
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
Bibo-Joshi
merged 14 commits into
python-telegram-bot:master
from
aelkheir:invoice-payload-filtering
Jan 2, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
96715df
Add 'SuccessfulPayment` message filter
aelkheir 1259f69
Add `pattern` arg to `PreCheckoutQueryHandler`
aelkheir 954167d
Disallow types `callable`, `type` in `PreCheckoutQueryHandler.pattern`
aelkheir 576f9d5
Add `'SuccessfulPayment'` to `ext.filters.__all__`
aelkheir e7153cd
Add tests for `filters.SuccessfulPayment` and `PreCheckoutQueryHandler`
aelkheir 5324ab1
Fix tests of `_precheckoutqueryhandler.py`
aelkheir 3c8b054
Fix docstring of `telegram.ext.filters.SuccessfulPayment`
aelkheir 84fd314
Fix: import `Pattern` from typing for python backward compatibility
aelkheir 75b05fa
Fix docstring of arg `PreCheckoutQueryHandler.pattern`
aelkheir c21e86d
Merge remote-tracking branch 'upstream/master' into invoice-payload-f…
aelkheir 25276a9
Apply code review suggestions
aelkheir f093609
Merge remote-tracking branch 'upstream/master' into invoice-payload-f…
aelkheir 8b677e1
Improve typing
aelkheir 07492ea
Merge branch 'master' into invoice-payload-filtering
Bibo-Joshi 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| # You should have received a copy of the GNU Lesser Public License | ||
| # along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
| import asyncio | ||
| import re | ||
|
|
||
| import pytest | ||
|
|
||
|
|
@@ -69,12 +70,15 @@ def false_update(request): | |
|
|
||
| @pytest.fixture(scope="class") | ||
| def pre_checkout_query(): | ||
| return Update( | ||
| update = Update( | ||
| 1, | ||
| pre_checkout_query=PreCheckoutQuery( | ||
| "id", User(1, "test user", False), "EUR", 223, "invoice_payload" | ||
| ), | ||
| ) | ||
| update._unfreeze() | ||
| update.pre_checkout_query._unfreeze() | ||
| return update | ||
|
|
||
|
|
||
| class TestPreCheckoutQueryHandler: | ||
|
|
@@ -103,6 +107,23 @@ async def callback(self, update, context): | |
| and isinstance(update.pre_checkout_query, PreCheckoutQuery) | ||
| ) | ||
|
|
||
| def test_with_pattern(self, pre_checkout_query): | ||
| handler = PreCheckoutQueryHandler(self.callback, pattern=".*voice.*") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please also test passing a compiled pattern :) |
||
|
|
||
| assert handler.check_update(pre_checkout_query) | ||
|
|
||
| pre_checkout_query.pre_checkout_query.invoice_payload = "nothing here" | ||
| assert not handler.check_update(pre_checkout_query) | ||
|
|
||
| def test_with_compiled_pattern(self, pre_checkout_query): | ||
|
Bibo-Joshi marked this conversation as resolved.
|
||
| handler = PreCheckoutQueryHandler(self.callback, pattern=re.compile(r".*payload")) | ||
|
|
||
| pre_checkout_query.pre_checkout_query.invoice_payload = "invoice_payload" | ||
| assert handler.check_update(pre_checkout_query) | ||
|
|
||
| pre_checkout_query.pre_checkout_query.invoice_payload = "nothing here" | ||
| assert not handler.check_update(pre_checkout_query) | ||
|
|
||
| def test_other_update_types(self, false_update): | ||
| handler = PreCheckoutQueryHandler(self.callback) | ||
| assert not handler.check_update(false_update) | ||
|
|
||
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.