diff --git a/.github/workflows/docs-linkcheck.yml b/.github/workflows/docs-linkcheck.yml index 82fafe3e5..f34fcc17d 100644 --- a/.github/workflows/docs-linkcheck.yml +++ b/.github/workflows/docs-linkcheck.yml @@ -10,7 +10,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - python-version: [3.9] + python-version: [3.10] os: [ubuntu-latest] fail-fast: False steps: diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml index bcd1794c4..8ebfd4888 100644 --- a/.github/workflows/release_pypi.yml +++ b/.github/workflows/release_pypi.yml @@ -1,17 +1,15 @@ name: Publish to PyPI on: - # Run on any tag - push: - tags: - - '**' - # manually trigger the workflow - for testing only + # manually trigger the workflow workflow_dispatch: jobs: build: name: Build Distribution runs-on: ubuntu-latest + outputs: + TAG: ${{ steps.get_tag.outputs.TAG }} steps: - uses: actions/checkout@v4 @@ -29,11 +27,15 @@ jobs: with: name: python-package-distributions path: dist/ + - name: Get Tag Name + id: get_tag + run: | + pip install . + TAG=$(python -c "from telegram import __version__; print(f'v{__version__}')") + echo "TAG=$TAG" >> $GITHUB_OUTPUT publish-to-pypi: name: Publish to PyPI - # only publish to PyPI on tag pushes - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') needs: - build runs-on: ubuntu-latest @@ -52,42 +54,11 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 - publish-to-test-pypi: - name: Publish to Test PyPI - needs: - - build - runs-on: ubuntu-latest - environment: - name: release_test_pypi - url: https://test.pypi.org/p/python-telegram-bot - permissions: - id-token: write # IMPORTANT: mandatory for trusted publishing - - steps: - - name: Download all the dists - uses: actions/download-artifact@v4 - with: - name: python-package-distributions - path: dist/ - - name: Publish to Test PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - repository-url: https://test.pypi.org/legacy/ - compute-signatures: name: Compute SHA1 Sums and Sign with Sigstore runs-on: ubuntu-latest needs: - publish-to-pypi - - publish-to-test-pypi - # run if either of the publishing jobs ran successfully - # see also: - # https://github.com/actions/runner/issues/491#issuecomment-850884422 - if: | - always() && ( - (needs.publish-to-pypi.result == 'success') || - (needs.publish-to-test-pypi.result == 'success') - ) permissions: id-token: write # IMPORTANT: mandatory for sigstore @@ -106,7 +77,7 @@ jobs: sha1sum $file > $file.sha1 done - name: Sign the dists with Sigstore - uses: sigstore/gh-action-sigstore-python@v2.1.1 + uses: sigstore/gh-action-sigstore-python@v3.0.0 with: inputs: >- ./dist/*.tar.gz @@ -120,13 +91,8 @@ jobs: github-release: name: Upload to GitHub Release needs: - - publish-to-pypi + - build - compute-signatures - if: | - always() && ( - (needs.publish-to-pypi.result == 'success') && - (needs.compute-signatures.result == 'success') - ) runs-on: ubuntu-latest @@ -142,63 +108,22 @@ jobs: - name: Create GitHub Release env: GITHUB_TOKEN: ${{ github.token }} - # Create a GitHub Release for this tag. The description can be changed later, as for now + TAG: ${{ needs.build.outputs.TAG }} + # Create a tag and a GitHub Release. The description can be changed later, as for now # we don't define it through this workflow. run: >- gh release create - '${{ github.ref_name }}' + '${{ env.TAG }}' --repo '${{ github.repository }}' --generate-notes - name: Upload artifact signatures to GitHub Release env: GITHUB_TOKEN: ${{ github.token }} + TAG: ${{ needs.build.outputs.TAG }} # Upload to GitHub Release using the `gh` CLI. # `dist/` contains the built packages, and the # sigstore-produced signatures and certificates. run: >- gh release upload - '${{ github.ref_name }}' dist/** - --repo '${{ github.repository }}' - - github-test-release: - name: Upload to GitHub Release Draft - needs: - - publish-to-test-pypi - - compute-signatures - if: | - always() && ( - (needs.publish-to-test-pypi.result == 'success') && - (needs.compute-signatures.result == 'success') - ) - runs-on: ubuntu-latest - - permissions: - contents: write # IMPORTANT: mandatory for making GitHub Releases - - steps: - - name: Download all the dists - uses: actions/download-artifact@v4 - with: - name: python-package-distributions-and-signatures - path: dist/ - - name: Create GitHub Release - env: - GITHUB_TOKEN: ${{ github.token }} - # Create a GitHub Release *draft*. The description can be changed later, as for now - # we don't define it through this workflow. - run: >- - gh release create - '${{ github.ref_name }}' - --repo '${{ github.repository }}' - --generate-notes - --draft - - name: Upload artifact signatures to GitHub Release - env: - GITHUB_TOKEN: ${{ github.token }} - # Upload to GitHub Release using the `gh` CLI. - # `dist/` contains the built packages, and the - # sigstore-produced signatures and certificates. - run: >- - gh release upload - '${{ github.ref_name }}' dist/** + '${{ env.TAG }}' dist/** --repo '${{ github.repository }}' diff --git a/.github/workflows/release_test_pypi.yml b/.github/workflows/release_test_pypi.yml new file mode 100644 index 000000000..6009a98d7 --- /dev/null +++ b/.github/workflows/release_test_pypi.yml @@ -0,0 +1,132 @@ +name: Publish to Test PyPI + +on: + # manually trigger the workflow + workflow_dispatch: + +jobs: + build: + name: Build Distribution + runs-on: ubuntu-latest + outputs: + TAG: ${{ steps.get_tag.outputs.TAG }} + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install pypa/build + run: >- + python3 -m pip install build --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Get Tag Name + id: get_tag + run: | + pip install . + TAG=$(python -c "from telegram import __version__; print(f'v{__version__}')") + echo "TAG=$TAG" >> $GITHUB_OUTPUT + + publish-to-test-pypi: + name: Publish to Test PyPI + needs: + - build + runs-on: ubuntu-latest + environment: + name: release_test_pypi + url: https://test.pypi.org/p/python-telegram-bot + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + compute-signatures: + name: Compute SHA1 Sums and Sign with Sigstore + runs-on: ubuntu-latest + needs: + - publish-to-test-pypi + + permissions: + id-token: write # IMPORTANT: mandatory for sigstore + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Compute SHA1 Sums + run: | + # Compute SHA1 sum of the distribution packages and save it to a file with the same name, + # but with .sha1 extension + for file in dist/*; do + sha1sum $file > $file.sha1 + done + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v3.0.0 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Store the distribution packages and signatures + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions-and-signatures + path: dist/ + + github-test-release: + name: Upload to GitHub Release Draft + needs: + - build + - compute-signatures + + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions-and-signatures + path: dist/ + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + TAG: ${{ needs.build.outputs.TAG }} + # Create a GitHub Release *draft*. The description can be changed later, as for now + # we don't define it through this workflow. + run: >- + gh release create + '${{ env.TAG }}' + --repo '${{ github.repository }}' + --generate-notes + --draft + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + TAG: ${{ needs.build.outputs.TAG }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ env.TAG }}' dist/** + --repo '${{ github.repository }}' diff --git a/CHANGES.rst b/CHANGES.rst index f56a61b9b..8e5f302dd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,58 @@ Changelog ========= +Version 21.5 +============ + +*Released 2024-09-01* + +This is the technical changelog for version 21.5. More elaborate release notes can be found in the news channel `@pythontelegrambotchannel `_. + +Major Changes +------------- + +- Full Support for Bot API 7.9 (:pr:`4429`) +- Full Support for Bot API 7.8 (:pr:`4408`) + +New Features +------------ + +- Add ``MessageEntity.shift_entities`` and ``MessageEntity.concatenate`` (:pr:`4376` closes :issue:`4372`) +- Add Parameter ``game_pattern`` to ``CallbackQueryHandler`` (:pr:`4353` by `jainamoswal `_ closes :issue:`4269`) +- Add Parameter ``read_file_handle`` to ``InputFile`` (:pr:`4388` closes :issue:`4339`) + +Documentation Improvements +-------------------------- + +- Bugfix for "Available In" Admonitions (:pr:`4413`) +- Documentation Improvements (:pr:`4400` closes :issue:`4446`, :pr:`4448` by `Palaptin `_) +- Document Return Types of ``RequestData`` Members (:pr:`4396`) +- Add Introductory Paragraphs to Telegram Types Subsections (:pr:`4389` by `mohdyusuf2312 `_ closes :issue:`4380`) +- Start Adapting to RTD Addons (:pr:`4386`) + +Minor and Internal Changes +--------------------------- + +- Remove Surplus Logging from ``Updater`` Network Loop (:pr:`4432` by `MartinHjelmare `_) +- Add Internal Constants for Encodings (:pr:`4378` by `elpekenin `_) +- Improve PyPI Automation (:pr:`4375` closes :issue:`4373`) +- Update Test Suite to New Test Channel Setup (:pr:`4435`) +- Improve Fixture Usage in ``test_message.py`` (:pr:`4431` by `Palaptin `_) +- Update Python 3.13 Test Suite to RC1 (:pr:`4415`) +- Bump ``ruff`` and Add New Rules (:pr:`4416`) + +Dependency Updates +------------------ + +- Update ``cachetools`` requirement from <5.5.0,>=5.3.3 to >=5.3.3,<5.6.0 (:pr:`4437`) +- Bump ``sphinx`` from 7.4.7 to 8.0.2 and ``furo`` from 2024.7.18 to 2024.8.6 (:pr:`4412`) +- Bump ``test-summary/action`` from 2.3 to 2.4 (:pr:`4410`) +- Bump ``pytest`` from 8.2.2 to 8.3.2 (:pr:`4403`) +- Bump ``dependabot/fetch-metadata`` from 2.1.0 to 2.2.0 (:pr:`4411`) +- Update ``cachetools`` requirement from ~=5.3.3 to >=5.3.3,<5.5.0 (:pr:`4390`) +- Bump ``sphinx`` from 7.3.7 to 7.4.7 (:pr:`4395`) +- Bump ``furo`` from 2024.5.6 to 2024.7.18 (:pr:`4392`) + Version 21.4 ============ diff --git a/README.rst b/README.rst index b2de996d2..605942c06 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,7 @@ :target: https://pypi.org/project/python-telegram-bot/ :alt: Supported Python versions -.. image:: https://img.shields.io/badge/Bot%20API-7.8-blue?logo=telegram +.. image:: https://img.shields.io/badge/Bot%20API-7.9-blue?logo=telegram :target: https://core.telegram.org/bots/api-changelog :alt: Supported Bot API version @@ -81,7 +81,7 @@ After installing_ the library, be sure to check out the section on `working with Telegram API support ~~~~~~~~~~~~~~~~~~~~ -All types and methods of the Telegram Bot API **7.8** are natively supported by this library. +All types and methods of the Telegram Bot API **7.9** are natively supported by this library. In addition, Bot API functionality not yet natively included can still be used as described `in our wiki `_. Notable Features @@ -119,7 +119,7 @@ Verifying Releases To enable you to verify that a release file that you downloaded was indeed provided by the ``python-telegram-bot`` team, we have taken the following measures. -Starting with v21.4, all releases are signed via `sigstore `_. +Starting with v21.4, all releases are signed via `sigstore `_. The corresponding signature files are uploaded to the `GitHub releases page`_. To verify the signature, please install the `sigstore Python client `_ and follow the instructions for `verifying signatures from GitHub Actions `_. As input for the ``--repository`` parameter, please use the value ``python-telegram-bot/python-telegram-bot``. @@ -157,7 +157,7 @@ PTB can be installed with optional dependencies: * ``pip install "python-telegram-bot[http2]"`` installs `httpx[http2] `_. Use this, if you want to use HTTP/2. * ``pip install "python-telegram-bot[rate-limiter]"`` installs `aiolimiter~=1.1.0 `_. Use this, if you want to use ``telegram.ext.AIORateLimiter``. * ``pip install "python-telegram-bot[webhooks]"`` installs the `tornado~=6.4 `_ library. Use this, if you want to use ``telegram.ext.Updater.start_webhook``/``telegram.ext.Application.run_webhook``. -* ``pip install "python-telegram-bot[callback-data]"`` installs the `cachetools>=5.3.3,<5.5.0 `_ library. Use this, if you want to use `arbitrary callback_data `_. +* ``pip install "python-telegram-bot[callback-data]"`` installs the `cachetools>=5.3.3,<5.6.0 `_ library. Use this, if you want to use `arbitrary callback_data `_. * ``pip install "python-telegram-bot[job-queue]"`` installs the `APScheduler~=3.10.4 `_ library and enforces `pytz>=2018.6 `_, where ``pytz`` is a dependency of ``APScheduler``. Use this, if you want to use the ``telegram.ext.JobQueue``. To install multiple optional dependencies, separate them by commas, e.g. ``pip install "python-telegram-bot[socks,webhooks]"``. diff --git a/docs/source/telegram.at-tree.rst b/docs/source/telegram.at-tree.rst index 8d3238a27..bb6e4c814 100644 --- a/docs/source/telegram.at-tree.rst +++ b/docs/source/telegram.at-tree.rst @@ -130,6 +130,7 @@ Available Types telegram.reactiontype telegram.reactiontypecustomemoji telegram.reactiontypeemoji + telegram.reactiontypepaid telegram.replykeyboardmarkup telegram.replykeyboardremove telegram.replyparameters diff --git a/docs/source/telegram.games-tree.rst b/docs/source/telegram.games-tree.rst index 010c3c6d1..97b961a9e 100644 --- a/docs/source/telegram.games-tree.rst +++ b/docs/source/telegram.games-tree.rst @@ -10,7 +10,7 @@ Your bot can offer users **HTML5 games** to play solo or to compete against each * If you send the game message without any buttons, it will automatically have a 'Play ``GameName``' button. When this button is pressed, your bot gets a :class:`telegram.CallbackQuery` with the ``game_short_name`` of the requested game. You provide the correct URL for this particular user and the app opens the game in the in-app browser. * You can manually add multiple buttons to your game message. Please note that the first button in the first row **must always** launch the game, using the field ``callback_game`` in :class:`telegram.InlineKeyboardButton`. You can add extra buttons according to taste: e.g., for a description of the rules, or to open the game's official community. * To make your game more attractive, you can upload a GIF animation that demonstrates the game to the users via `BotFather `_ (see `Lumberjack `_ for example). -* A game message will also display high scores for the current chat. Use :meth:`~telegram.Bot.setGameScore` to post high scores to the chat with the game, optionally add the :paramref:`~telegram.Bot.set_game_score.disable_edit_message` parameter if you don't want to automatically update the message with the current scoreboard. +* A game message will also display high scores for the current chat. Use :meth:`~telegram.Bot.setGameScore` to post high scores to the chat with the game, add the :paramref:`~telegram.Bot.set_game_score.disable_edit_message` parameter to disable automatic update of the message with the current scoreboard. * Use :meth:`~telegram.Bot.getGameHighScores` to get data for in-game high score tables. * You can also add an extra sharing button for users to share their best score to different chats. * For examples of what can be done using this new stuff, check the `@gamebot `_ and `@gamee `_ bots. diff --git a/docs/source/telegram.reactiontypepaid.rst b/docs/source/telegram.reactiontypepaid.rst new file mode 100644 index 000000000..f5035a1ba --- /dev/null +++ b/docs/source/telegram.reactiontypepaid.rst @@ -0,0 +1,6 @@ +ReactionTypePaid +================ + +.. autoclass:: telegram.ReactionTypePaid + :members: + :show-inheritance: diff --git a/docs/substitutions/global.rst b/docs/substitutions/global.rst index c4e9e493b..88a604cd1 100644 --- a/docs/substitutions/global.rst +++ b/docs/substitutions/global.rst @@ -60,10 +60,12 @@ .. |removed_thumb_note| replace:: Removed the deprecated argument and attribute ``thumb``. -.. |removed_thumb_url_note| replace:: Removed the deprecated argument and attribute ``thumb_url``. +.. |removed_thumb_url_note| replace:: Removed the deprecated argument and attribute ``thumb_url`` which made thumbnail_url mandatory. .. |removed_thumb_wildcard_note| replace:: Removed the deprecated arguments and attributes ``thumb_*``. +.. |thumbnail_url_mandatory| replace:: Removal of the deprecated argument ``thumb_url`` made ``thumbnail_url`` mandatory. + .. |async_context_manager| replace:: Asynchronous context manager which .. |reply_parameters| replace:: Description of the message to reply to. diff --git a/pyproject.toml b/pyproject.toml index 9285497df..80edfde44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,7 @@ all = [ ] callback-data = [ # Cachetools doesn't have a strict stability policy. Let's be cautious for now. - "cachetools>=5.3.3,<5.5.0", + "cachetools>=5.3.3,<5.6.0", ] ext = [ "python-telegram-bot[callback-data,job-queue,rate-limiter,webhooks]", diff --git a/telegram/__init__.py b/telegram/__init__.py index 5b52bf85c..7b5803a3e 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -204,6 +204,7 @@ __all__ = ( "ReactionType", "ReactionTypeCustomEmoji", "ReactionTypeEmoji", + "ReactionTypePaid", "RefundedPayment", "ReplyKeyboardMarkup", "ReplyKeyboardRemove", @@ -467,7 +468,13 @@ from ._payment.stars import ( from ._payment.successfulpayment import SuccessfulPayment from ._poll import InputPollOption, Poll, PollAnswer, PollOption from ._proximityalerttriggered import ProximityAlertTriggered -from ._reaction import ReactionCount, ReactionType, ReactionTypeCustomEmoji, ReactionTypeEmoji +from ._reaction import ( + ReactionCount, + ReactionType, + ReactionTypeCustomEmoji, + ReactionTypeEmoji, + ReactionTypePaid, +) from ._reply import ExternalReplyInfo, ReplyParameters, TextQuote from ._replykeyboardmarkup import ReplyKeyboardMarkup from ._replykeyboardremove import ReplyKeyboardRemove diff --git a/telegram/_bot.py b/telegram/_bot.py index d825a8878..b79df08ff 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -18,6 +18,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/]. """This module contains an object that represents a Telegram Bot.""" + import asyncio import contextlib import copy @@ -4427,18 +4428,6 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): If you're having any trouble setting up webhooks, please check out this `guide to Webhooks`_. - Note: - 1. You will not be able to receive updates using :meth:`get_updates` for long as an - outgoing webhook is set up. - 2. To use a self-signed certificate, you need to upload your public key certificate - using certificate parameter. Please upload as InputFile, sending a String will not - work. - 3. Ports currently supported for Webhooks: - :attr:`telegram.constants.SUPPORTED_WEBHOOK_PORTS`. - - If you're having any trouble setting up webhooks, please check out this `guide to - Webhooks`_. - .. seealso:: :meth:`telegram.ext.Application.run_webhook`, :meth:`telegram.ext.Updater.start_webhook` @@ -5019,7 +5008,7 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): payload (:obj:`str`): Bot-defined invoice payload. :tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`- :tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be - displayed to the user, use for your internal processes. + displayed to the user, use it for your internal processes. provider_token (:obj:`str`): Payments provider token, obtained via `@BotFather `_. Pass an empty string for payments in |tg_stars|. @@ -5785,10 +5774,10 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| - invite_link (:obj:`str` | :obj:`telegram.ChatInviteLink`): The invite link to edit. + invite_link (:obj:`str` | :class:`telegram.ChatInviteLink`): The invite link to edit. .. versionchanged:: 20.0 - Now also accepts :obj:`telegram.ChatInviteLink` instances. + Now also accepts :class:`telegram.ChatInviteLink` instances. expire_date (:obj:`int` | :obj:`datetime.datetime`, optional): Date when the link will expire. For timezone naive :obj:`datetime.datetime` objects, the default timezone of the @@ -5857,10 +5846,10 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| - invite_link (:obj:`str` | :obj:`telegram.ChatInviteLink`): The invite link to revoke. + invite_link (:obj:`str` | :class:`telegram.ChatInviteLink`): The invite link to revoke. .. versionchanged:: 20.0 - Now also accepts :obj:`telegram.ChatInviteLink` instances. + Now also accepts :class:`telegram.ChatInviteLink` instances. Returns: :class:`telegram.ChatInviteLink` @@ -6156,7 +6145,7 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): business_connection_id (:obj:`str`, optional): Unique identifier of the business connection on behalf of which the message will be pinned. - .. versionadded:: NEXT.VERSION + .. versionadded:: 21.5 Returns: :obj:`bool`: On success, :obj:`True` is returned. @@ -6209,7 +6198,7 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): business_connection_id (:obj:`str`, optional): Unique identifier of the business connection on behalf of which the message will be unpinned. - .. versionadded:: NEXT.VERSION + .. versionadded:: 21.5 Returns: :obj:`bool`: On success, :obj:`True` is returned. @@ -7402,8 +7391,9 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. .. versionadded:: 20.0 Args: - rights (:obj:`telegram.ChatAdministratorRights`, optional): A - :obj:`telegram.ChatAdministratorRights` object describing new default administrator + rights (:class:`telegram.ChatAdministratorRights`, optional): A + :class:`telegram.ChatAdministratorRights` object describing new default + administrator rights. If not specified, the default administrator rights will be cleared. for_channels (:obj:`bool`, optional): Pass :obj:`True` to change the default administrator rights of the bot in channels. Otherwise, the default administrator @@ -7413,7 +7403,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. :obj:`bool`: Returns :obj:`True` on success. Raises: - :obj:`telegram.error.TelegramError` + :exc:`telegram.error.TelegramError` """ data: JSONDict = {"rights": rights, "for_channels": for_channels} @@ -7979,7 +7969,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. payload (:obj:`str`): Bot-defined invoice payload. :tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`- :tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be - displayed to the user, use for your internal processes. + displayed to the user, use it for your internal processes. provider_token (:obj:`str`): Payments provider token, obtained via `@BotFather `_. Pass an empty string for payments in |tg_stars|. @@ -8179,7 +8169,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. ) -> bool: """ Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must - be an administrator in the chat for this to work and must have + be an administrator in the chat for this to work and must have the :paramref:`~telegram.ChatAdministratorRights.can_manage_topics` administrator rights, unless it is the creator of the topic. @@ -8447,7 +8437,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. ) -> bool: """ Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot - must be an administrator in the chat for this to work and must have + must be an administrator in the chat for this to work and must have the :attr:`~telegram.ChatAdministratorRights.can_manage_topics` administrator rights. .. versionadded:: 20.0 @@ -8946,7 +8936,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. """ Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have - the same available reactions as messages in the channel. + the same available reactions as messages in the channel. Bots can't use paid reactions. .. versionadded:: 20.8 @@ -8959,7 +8949,8 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. :class:`telegram.ReactionType` | :obj:`str`, optional): A list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either - already present on the message or explicitly allowed by chat administrators. + already present on the message or explicitly allowed by chat administrators. Paid + reactions can't be used by bots. Tip: Passed :obj:`str` values will be converted to either @@ -9076,7 +9067,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. user_id (:obj:`int`): User identifier of the sticker set owner. name (:obj:`str`): Sticker set name. old_sticker (:obj:`str`): File identifier of the replaced sticker. - sticker (:obj:`telegram.InputSticker`): An object with information about the added + sticker (:class:`telegram.InputSticker`): An object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged. @@ -9201,6 +9192,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. protect_content: ODVInput[bool] = DEFAULT_NONE, reply_parameters: Optional["ReplyParameters"] = None, reply_markup: Optional[ReplyMarkup] = None, + business_connection_id: Optional[str] = None, *, allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE, reply_to_message_id: Optional[int] = None, @@ -9210,12 +9202,14 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. pool_timeout: ODVInput[float] = DEFAULT_NONE, api_kwargs: Optional[JSONDict] = None, ) -> Message: - """Use this method to send paid media to channel chats. + """Use this method to send paid media. .. versionadded:: 21.4 Args: - chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| + chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| If the chat is a channel, all + Telegram Star proceeds from this media will be credited to the chat's balance. + Otherwise, they will be credited to the bot's balance. star_count (:obj:`int`): The number of Telegram Stars that must be paid to buy access to the media. media (Sequence[:class:`telegram.InputPaidMedia`]): A list describing the media to be @@ -9233,6 +9227,9 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. :class:`ReplyKeyboardRemove` | :class:`ForceReply`, optional): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + business_connection_id (:obj:`str`, optional): |business_id_str| + + .. versionadded:: 21.5 Keyword Args: allow_sending_without_reply (:obj:`bool`, optional): |allow_sending_without_reply| @@ -9274,8 +9271,122 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. connect_timeout=connect_timeout, pool_timeout=pool_timeout, api_kwargs=api_kwargs, + business_connection_id=business_connection_id, ) + async def create_chat_subscription_invite_link( + self, + chat_id: Union[str, int], + subscription_period: int, + subscription_price: int, + name: Optional[str] = None, + *, + read_timeout: ODVInput[float] = DEFAULT_NONE, + write_timeout: ODVInput[float] = DEFAULT_NONE, + connect_timeout: ODVInput[float] = DEFAULT_NONE, + pool_timeout: ODVInput[float] = DEFAULT_NONE, + api_kwargs: Optional[JSONDict] = None, + ) -> ChatInviteLink: + """ + Use this method to create a `subscription invite link `_ for a channel chat. + The bot must have the :attr:`~telegram.ChatPermissions.can_invite_users` administrator + right. The link can be edited using the :meth:`edit_chat_subscription_invite_link` or + revoked using the :meth:`revoke_chat_invite_link`. + + .. versionadded:: 21.5 + + Args: + chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| + subscription_period (:obj:`int`): The number of seconds the subscription will be + active for before the next payment. Currently, it must always be + :tg-const:`telegram.constants.ChatSubscriptionLimit.SUBSCRIPTION_PERIOD` (30 days). + subscription_price (:obj:`int`): The number of Telegram Stars a user must pay initially + and after each subsequent subscription period to be a member of the chat; + :tg-const:`telegram.constants.ChatSubscriptionLimit.MIN_PRICE`- + :tg-const:`telegram.constants.ChatSubscriptionLimit.MAX_PRICE`. + name (:obj:`str`, optional): Invite link name; + 0-:tg-const:`telegram.constants.ChatInviteLinkLimit.NAME_LENGTH` characters. + + Returns: + :class:`telegram.ChatInviteLink` + + Raises: + :class:`telegram.error.TelegramError` + + """ + data: JSONDict = { + "chat_id": chat_id, + "subscription_period": subscription_period, + "subscription_price": subscription_price, + "name": name, + } + + result = await self._post( + "createChatSubscriptionInviteLink", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + return ChatInviteLink.de_json(result, self) # type: ignore[return-value] + + async def edit_chat_subscription_invite_link( + self, + chat_id: Union[str, int], + invite_link: Union[str, "ChatInviteLink"], + name: Optional[str] = None, + *, + read_timeout: ODVInput[float] = DEFAULT_NONE, + write_timeout: ODVInput[float] = DEFAULT_NONE, + connect_timeout: ODVInput[float] = DEFAULT_NONE, + pool_timeout: ODVInput[float] = DEFAULT_NONE, + api_kwargs: Optional[JSONDict] = None, + ) -> ChatInviteLink: + """ + Use this method to edit a subscription invite link created by the bot. The bot must have + :attr:`telegram.ChatPermissions.can_invite_users` administrator right. + + .. versionadded:: 21.5 + + Args: + chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| + invite_link (:obj:`str` | :obj:`telegram.ChatInviteLink`): The invite link to edit. + name (:obj:`str`, optional): Invite link name; + 0-:tg-const:`telegram.constants.ChatInviteLinkLimit.NAME_LENGTH` characters. + + Tip: + Omitting this argument removes the name of the invite link. + + Returns: + :class:`telegram.ChatInviteLink` + + Raises: + :class:`telegram.error.TelegramError` + + """ + link = invite_link.invite_link if isinstance(invite_link, ChatInviteLink) else invite_link + data: JSONDict = { + "chat_id": chat_id, + "invite_link": link, + "name": name, + } + + result = await self._post( + "editChatSubscriptionInviteLink", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + return ChatInviteLink.de_json(result, self) # type: ignore[return-value] + def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002 """See :meth:`telegram.TelegramObject.to_dict`.""" data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name} @@ -9532,3 +9643,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. """Alias for :meth:`get_star_transactions`""" sendPaidMedia = send_paid_media """Alias for :meth:`send_paid_media`""" + createChatSubscriptionInviteLink = create_chat_subscription_invite_link + """Alias for :meth:`create_chat_subscription_invite_link`""" + editChatSubscriptionInviteLink = edit_chat_subscription_invite_link + """Alias for :meth:`edit_chat_subscription_invite_link`""" diff --git a/telegram/_chat.py b/telegram/_chat.py index 02d80c947..6eb789785 100644 --- a/telegram/_chat.py +++ b/telegram/_chat.py @@ -2666,6 +2666,81 @@ class _ChatBase(TelegramObject): api_kwargs=api_kwargs, ) + async def create_subscription_invite_link( + self, + subscription_period: int, + subscription_price: int, + name: Optional[str] = None, + *, + read_timeout: ODVInput[float] = DEFAULT_NONE, + write_timeout: ODVInput[float] = DEFAULT_NONE, + connect_timeout: ODVInput[float] = DEFAULT_NONE, + pool_timeout: ODVInput[float] = DEFAULT_NONE, + api_kwargs: Optional[JSONDict] = None, + ) -> "ChatInviteLink": + """Shortcut for:: + + await bot.create_chat_subscription_invite_link( + chat_id=update.effective_chat.id, *args, **kwargs + ) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.create_chat_subscription_invite_link`. + + .. versionadded:: 21.5 + + Returns: + :class:`telegram.ChatInviteLink` + """ + return await self.get_bot().create_chat_subscription_invite_link( + chat_id=self.id, + subscription_period=subscription_period, + subscription_price=subscription_price, + name=name, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + async def edit_subscription_invite_link( + self, + invite_link: Union[str, "ChatInviteLink"], + name: Optional[str] = None, + *, + read_timeout: ODVInput[float] = DEFAULT_NONE, + write_timeout: ODVInput[float] = DEFAULT_NONE, + connect_timeout: ODVInput[float] = DEFAULT_NONE, + pool_timeout: ODVInput[float] = DEFAULT_NONE, + api_kwargs: Optional[JSONDict] = None, + ) -> "ChatInviteLink": + """Shortcut for:: + + await bot.edit_chat_subscription_invite_link( + chat_id=update.effective_chat.id, *args, **kwargs + ) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.edit_chat_subscription_invite_link`. + + .. versionadded:: 21.5 + + Returns: + :class:`telegram.ChatInviteLink` + + """ + return await self.get_bot().edit_chat_subscription_invite_link( + chat_id=self.id, + invite_link=invite_link, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + name=name, + ) + async def approve_join_request( self, user_id: int, @@ -3274,6 +3349,7 @@ class _ChatBase(TelegramObject): protect_content: ODVInput[bool] = DEFAULT_NONE, reply_parameters: Optional["ReplyParameters"] = None, reply_markup: Optional[ReplyMarkup] = None, + business_connection_id: Optional[str] = None, *, allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE, reply_to_message_id: Optional[int] = None, @@ -3314,6 +3390,7 @@ class _ChatBase(TelegramObject): connect_timeout=connect_timeout, pool_timeout=pool_timeout, api_kwargs=api_kwargs, + business_connection_id=business_connection_id, ) diff --git a/telegram/_chatbackground.py b/telegram/_chatbackground.py index f9c77619f..b33fd4d91 100644 --- a/telegram/_chatbackground.py +++ b/telegram/_chatbackground.py @@ -307,7 +307,7 @@ class BackgroundTypeFill(BackgroundType): .. versionadded:: 21.2 Args: - fill (:obj:`telegram.BackgroundFill`): The background fill. + fill (:class:`telegram.BackgroundFill`): The background fill. dark_theme_dimming (:obj:`int`): Dimming of the background in dark themes, as a percentage; 0-:tg-const:`telegram.constants.BackgroundTypeLimit.MAX_DIMMING`. @@ -315,7 +315,7 @@ class BackgroundTypeFill(BackgroundType): Attributes: type (:obj:`str`): Type of the background. Always :attr:`~telegram.BackgroundType.FILL`. - fill (:obj:`telegram.BackgroundFill`): The background fill. + fill (:class:`telegram.BackgroundFill`): The background fill. dark_theme_dimming (:obj:`int`): Dimming of the background in dark themes, as a percentage; 0-:tg-const:`telegram.constants.BackgroundTypeLimit.MAX_DIMMING`. @@ -349,7 +349,7 @@ class BackgroundTypeWallpaper(BackgroundType): .. versionadded:: 21.2 Args: - document (:obj:`telegram.Document`): Document with the wallpaper + document (:class:`telegram.Document`): Document with the wallpaper dark_theme_dimming (:obj:`int`): Dimming of the background in dark themes, as a percentage; 0-:tg-const:`telegram.constants.BackgroundTypeLimit.MAX_DIMMING`. @@ -361,7 +361,7 @@ class BackgroundTypeWallpaper(BackgroundType): Attributes: type (:obj:`str`): Type of the background. Always :attr:`~telegram.BackgroundType.WALLPAPER`. - document (:obj:`telegram.Document`): Document with the wallpaper + document (:class:`telegram.Document`): Document with the wallpaper dark_theme_dimming (:obj:`int`): Dimming of the background in dark themes, as a percentage; 0-:tg-const:`telegram.constants.BackgroundTypeLimit.MAX_DIMMING`. @@ -407,8 +407,8 @@ class BackgroundTypePattern(BackgroundType): .. versionadded:: 21.2 Args: - document (:obj:`telegram.Document`): Document with the pattern. - fill (:obj:`telegram.BackgroundFill`): The background fill that is combined with + document (:class:`telegram.Document`): Document with the pattern. + fill (:class:`telegram.BackgroundFill`): The background fill that is combined with the pattern. intensity (:obj:`int`): Intensity of the pattern when it is shown above the filled background; @@ -422,8 +422,8 @@ class BackgroundTypePattern(BackgroundType): Attributes: type (:obj:`str`): Type of the background. Always :attr:`~telegram.BackgroundType.PATTERN`. - document (:obj:`telegram.Document`): Document with the pattern. - fill (:obj:`telegram.BackgroundFill`): The background fill that is combined with + document (:class:`telegram.Document`): Document with the pattern. + fill (:class:`telegram.BackgroundFill`): The background fill that is combined with the pattern. intensity (:obj:`int`): Intensity of the pattern when it is shown above the filled background; @@ -511,10 +511,10 @@ class ChatBackground(TelegramObject): .. versionadded:: 21.2 Args: - type (:obj:`telegram.BackgroundType`): Type of the background. + type (:class:`telegram.BackgroundType`): Type of the background. Attributes: - type (:obj:`telegram.BackgroundType`): Type of the background. + type (:class:`telegram.BackgroundType`): Type of the background. """ __slots__ = ("type",) diff --git a/telegram/_chatfullinfo.py b/telegram/_chatfullinfo.py index 04898659c..de26101f3 100644 --- a/telegram/_chatfullinfo.py +++ b/telegram/_chatfullinfo.py @@ -78,7 +78,7 @@ class ChatFullInfo(_ChatBase): #collectible-usernames>`_; for private chats, supergroups and channels. .. versionadded:: 20.0 - birthdate (:obj:`telegram.Birthdate`, optional): For private chats, + birthdate (:class:`telegram.Birthdate`, optional): For private chats, the date of birth of the user. .. versionadded:: 21.1 @@ -94,8 +94,8 @@ class ChatFullInfo(_ChatBase): chats with business accounts, the opening hours of the business. .. versionadded:: 21.1 - personal_chat (:obj:`telegram.Chat`, optional): For private chats, the personal channel of - the user. + personal_chat (:class:`telegram.Chat`, optional): For private chats, the personal channel + of the user. .. versionadded:: 21.1 available_reactions (Sequence[:class:`telegram.ReactionType`], optional): List of available @@ -232,7 +232,7 @@ class ChatFullInfo(_ChatBase): obtained via :meth:`~telegram.Bot.get_chat`. .. versionadded:: 20.0 - birthdate (:obj:`telegram.Birthdate`): Optional. For private chats, + birthdate (:class:`telegram.Birthdate`): Optional. For private chats, the date of birth of the user. .. versionadded:: 21.1 @@ -248,8 +248,8 @@ class ChatFullInfo(_ChatBase): chats with business accounts, the opening hours of the business. .. versionadded:: 21.1 - personal_chat (:obj:`telegram.Chat`): Optional. For private chats, the personal channel of - the user. + personal_chat (:class:`telegram.Chat`): Optional. For private chats, the personal channel + of the user. .. versionadded:: 21.1 available_reactions (Tuple[:class:`telegram.ReactionType`]): Optional. List of available diff --git a/telegram/_chatinvitelink.py b/telegram/_chatinvitelink.py index 43e7e8ab6..b26de4e33 100644 --- a/telegram/_chatinvitelink.py +++ b/telegram/_chatinvitelink.py @@ -69,6 +69,16 @@ class ChatInviteLink(TelegramObject): created using this link. .. versionadded:: 13.8 + subscription_period (:obj:`int`, optional): The number of seconds the subscription will be + active for before the next payment. + + .. versionadded:: 21.5 + subscription_price (:obj:`int`, optional): The amount of Telegram Stars a user must pay + initially and after each subsequent subscription period to be a member of the chat + using the link. + + .. versionadded:: 21.5 + Attributes: invite_link (:obj:`str`): The invite link. If the link was created by another chat administrator, then the second part of the link will be replaced with ``'…'``. @@ -96,6 +106,15 @@ class ChatInviteLink(TelegramObject): created using this link. .. versionadded:: 13.8 + subscription_period (:obj:`int`): Optional. The number of seconds the subscription will be + active for before the next payment. + + .. versionadded:: 21.5 + subscription_price (:obj:`int`): Optional. The amount of Telegram Stars a user must pay + initially and after each subsequent subscription period to be a member of the chat + using the link. + + .. versionadded:: 21.5 """ @@ -109,6 +128,8 @@ class ChatInviteLink(TelegramObject): "member_limit", "name", "pending_join_request_count", + "subscription_period", + "subscription_price", ) def __init__( @@ -122,6 +143,8 @@ class ChatInviteLink(TelegramObject): member_limit: Optional[int] = None, name: Optional[str] = None, pending_join_request_count: Optional[int] = None, + subscription_period: Optional[int] = None, + subscription_price: Optional[int] = None, *, api_kwargs: Optional[JSONDict] = None, ): @@ -140,6 +163,9 @@ class ChatInviteLink(TelegramObject): self.pending_join_request_count: Optional[int] = ( int(pending_join_request_count) if pending_join_request_count is not None else None ) + self.subscription_period: Optional[int] = subscription_period + self.subscription_price: Optional[int] = subscription_price + self._id_attrs = ( self.invite_link, self.creates_join_request, diff --git a/telegram/_chatmember.py b/telegram/_chatmember.py index 0cc06bf58..da84516b1 100644 --- a/telegram/_chatmember.py +++ b/telegram/_chatmember.py @@ -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/]. """This module contains an object that represents a Telegram ChatMember.""" + import datetime from typing import TYPE_CHECKING, Dict, Final, Optional, Type @@ -391,24 +392,34 @@ class ChatMemberMember(ChatMember): Args: user (:class:`telegram.User`): Information about the user. + until_date (:class:`datetime.datetime`, optional): Date when the user's subscription will + expire. + + .. versionadded:: 21.5 Attributes: status (:obj:`str`): The member's status in the chat, always :tg-const:`telegram.ChatMember.MEMBER`. user (:class:`telegram.User`): Information about the user. + until_date (:class:`datetime.datetime`): Optional. Date when the user's subscription will + expire. + + .. versionadded:: 21.5 """ - __slots__ = () + __slots__ = ("until_date",) def __init__( self, user: User, + until_date: Optional[datetime.datetime] = None, *, api_kwargs: Optional[JSONDict] = None, ): super().__init__(status=ChatMember.MEMBER, user=user, api_kwargs=api_kwargs) - self._freeze() + with self._unfrozen(): + self.until_date: Optional[datetime.datetime] = until_date class ChatMemberRestricted(ChatMember): diff --git a/telegram/_files/inputfile.py b/telegram/_files/inputfile.py index 8f9c24a20..e7c9cc6c6 100644 --- a/telegram/_files/inputfile.py +++ b/telegram/_files/inputfile.py @@ -78,7 +78,7 @@ class InputFile: # here the file handle is already closed and the upload will fail await bot.send_document(chat_id, input_file) - .. versionadded:: NEXT.VERSION + .. versionadded:: 21.5 Attributes: @@ -126,7 +126,7 @@ class InputFile: def field_tuple(self) -> FieldTuple: """Field tuple representing the contents of the file for upload to the Telegram servers. - .. versionchanged:: NEXT.VERSION + .. versionchanged:: 21.5 Content may now be a file handle. Returns: diff --git a/telegram/_files/inputsticker.py b/telegram/_files/inputsticker.py index 89f1db81d..8fc8b8461 100644 --- a/telegram/_files/inputsticker.py +++ b/telegram/_files/inputsticker.py @@ -49,7 +49,7 @@ class InputSticker(TelegramObject): :tg-const:`telegram.constants.StickerLimit.MIN_STICKER_EMOJI` - :tg-const:`telegram.constants.StickerLimit.MAX_STICKER_EMOJI` emoji associated with the sticker. - mask_position (:obj:`telegram.MaskPosition`, optional): Position where the mask should be + mask_position (:class:`telegram.MaskPosition`, optional): Position where the mask should be placed on faces. For ":tg-const:`telegram.constants.StickerType.MASK`" stickers only. keywords (Sequence[:obj:`str`], optional): Sequence of 0-:tg-const:`telegram.constants.StickerLimit.MAX_SEARCH_KEYWORDS` search keywords @@ -71,7 +71,7 @@ class InputSticker(TelegramObject): :tg-const:`telegram.constants.StickerLimit.MIN_STICKER_EMOJI` - :tg-const:`telegram.constants.StickerLimit.MAX_STICKER_EMOJI` emoji associated with the sticker. - mask_position (:obj:`telegram.MaskPosition`): Optional. Position where the mask should be + mask_position (:class:`telegram.MaskPosition`): Optional. Position where the mask should be placed on faces. For ":tg-const:`telegram.constants.StickerType.MASK`" stickers only. keywords (Tuple[:obj:`str`]): Optional. Tuple of 0-:tg-const:`telegram.constants.StickerLimit.MAX_SEARCH_KEYWORDS` search keywords diff --git a/telegram/_giveaway.py b/telegram/_giveaway.py index 0008dc9dd..b287433fe 100644 --- a/telegram/_giveaway.py +++ b/telegram/_giveaway.py @@ -126,7 +126,7 @@ class Giveaway(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["Giveaway"]: - """See :obj:`telegram.TelegramObject.de_json`.""" + """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if data is None: @@ -262,7 +262,7 @@ class GiveawayWinners(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["GiveawayWinners"]: - """See :obj:`telegram.TelegramObject.de_json`.""" + """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if data is None: @@ -330,7 +330,7 @@ class GiveawayCompleted(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["GiveawayCompleted"]: - """See :obj:`telegram.TelegramObject.de_json`.""" + """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if data is None: diff --git a/telegram/_inline/inlinekeyboardbutton.py b/telegram/_inline/inlinekeyboardbutton.py index 6ceca1a31..cff4df66a 100644 --- a/telegram/_inline/inlinekeyboardbutton.py +++ b/telegram/_inline/inlinekeyboardbutton.py @@ -99,7 +99,7 @@ class InlineKeyboardButton(TelegramObject): .. seealso:: :wiki:`Arbitrary callback_data ` - web_app (:obj:`telegram.WebAppInfo`, optional): Description of the `Web App + web_app (:class:`telegram.WebAppInfo`, optional): Description of the `Web App `_ that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method :meth:`~telegram.Bot.answer_web_app_query`. Available only in @@ -107,16 +107,14 @@ class InlineKeyboardButton(TelegramObject): a Telegram Business account. .. versionadded:: 20.0 - switch_inline_query (:obj:`str`, optional): If set, pressing the button will insert the - bot's username and the specified inline query in the current chat's input field. May be - empty, in which case only the bot's username will be inserted. - - This offers a quick way for the user to open your bot in inline mode in the same chat - - good for selecting something from multiple options. Not supported in channels and for - messages sent on behalf of a Telegram Business account. + switch_inline_query (:obj:`str`, optional): If set, pressing the button will prompt the + user to select one of their chats, open that chat and insert the bot's username and the + specified inline query in the input field. May be empty, in which case just the bot's + username will be inserted. Not supported for messages sent on behalf of a Telegram + Business account. Tip: - This is similar to the new parameter :paramref:`switch_inline_query_chosen_chat`, + This is similar to the parameter :paramref:`switch_inline_query_chosen_chat`, but gives no control over which chats can be selected. switch_inline_query_current_chat (:obj:`str`, optional): If set, pressing the button will insert the bot's username and the specified inline query in the current chat's input @@ -137,7 +135,7 @@ class InlineKeyboardButton(TelegramObject): Note: This type of button **must** always be the first button in the first row and can only be used in invoice messages. - switch_inline_query_chosen_chat (:obj:`telegram.SwitchInlineQueryChosenChat`, optional): + switch_inline_query_chosen_chat (:class:`telegram.SwitchInlineQueryChosenChat`, optional): If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field. Not supported for messages sent on behalf of a Telegram @@ -170,7 +168,7 @@ class InlineKeyboardButton(TelegramObject): to the bot when the button is pressed, UTF-8 :tg-const:`telegram.InlineKeyboardButton.MIN_CALLBACK_DATA`- :tg-const:`telegram.InlineKeyboardButton.MAX_CALLBACK_DATA` bytes. - web_app (:obj:`telegram.WebAppInfo`): Optional. Description of the `Web App + web_app (:class:`telegram.WebAppInfo`): Optional. Description of the `Web App `_ that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method :meth:`~telegram.Bot.answer_web_app_query`. Available only in @@ -178,16 +176,14 @@ class InlineKeyboardButton(TelegramObject): a Telegram Business account. .. versionadded:: 20.0 - switch_inline_query (:obj:`str`): Optional. If set, pressing the button will insert the - bot's username and the specified inline query in the current chat's input field. May be - empty, in which case only the bot's username will be inserted. - - This offers a quick way for the user to open your bot in inline mode in the same chat - - good for selecting something from multiple options. Not supported in channels and for - messages sent on behalf of a Telegram Business account. + switch_inline_query (:obj:`str`): Optional. If set, pressing the button will prompt the + user to select one of their chats, open that chat and insert the bot's username and the + specified inline query in the input field. May be empty, in which case just the bot's + username will be inserted. Not supported for messages sent on behalf of a Telegram + Business account. Tip: - This is similar to the new parameter :paramref:`switch_inline_query_chosen_chat`, + This is similar to the parameter :paramref:`switch_inline_query_chosen_chat`, but gives no control over which chats can be selected. switch_inline_query_current_chat (:obj:`str`): Optional. If set, pressing the button will insert the bot's username and the specified inline query in the current chat's input @@ -208,7 +204,7 @@ class InlineKeyboardButton(TelegramObject): Note: This type of button **must** always be the first button in the first row and can only be used in invoice messages. - switch_inline_query_chosen_chat (:obj:`telegram.SwitchInlineQueryChosenChat`): Optional. + switch_inline_query_chosen_chat (:class:`telegram.SwitchInlineQueryChosenChat`): Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field. Not supported for messages sent on behalf of a Telegram diff --git a/telegram/_inline/inlinequeryresultgif.py b/telegram/_inline/inlinequeryresultgif.py index 13e1f253b..e5694e4f8 100644 --- a/telegram/_inline/inlinequeryresultgif.py +++ b/telegram/_inline/inlinequeryresultgif.py @@ -50,16 +50,14 @@ class InlineQueryResultGif(InlineQueryResult): gif_width (:obj:`int`, optional): Width of the GIF. gif_height (:obj:`int`, optional): Height of the GIF. gif_duration (:obj:`int`, optional): Duration of the GIF in seconds. - thumbnail_url (:obj:`str`, optional): URL of the static (JPEG or GIF) or animated (MPEG4) + thumbnail_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result. - Warning: - The Bot API does **not** define this as an optional argument. It is formally - optional for backwards compatibility with the deprecated :paramref:`thumb_url`. - If you pass neither :paramref:`thumbnail_url` nor :paramref:`thumb_url`, - :class:`ValueError` will be raised. - .. versionadded:: 20.2 + + ..versionchanged:: 20.5 + |thumbnail_url_mandatory| + thumbnail_mime_type (:obj:`str`, optional): MIME type of the thumbnail, must be one of ``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``. @@ -82,10 +80,6 @@ class InlineQueryResultGif(InlineQueryResult): .. versionadded:: 21.3 - Raises: - :class:`ValueError`: If neither :paramref:`thumbnail_url` nor :paramref:`thumb_url` is - supplied or if both are supplied and are not equal. - Attributes: type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.GIF`. id (:obj:`str`): Unique identifier for this result, diff --git a/telegram/_inline/inlinequeryresultmpeg4gif.py b/telegram/_inline/inlinequeryresultmpeg4gif.py index 1fff84841..9e27ab949 100644 --- a/telegram/_inline/inlinequeryresultmpeg4gif.py +++ b/telegram/_inline/inlinequeryresultmpeg4gif.py @@ -51,16 +51,14 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): mpeg4_width (:obj:`int`, optional): Video width. mpeg4_height (:obj:`int`, optional): Video height. mpeg4_duration (:obj:`int`, optional): Video duration in seconds. - thumbnail_url (:obj:`str`, optional): URL of the static (JPEG or GIF) or animated (MPEG4) + thumbnail_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result. - Warning: - The Bot API does **not** define this as an optional argument. It is formally - optional for backwards compatibility with the deprecated :paramref:`thumb_url`. - If you pass neither :paramref:`thumbnail_url` nor :paramref:`thumb_url`, - :class:`ValueError` will be raised. - .. versionadded:: 20.2 + + ..versionchanged:: 20.5 + |thumbnail_url_mandatory| + thumbnail_mime_type (:obj:`str`, optional): MIME type of the thumbnail, must be one of ``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``. @@ -83,9 +81,6 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med| .. versionadded:: 21.3 - Raises: - :class:`ValueError`: If neither :paramref:`thumbnail_url` nor :paramref:`thumb_url` is - supplied or if both are supplied and are not equal. Attributes: type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.MPEG4GIF`. diff --git a/telegram/_inline/inlinequeryresultphoto.py b/telegram/_inline/inlinequeryresultphoto.py index 637e952d4..b74adf218 100644 --- a/telegram/_inline/inlinequeryresultphoto.py +++ b/telegram/_inline/inlinequeryresultphoto.py @@ -48,15 +48,13 @@ class InlineQueryResultPhoto(InlineQueryResult): :tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes. photo_url (:obj:`str`): A valid URL of the photo. Photo must be in JPEG format. Photo size must not exceed 5MB. - thumbnail_url (:obj:`str`, optional): URL of the thumbnail for the photo. - - Warning: - The Bot API does **not** define this as an optional argument. It is formally - optional for backwards compatibility with the deprecated :paramref:`thumb_url`. - If you pass neither :paramref:`thumbnail_url` nor :paramref:`thumb_url`, - :class:`ValueError` will be raised. + thumbnail_url (:obj:`str`): URL of the thumbnail for the photo. .. versionadded:: 20.2 + + ..versionchanged:: 20.5 + |thumbnail_url_mandatory| + photo_width (:obj:`int`, optional): Width of the photo. photo_height (:obj:`int`, optional): Height of the photo. title (:obj:`str`, optional): Title for the result. @@ -78,10 +76,6 @@ class InlineQueryResultPhoto(InlineQueryResult): .. versionadded:: 21.3 - Raises: - :class:`ValueError`: If neither :paramref:`thumbnail_url` nor :paramref:`thumb_url` is - supplied or if both are supplied and are not equal. - Attributes: type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.PHOTO`. id (:obj:`str`): Unique identifier for this result, diff --git a/telegram/_inline/inlinequeryresultvideo.py b/telegram/_inline/inlinequeryresultvideo.py index 90bf4c86d..bb01c1ac1 100644 --- a/telegram/_inline/inlinequeryresultvideo.py +++ b/telegram/_inline/inlinequeryresultvideo.py @@ -55,20 +55,12 @@ class InlineQueryResultVideo(InlineQueryResult): mime_type (:obj:`str`): Mime type of the content of video url, "text/html" or "video/mp4". thumbnail_url (:obj:`str`, optional): URL of the thumbnail (JPEG only) for the video. - Warning: - The Bot API does **not** define this as an optional argument. It is formally - optional for backwards compatibility with the deprecated :paramref:`thumb_url`. - If you pass neither :paramref:`thumbnail_url` nor :paramref:`thumb_url`, - :class:`ValueError` will be raised. - .. versionadded:: 20.2 - title (:obj:`str`, optional): Title for the result. - Warning: - The Bot API does **not** define this as an optional argument. It is formally - optional to ensure backwards compatibility of :paramref:`thumbnail_url` with the - deprecated :paramref:`thumb_url`, which required that :paramref:`thumbnail_url` - become optional. :class:`TypeError` will be raised if no ``title`` is passed. + ..versionchanged:: 20.5 + |thumbnail_url_mandatory| + + title (:obj:`str`): Title for the result. caption (:obj:`str`, optional): Caption of the video to be sent, 0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities parsing. @@ -92,11 +84,6 @@ class InlineQueryResultVideo(InlineQueryResult): .. versionadded:: 21.3 - Raises: - :class:`ValueError`: If neither :paramref:`thumbnail_url` nor :paramref:`thumb_url` is - supplied or if both are supplied and are not equal. - :class:`TypeError`: If no :paramref:`title` is passed. - Attributes: type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.VIDEO`. id (:obj:`str`): Unique identifier for this result, diff --git a/telegram/_inline/inputinvoicemessagecontent.py b/telegram/_inline/inputinvoicemessagecontent.py index e13642da5..101e0184b 100644 --- a/telegram/_inline/inputinvoicemessagecontent.py +++ b/telegram/_inline/inputinvoicemessagecontent.py @@ -47,7 +47,7 @@ class InputInvoiceMessageContent(InputMessageContent): payload (:obj:`str`): Bot-defined invoice payload. :tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`- :tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be displayed - to the user, use for your internal processes. + to the user, use it for your internal processes. provider_token (:obj:`str`): Payment provider token, obtained via `@Botfather `_. Pass an empty string for payments in |tg_stars|. @@ -115,7 +115,7 @@ class InputInvoiceMessageContent(InputMessageContent): payload (:obj:`str`): Bot-defined invoice payload. :tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`- :tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be displayed - to the user, use for your internal processes. + to the user, use it for your internal processes. provider_token (:obj:`str`): Payment provider token, obtained via `@Botfather `_. Pass an empty string for payments in `Telegram Stars `_. diff --git a/telegram/_message.py b/telegram/_message.py index 7d077a4d9..11bee5724 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -280,15 +280,14 @@ class Message(MaybeInaccessibleMessage): Args: message_id (:obj:`int`): Unique message identifier inside this chat. - from_user (:class:`telegram.User`, optional): Sender of the message; empty for messages - sent to channels. For backward compatibility, this will contain a fake sender user in - non-channel chats, if the message was sent on behalf of a chat. - sender_chat (:class:`telegram.Chat`, optional): Sender of the message, sent on behalf of a - chat. For example, the channel itself for channel posts, the supergroup itself for - messages from anonymous group administrators, the linked channel for messages - automatically forwarded to the discussion group. For backward compatibility, - :attr:`from_user` contains a fake sender user in non-channel chats, if the message was - sent on behalf of a chat. + from_user (:class:`telegram.User`, optional): Sender of the message; may be empty for + messages sent to channels. For backward compatibility, if the message was sent on + behalf of a chat, the field contains a fake sender user in non-channel chats. + sender_chat (:class:`telegram.Chat`, optional): Sender of the message when sent on behalf + of a chat. For example, the supergroup itself for messages sent by its anonymous + administrators or a linked channel for messages automatically forwarded to the + channel's discussion group. For backward compatibility, if the message was sent on + behalf of a chat, the field from contains a fake sender user in non-channel chats. date (:class:`datetime.datetime`): Date the message was sent in Unix time. Converted to :class:`datetime.datetime`. @@ -570,36 +569,35 @@ class Message(MaybeInaccessibleMessage): .. versionadded:: 21.1 - sender_business_bot (:obj:`telegram.User`, optional): The bot that actually sent the + sender_business_bot (:class:`telegram.User`, optional): The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the connected business account. .. versionadded:: 21.1 - chat_background_set (:obj:`telegram.ChatBackground`, optional): Service message: chat + chat_background_set (:class:`telegram.ChatBackground`, optional): Service message: chat background set. .. versionadded:: 21.2 - paid_media (:obj:`telegram.PaidMediaInfo`, optional): Message contains paid media; + paid_media (:class:`telegram.PaidMediaInfo`, optional): Message contains paid media; information about the paid media. .. versionadded:: 21.4 - refunded_payment (:obj:`telegram.RefundedPayment`, optional): Message is a service message - about a refunded payment, information about the payment. + refunded_payment (:class:`telegram.RefundedPayment`, optional): Message is a service + message about a refunded payment, information about the payment. .. versionadded:: 21.4 Attributes: message_id (:obj:`int`): Unique message identifier inside this chat. - from_user (:class:`telegram.User`): Optional. Sender of the message; empty for messages - sent to channels. For backward compatibility, this will contain a fake sender user in - non-channel chats, if the message was sent on behalf of a chat. - sender_chat (:class:`telegram.Chat`): Optional. Sender of the message, sent on behalf of a - chat. For example, the channel itself for channel posts, the supergroup itself for - messages from anonymous group administrators, the linked channel for messages - automatically forwarded to the discussion group. For backward compatibility, - :attr:`from_user` contains a fake sender user in non-channel chats, if the message was - sent on behalf of a chat. + from_user (:class:`telegram.User`): Optional. Sender of the message; may be empty for + messages sent to channels. For backward compatibility, if the message was sent on + behalf of a chat, the field contains a fake sender user in non-channel chats. + sender_chat (:class:`telegram.Chat`): Optional. Sender of the message when sent on behalf + of a chat. For example, the supergroup itself for messages sent by its anonymous + administrators or a linked channel for messages automatically forwarded to the + channel's discussion group. For backward compatibility, if the message was sent on + behalf of a chat, the field from contains a fake sender user in non-channel chats. date (:class:`datetime.datetime`): Date the message was sent in Unix time. Converted to :class:`datetime.datetime`. @@ -897,22 +895,22 @@ class Message(MaybeInaccessibleMessage): .. versionadded:: 21.1 - sender_business_bot (:obj:`telegram.User`): Optional. The bot that actually sent the + sender_business_bot (:class:`telegram.User`): Optional. The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the connected business account. .. versionadded:: 21.1 - chat_background_set (:obj:`telegram.ChatBackground`): Optional. Service message: chat + chat_background_set (:class:`telegram.ChatBackground`): Optional. Service message: chat background set .. versionadded:: 21.2 - paid_media (:obj:`telegram.PaidMediaInfo`): Optional. Message contains paid media; + paid_media (:class:`telegram.PaidMediaInfo`): Optional. Message contains paid media; information about the paid media. .. versionadded:: 21.4 - refunded_payment (:obj:`telegram.RefundedPayment`): Optional. Message is a service message - about a refunded payment, information about the payment. + refunded_payment (:class:`telegram.RefundedPayment`): Optional. Message is a service + message about a refunded payment, information about the payment. .. versionadded:: 21.4 @@ -4114,7 +4112,7 @@ class Message(MaybeInaccessibleMessage): For the documentation of the arguments, please see :meth:`telegram.Bot.pin_chat_message`. - .. versionchanged:: NEXT.VERSION + .. versionchanged:: 21.5 Now also passes :attr:`business_connection_id` to :meth:`telegram.Bot.pin_chat_message`. @@ -4154,7 +4152,7 @@ class Message(MaybeInaccessibleMessage): For the documentation of the arguments, please see :meth:`telegram.Bot.unpin_chat_message`. - .. versionchanged:: NEXT.VERSION + .. versionchanged:: 21.5 Now also passes :attr:`business_connection_id` to :meth:`telegram.Bot.pin_chat_message`. diff --git a/telegram/_messageentity.py b/telegram/_messageentity.py index 6e219537f..ae675e8e9 100644 --- a/telegram/_messageentity.py +++ b/telegram/_messageentity.py @@ -20,7 +20,7 @@ import copy import itertools -from typing import TYPE_CHECKING, Dict, Final, List, Optional, Sequence +from typing import TYPE_CHECKING, Dict, Final, List, Optional, Sequence, Tuple, Union from telegram import constants from telegram._telegramobject import TelegramObject @@ -32,6 +32,8 @@ from telegram._utils.types import JSONDict if TYPE_CHECKING: from telegram import Bot +_SEM = Sequence["MessageEntity"] + class MessageEntity(TelegramObject): """ @@ -146,9 +148,7 @@ class MessageEntity(TelegramObject): return super().de_json(data=data, bot=bot) @staticmethod - def adjust_message_entities_to_utf_16( - text: str, entities: Sequence["MessageEntity"] - ) -> Sequence["MessageEntity"]: + def adjust_message_entities_to_utf_16(text: str, entities: _SEM) -> _SEM: """Utility functionality for converting the offset and length of entities from Unicode (:obj:`str`) to UTF-16 (``utf-16-le`` encoded :obj:`bytes`). @@ -206,7 +206,7 @@ class MessageEntity(TelegramObject): text_slice = text[last_position:position] accumulated_length += len(text_slice.encode(TextEncoding.UTF_16_LE)) // 2 position_translation[position] = accumulated_length - # get the final output entites + # get the final output entities out = [] for entity in entities: translated_positions = position_translation[entity.offset] @@ -220,6 +220,143 @@ class MessageEntity(TelegramObject): out.append(new_entity) return out + @staticmethod + def shift_entities(by: Union[str, int], entities: _SEM) -> _SEM: + """Utility functionality for shifting the offset of entities by a given amount. + + Examples: + Shifting by an integer amount: + + .. code-block:: python + + text = "Hello, world!" + entities = [ + MessageEntity(offset=0, length=5, type=MessageEntity.BOLD), + MessageEntity(offset=7, length=5, type=MessageEntity.ITALIC), + ] + shifted_entities = MessageEntity.shift_entities(1, entities) + await bot.send_message( + chat_id=123, + text="!" + text, + entities=shifted_entities, + ) + + Shifting using a string: + + .. code-block:: python + + text = "Hello, world!" + prefix = "𝄢" + entities = [ + MessageEntity(offset=0, length=5, type=MessageEntity.BOLD), + MessageEntity(offset=7, length=5, type=MessageEntity.ITALIC), + ] + shifted_entities = MessageEntity.shift_entities(prefix, entities) + await bot.send_message( + chat_id=123, + text=prefix + text, + entities=shifted_entities, + ) + + Tip: + The :paramref:`entities` are *not* modified in place. The function returns a sequence + of new objects. + + .. versionadded:: 21.5 + + Args: + by (:obj:`str` | :obj:`int`): Either the amount to shift the offset by or + a string whose length will be used as the amount to shift the offset by. In this + case, UTF-16 encoding will be used to calculate the length. + entities (Sequence[:class:`telegram.MessageEntity`]): Sequence of entities + + Returns: + Sequence[:class:`telegram.MessageEntity`]: Sequence of entities with the offset shifted + """ + effective_shift = by if isinstance(by, int) else len(by.encode("utf-16-le")) // 2 + + out = [] + for entity in entities: + new_entity = copy.copy(entity) + with new_entity._unfrozen(): + new_entity.offset += effective_shift + out.append(new_entity) + return out + + @classmethod + def concatenate( + cls, + *args: Union[Tuple[str, _SEM], Tuple[str, _SEM, bool]], + ) -> Tuple[str, _SEM]: + """Utility functionality for concatenating two text along with their formatting entities. + + Tip: + This function is useful for prefixing an already formatted text with a new text and its + formatting entities. In particular, it automatically correctly handles UTF-16 encoding. + + Examples: + This example shows a callback function that can be used to add a prefix and suffix to + the message in a :class:`~telegram.ext.CallbackQueryHandler`: + + .. code-block:: python + + async def prefix_message(update: Update, context: ContextTypes.DEFAULT_TYPE): + prefix = "𠌕 bold 𝄢 italic underlined: 𝛙𝌢𑁍 | " + prefix_entities = [ + MessageEntity(offset=2, length=4, type=MessageEntity.BOLD), + MessageEntity(offset=9, length=6, type=MessageEntity.ITALIC), + MessageEntity(offset=28, length=3, type=MessageEntity.UNDERLINE), + ] + suffix = " | 𠌕 bold 𝄢 italic underlined: 𝛙𝌢𑁍" + suffix_entities = [ + MessageEntity(offset=5, length=4, type=MessageEntity.BOLD), + MessageEntity(offset=12, length=6, type=MessageEntity.ITALIC), + MessageEntity(offset=31, length=3, type=MessageEntity.UNDERLINE), + ] + + message = update.effective_message + first = (prefix, prefix_entities, True) + second = (message.text, message.entities) + third = (suffix, suffix_entities, True) + + new_text, new_entities = MessageEntity.concatenate(first, second, third) + await update.callback_query.edit_message_text( + text=new_text, + entities=new_entities, + ) + + Hint: + The entities are *not* modified in place. The function returns a + new sequence of objects. + + .. versionadded:: 21.5 + + Args: + *args (Tuple[:obj:`str`, Sequence[:class:`telegram.MessageEntity`]] | \ + Tuple[:obj:`str`, Sequence[:class:`telegram.MessageEntity`], :obj:`bool`]): + Arbitrary number of tuples containing the text and its entities to concatenate. + If the last element of the tuple is a :obj:`bool`, it is used to determine whether + to adjust the entities to UTF-16 via + :meth:`adjust_message_entities_to_utf_16`. UTF-16 adjustment is disabled by + default. + + Returns: + Tuple[:obj:`str`, Sequence[:class:`telegram.MessageEntity`]]: The concatenated text + and its entities + """ + output_text = "" + output_entities: List[MessageEntity] = [] + for arg in args: + text, entities = arg[0], arg[1] + + if len(arg) > 2 and arg[2] is True: + entities = cls.adjust_message_entities_to_utf_16(text, entities) + + output_entities.extend(cls.shift_entities(output_text, entities)) + output_text += text + + return output_text, output_entities + ALL_TYPES: Final[List[str]] = list(constants.MessageEntityType) """List[:obj:`str`]: A list of all available message entity types.""" BLOCKQUOTE: Final[str] = constants.MessageEntityType.BLOCKQUOTE diff --git a/telegram/_passport/credentials.py b/telegram/_passport/credentials.py index fab0b6eb2..7345991a5 100644 --- a/telegram/_passport/credentials.py +++ b/telegram/_passport/credentials.py @@ -112,7 +112,7 @@ class EncryptedCredentials(TelegramObject): Note: This object is decrypted only when originating from - :obj:`telegram.PassportData.decrypted_credentials`. + :attr:`telegram.PassportData.decrypted_credentials`. Args: data (:class:`telegram.Credentials` | :obj:`str`): Decrypted data with unique user's diff --git a/telegram/_passport/encryptedpassportelement.py b/telegram/_passport/encryptedpassportelement.py index b05003f2c..9f16d81e0 100644 --- a/telegram/_passport/encryptedpassportelement.py +++ b/telegram/_passport/encryptedpassportelement.py @@ -42,7 +42,7 @@ class EncryptedPassportElement(TelegramObject): Note: This object is decrypted only when originating from - :obj:`telegram.PassportData.decrypted_data`. + :attr:`telegram.PassportData.decrypted_data`. Args: type (:obj:`str`): Element type. One of "personal_details", "passport", "driver_license", diff --git a/telegram/_passport/passportfile.py b/telegram/_passport/passportfile.py index 61b704862..84a1ce201 100644 --- a/telegram/_passport/passportfile.py +++ b/telegram/_passport/passportfile.py @@ -203,7 +203,7 @@ class PassportFile(TelegramObject): """ Wrapper over :meth:`telegram.Bot.get_file`. Will automatically assign the correct credentials to the returned :class:`telegram.File` if originating from - :obj:`telegram.PassportData.decrypted_data`. + :attr:`telegram.PassportData.decrypted_data`. For the documentation of the arguments, please see :meth:`telegram.Bot.get_file`. diff --git a/telegram/_payment/stars.py b/telegram/_payment/stars.py index b176f2315..94f621d00 100644 --- a/telegram/_payment/stars.py +++ b/telegram/_payment/stars.py @@ -23,6 +23,7 @@ from datetime import datetime from typing import TYPE_CHECKING, Dict, Final, Optional, Sequence, Tuple, Type from telegram import constants +from telegram._paidmedia import PaidMedia from telegram._telegramobject import TelegramObject from telegram._user import User from telegram._utils import enum @@ -74,6 +75,17 @@ class RevenueWithdrawalState(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["RevenueWithdrawalState"]: + """Converts JSON data to the appropriate :class:`RevenueWithdrawalState` object, i.e. takes + care of selecting the correct subclass. + + Args: + data (Dict[:obj:`str`, ...]): The JSON data. + bot (:class:`telegram.Bot`): The bot associated with this object. + + Returns: + The Telegram object. + + """ data = cls._parse_data(data) if not data: @@ -150,6 +162,7 @@ class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["RevenueWithdrawalStateSucceeded"]: + """See :meth:`telegram.RevenueWithdrawalState.de_json`.""" data = cls._parse_data(data) if not data: @@ -260,13 +273,13 @@ class TransactionPartnerFragment(TransactionPartner): .. versionadded:: 21.4 Args: - withdrawal_state (:obj:`telegram.RevenueWithdrawalState`, optional): State of the + withdrawal_state (:class:`telegram.RevenueWithdrawalState`, optional): State of the transaction if the transaction is outgoing. Attributes: type (:obj:`str`): The type of the transaction partner, always :tg-const:`telegram.TransactionPartner.FRAGMENT`. - withdrawal_state (:obj:`telegram.RevenueWithdrawalState`): Optional. State of the + withdrawal_state (:class:`telegram.RevenueWithdrawalState`): Optional. State of the transaction if the transaction is outgoing. """ @@ -287,6 +300,7 @@ class TransactionPartnerFragment(TransactionPartner): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["TransactionPartnerFragment"]: + """See :meth:`telegram.TransactionPartner.de_json`.""" data = cls._parse_data(data) if not data: @@ -310,20 +324,33 @@ class TransactionPartnerUser(TransactionPartner): Args: user (:class:`telegram.User`): Information about the user. invoice_payload (:obj:`str`, optional): Bot-specified invoice payload. + paid_media (Sequence[:class:`telegram.PaidMedia`], optional): Information about the paid + media bought by the user. + + .. versionadded:: 21.5 Attributes: type (:obj:`str`): The type of the transaction partner, always :tg-const:`telegram.TransactionPartner.USER`. user (:class:`telegram.User`): Information about the user. invoice_payload (:obj:`str`): Optional. Bot-specified invoice payload. + paid_media (Tuple[:class:`telegram.PaidMedia`]): Optional. Information about the paid + media bought by the user. + + .. versionadded:: 21.5 """ - __slots__ = ("invoice_payload", "user") + __slots__ = ( + "invoice_payload", + "paid_media", + "user", + ) def __init__( self, user: "User", invoice_payload: Optional[str] = None, + paid_media: Optional[Sequence[PaidMedia]] = None, *, api_kwargs: Optional[JSONDict] = None, ) -> None: @@ -332,6 +359,7 @@ class TransactionPartnerUser(TransactionPartner): with self._unfrozen(): self.user: User = user self.invoice_payload: Optional[str] = invoice_payload + self.paid_media: Optional[Tuple[PaidMedia, ...]] = parse_sequence_arg(paid_media) self._id_attrs = ( self.type, self.user, @@ -341,12 +369,14 @@ class TransactionPartnerUser(TransactionPartner): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["TransactionPartnerUser"]: + """See :meth:`telegram.TransactionPartner.de_json`.""" data = cls._parse_data(data) if not data: return None data["user"] = User.de_json(data.get("user"), bot) + data["paid_media"] = PaidMedia.de_list(data.get("paid_media"), bot=bot) return super().de_json(data=data, bot=bot) # type: ignore[return-value] @@ -452,6 +482,7 @@ class StarTransaction(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["StarTransaction"]: + """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if not data: @@ -498,6 +529,7 @@ class StarTransactions(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["StarTransactions"]: + """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if data is None: diff --git a/telegram/_reaction.py b/telegram/_reaction.py index d1ba718f0..90de7823d 100644 --- a/telegram/_reaction.py +++ b/telegram/_reaction.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains objects that represents a Telegram ReactionType.""" -from typing import TYPE_CHECKING, Final, Literal, Optional, Union + +from typing import TYPE_CHECKING, Dict, Final, Literal, Optional, Type, Union from telegram import constants from telegram._telegramobject import TelegramObject @@ -30,16 +31,22 @@ if TYPE_CHECKING: class ReactionType(TelegramObject): """Base class for Telegram ReactionType Objects. - There exist :class:`telegram.ReactionTypeEmoji` and :class:`telegram.ReactionTypeCustomEmoji`. + There exist :class:`telegram.ReactionTypeEmoji`, :class:`telegram.ReactionTypeCustomEmoji` + and :class:`telegram.ReactionTypePaid`. .. versionadded:: 20.8 + .. versionchanged:: 21.5 + + Added paid reaction. Args: type (:obj:`str`): Type of the reaction. Can be - :attr:`~telegram.ReactionType.EMOJI` or :attr:`~telegram.ReactionType.CUSTOM_EMOJI`. + :attr:`~telegram.ReactionType.EMOJI`, :attr:`~telegram.ReactionType.CUSTOM_EMOJI` or + :attr:`~telegram.ReactionType.PAID`. Attributes: type (:obj:`str`): Type of the reaction. Can be - :attr:`~telegram.ReactionType.EMOJI` or :attr:`~telegram.ReactionType.CUSTOM_EMOJI`. + :attr:`~telegram.ReactionType.EMOJI`, :attr:`~telegram.ReactionType.CUSTOM_EMOJI` or + :attr:`~telegram.ReactionType.PAID`. """ @@ -49,11 +56,16 @@ class ReactionType(TelegramObject): """:const:`telegram.constants.ReactionType.EMOJI`""" CUSTOM_EMOJI: Final[constants.ReactionType] = constants.ReactionType.CUSTOM_EMOJI """:const:`telegram.constants.ReactionType.CUSTOM_EMOJI`""" + PAID: Final[constants.ReactionType] = constants.ReactionType.PAID + """:const:`telegram.constants.ReactionType.PAID` + + .. versionadded:: 21.5 + """ def __init__( self, type: Union[ # pylint: disable=redefined-builtin - Literal["emoji", "custom_emoji"], constants.ReactionType + Literal["emoji", "custom_emoji", "paid"], constants.ReactionType ], *, api_kwargs: Optional[JSONDict] = None, @@ -71,14 +83,20 @@ class ReactionType(TelegramObject): """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) - if not data: + if data is None: return None - if cls is ReactionType and data.get("type") in [cls.EMOJI, cls.CUSTOM_EMOJI]: - reaction_type = data.pop("type") - if reaction_type == cls.EMOJI: - return ReactionTypeEmoji.de_json(data=data, bot=bot) - return ReactionTypeCustomEmoji.de_json(data=data, bot=bot) + if not data and cls is ReactionType: + return None + + _class_mapping: Dict[str, Type[ReactionType]] = { + cls.EMOJI: ReactionTypeEmoji, + cls.CUSTOM_EMOJI: ReactionTypeCustomEmoji, + cls.PAID: ReactionTypePaid, + } + + if cls is ReactionType and data.get("type") in _class_mapping: + return _class_mapping[data.pop("type")].de_json(data, bot) return super().de_json(data=data, bot=bot) @@ -152,6 +170,24 @@ class ReactionTypeCustomEmoji(ReactionType): self._id_attrs = (self.custom_emoji_id,) +class ReactionTypePaid(ReactionType): + """ + The reaction is paid. + + .. versionadded:: 21.5 + + Attributes: + type (:obj:`str`): Type of the reaction, + always :tg-const:`telegram.ReactionType.PAID`. + """ + + __slots__ = () + + def __init__(self, *, api_kwargs: Optional[JSONDict] = None): + super().__init__(type=ReactionType.PAID, api_kwargs=api_kwargs) + self._freeze() + + class ReactionCount(TelegramObject): """This class represents a reaction added to a message along with the number of times it was added. diff --git a/telegram/_reply.py b/telegram/_reply.py index 222e522a6..65e426657 100644 --- a/telegram/_reply.py +++ b/telegram/_reply.py @@ -250,7 +250,7 @@ class ExternalReplyInfo(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["ExternalReplyInfo"]: - """See :obj:`telegram.TelegramObject.de_json`.""" + """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if data is None: @@ -299,7 +299,8 @@ class TextQuote(TelegramObject): message. position (:obj:`int`): Approximate quote position in the original message in UTF-16 code units as specified by the sender. - entities (Sequence[:obj:`telegram.MessageEntity`], optional): Special entities that appear + entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that + appear in the quote. Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are kept in quotes. is_manual (:obj:`bool`, optional): :obj:`True`, if the quote was chosen manually by the @@ -310,7 +311,7 @@ class TextQuote(TelegramObject): message. position (:obj:`int`): Approximate quote position in the original message in UTF-16 code units as specified by the sender. - entities (Tuple[:obj:`telegram.MessageEntity`]): Optional. Special entities that appear + entities (Tuple[:class:`telegram.MessageEntity`]): Optional. Special entities that appear in the quote. Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are kept in quotes. is_manual (:obj:`bool`): Optional. :obj:`True`, if the quote was chosen manually by the @@ -351,7 +352,7 @@ class TextQuote(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["TextQuote"]: - """See :obj:`telegram.TelegramObject.de_json`.""" + """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if data is None: @@ -387,7 +388,8 @@ class ReplyParameters(TelegramObject): quote_parse_mode (:obj:`str`, optional): Mode for parsing entities in the quote. See :wiki:`formatting options ` for more details. - quote_entities (Sequence[:obj:`telegram.MessageEntity`], optional): A JSON-serialized list + quote_entities (Sequence[:class:`telegram.MessageEntity`], optional): A JSON-serialized + list of special entities that appear in the quote. It can be specified instead of :paramref:`quote_parse_mode`. quote_position (:obj:`int`, optional): Position of the quote in the original message in @@ -409,8 +411,8 @@ class ReplyParameters(TelegramObject): quote_parse_mode (:obj:`str`): Optional. Mode for parsing entities in the quote. See :wiki:`formatting options ` for more details. - quote_entities (Tuple[:obj:`telegram.MessageEntity`]): Optional. A JSON-serialized list of - special entities that appear in the quote. It can be specified instead of + quote_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. A JSON-serialized list + of special entities that appear in the quote. It can be specified instead of :paramref:`quote_parse_mode`. quote_position (:obj:`int`): Optional. Position of the quote in the original message in UTF-16 code units. @@ -458,7 +460,7 @@ class ReplyParameters(TelegramObject): def de_json( cls, data: Optional[JSONDict], bot: Optional["Bot"] = None ) -> Optional["ReplyParameters"]: - """See :obj:`telegram.TelegramObject.de_json`.""" + """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if data is None: diff --git a/telegram/_telegramobject.py b/telegram/_telegramobject.py index 6666b49b2..504075532 100644 --- a/telegram/_telegramobject.py +++ b/telegram/_telegramobject.py @@ -354,7 +354,7 @@ class TelegramObject: memodict (:obj:`dict`): A dictionary that maps objects to their copies. Returns: - :obj:`telegram.TelegramObject`: The copied object. + :class:`telegram.TelegramObject`: The copied object. """ bot = self._bot # Save bot so we can set it after copying self.set_bot(None) # set to None so it is not deepcopied diff --git a/telegram/_user.py b/telegram/_user.py index 50dd66870..075c4f128 100644 --- a/telegram/_user.py +++ b/telegram/_user.py @@ -100,7 +100,7 @@ class User(TelegramObject): has_main_web_app (:obj:`bool`, optional): :obj:`True`, if the bot has the main Web App. Returned only in :meth:`telegram.Bot.get_me`. - .. versionadded:: NEXT.VERSION + .. versionadded:: 21.5 Attributes: id (:obj:`int`): Unique identifier for this user or bot. @@ -131,7 +131,7 @@ class User(TelegramObject): has_main_web_app (:obj:`bool`) Optional. :obj:`True`, if the bot has the main Web App. Returned only in :meth:`telegram.Bot.get_me`. - .. versionadded:: NEXT.VERSION + .. versionadded:: 21.5 .. |user_chat_id_note| replace:: This shortcuts build on the assumption that :attr:`User.id` coincides with the :attr:`Chat.id` of the private chat with the user. This has been the diff --git a/telegram/_utils/strings.py b/telegram/_utils/strings.py index c57e4e48b..9c386247e 100644 --- a/telegram/_utils/strings.py +++ b/telegram/_utils/strings.py @@ -33,7 +33,7 @@ from telegram._utils.enum import StringEnum class TextEncoding(StringEnum): """This enum contains encoding schemes for text. - .. versionadded:: NEXT.VERSION + .. versionadded:: 21.5 """ __slots__ = () diff --git a/telegram/_version.py b/telegram/_version.py index ec3f5618c..20043c830 100644 --- a/telegram/_version.py +++ b/telegram/_version.py @@ -51,6 +51,6 @@ class Version(NamedTuple): __version_info__: Final[Version] = Version( - major=21, minor=4, micro=0, releaselevel="final", serial=0 + major=21, minor=5, micro=0, releaselevel="final", serial=0 ) __version__: Final[str] = str(__version_info__) diff --git a/telegram/constants.py b/telegram/constants.py index 1aba1f2a9..52d69aaca 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -54,6 +54,7 @@ __all__ = [ "ChatLimit", "ChatMemberStatus", "ChatPhotoSize", + "ChatSubscriptionLimit", "ChatType", "ContactLimit", "CustomEmojiStickerLimit", @@ -151,7 +152,7 @@ class _AccentColor(NamedTuple): #: :data:`telegram.__bot_api_version_info__`. #: #: .. versionadded:: 20.0 -BOT_API_VERSION_INFO: Final[_BotAPIVersion] = _BotAPIVersion(major=7, minor=8) +BOT_API_VERSION_INFO: Final[_BotAPIVersion] = _BotAPIVersion(major=7, minor=9) #: :obj:`str`: Telegram Bot API #: version supported by this version of `python-telegram-bot`. Also available as #: :data:`telegram.__bot_api_version__`. @@ -2903,6 +2904,11 @@ class ReactionType(StringEnum): """:obj:`str`: A :class:`telegram.ReactionType` with a normal emoji.""" CUSTOM_EMOJI = "custom_emoji" """:obj:`str`: A :class:`telegram.ReactionType` with a custom emoji.""" + PAID = "paid" + """:obj:`str`: A :class:`telegram.ReactionType` with a paid reaction. + + .. versionadded:: 21.5 + """ class ReactionEmoji(StringEnum): @@ -3096,3 +3102,22 @@ class BackgroundFillType(StringEnum): """:obj:`str`: A :class:`telegram.BackgroundFill` with gradient fill.""" FREEFORM_GRADIENT = "freeform_gradient" """:obj:`str`: A :class:`telegram.BackgroundFill` with freeform_gradient fill.""" + + +class ChatSubscriptionLimit(IntEnum): + """This enum contains limitations for + :paramref:`telegram.Bot.create_chat_subscription_invite_link.subscription_period` and + :paramref:`telegram.Bot.create_chat_subscription_invite_link.subscription_price`. + The enum members of this enumeration are instances of :class:`int` and can be treated as such. + + .. versionadded:: 21.5 + """ + + __slots__ = () + + SUBSCRIPTION_PERIOD = 2592000 + """:obj:`int`: The number of seconds the subscription will be active.""" + MIN_PRICE = 1 + """:obj:`int`: Amount of stars a user pays, minimum amount the subscription can be set to.""" + MAX_PRICE = 2500 + """:obj:`int`: Amount of stars a user pays, maximum amount the subscription can be set to.""" diff --git a/telegram/ext/_extbot.py b/telegram/ext/_extbot.py index d85d8822d..76b17bad0 100644 --- a/telegram/ext/_extbot.py +++ b/telegram/ext/_extbot.py @@ -4234,6 +4234,7 @@ class ExtBot(Bot, Generic[RLARGS]): protect_content: ODVInput[bool] = DEFAULT_NONE, reply_parameters: Optional["ReplyParameters"] = None, reply_markup: Optional[ReplyMarkup] = None, + business_connection_id: Optional[str] = None, *, allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE, reply_to_message_id: Optional[int] = None, @@ -4263,6 +4264,57 @@ class ExtBot(Bot, Generic[RLARGS]): connect_timeout=connect_timeout, pool_timeout=pool_timeout, api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + business_connection_id=business_connection_id, + ) + + async def create_chat_subscription_invite_link( + self, + chat_id: Union[str, int], + subscription_period: int, + subscription_price: int, + name: Optional[str] = None, + *, + read_timeout: ODVInput[float] = DEFAULT_NONE, + write_timeout: ODVInput[float] = DEFAULT_NONE, + connect_timeout: ODVInput[float] = DEFAULT_NONE, + pool_timeout: ODVInput[float] = DEFAULT_NONE, + api_kwargs: Optional[JSONDict] = None, + rate_limit_args: Optional[RLARGS] = None, + ) -> ChatInviteLink: + return await super().create_chat_subscription_invite_link( + chat_id=chat_id, + subscription_period=subscription_period, + subscription_price=subscription_price, + name=name, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + + async def edit_chat_subscription_invite_link( + self, + chat_id: Union[str, int], + invite_link: Union[str, "ChatInviteLink"], + name: Optional[str] = None, + *, + read_timeout: ODVInput[float] = DEFAULT_NONE, + write_timeout: ODVInput[float] = DEFAULT_NONE, + connect_timeout: ODVInput[float] = DEFAULT_NONE, + pool_timeout: ODVInput[float] = DEFAULT_NONE, + api_kwargs: Optional[JSONDict] = None, + rate_limit_args: Optional[RLARGS] = None, + ) -> ChatInviteLink: + return await super().edit_chat_subscription_invite_link( + chat_id=chat_id, + invite_link=invite_link, + name=name, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), ) # updated camelCase aliases @@ -4388,4 +4440,6 @@ class ExtBot(Bot, Generic[RLARGS]): replaceStickerInSet = replace_sticker_in_set refundStarPayment = refund_star_payment getStarTransactions = get_star_transactions + createChatSubscriptionInviteLink = create_chat_subscription_invite_link + editChatSubscriptionInviteLink = edit_chat_subscription_invite_link sendPaidMedia = send_paid_media diff --git a/telegram/ext/_handlers/callbackqueryhandler.py b/telegram/ext/_handlers/callbackqueryhandler.py index c8fb0e7b3..a149739a2 100644 --- a/telegram/ext/_handlers/callbackqueryhandler.py +++ b/telegram/ext/_handlers/callbackqueryhandler.py @@ -58,7 +58,7 @@ class CallbackQueryHandler(BaseHandler[Update, CCT]): `~telegram.CallbackQuery.game_short_name` or :attr:`~telegram.CallbackQuery.data` matching the defined pattern will be handled - .. versionadded:: NEXT.VERSION + .. versionadded:: 21.5 Warning: When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom @@ -100,7 +100,7 @@ class CallbackQueryHandler(BaseHandler[Update, CCT]): :attr:`telegram.CallbackQuery.game_short_name` to determine if an update should be handled by this handler. - .. versionadded:: NEXT.VERSION + .. versionadded:: 21.5 block (:obj:`bool`, optional): Determines whether the return value of the callback should be awaited before processing the next handler in :meth:`telegram.ext.Application.process_update`. Defaults to :obj:`True`. diff --git a/telegram/ext/_updater.py b/telegram/ext/_updater.py index bdf14e0a9..30635e40a 100644 --- a/telegram/ext/_updater.py +++ b/telegram/ext/_updater.py @@ -763,7 +763,6 @@ class Updater(AsyncContextManager["Updater"]): _LOGGER.exception("Invalid token; aborting") raise except TelegramError as telegram_exc: - _LOGGER.exception("Error while %s:", description) on_err_cb(telegram_exc) # increase waiting times on subsequent errors up to 30secs diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index de105e28b..fe5b8a79d 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -302,7 +302,7 @@ class BaseFilter: class MessageFilter(BaseFilter): """Base class for all Message Filters. In contrast to :class:`UpdateFilter`, the object passed - to :meth:`filter` is :obj:`telegram.Update.effective_message`. + to :meth:`filter` is :attr:`telegram.Update.effective_message`. Please see :class:`BaseFilter` for details on how to create custom filters. diff --git a/telegram/request/_requestdata.py b/telegram/request/_requestdata.py index a6b8752ee..71b2654e5 100644 --- a/telegram/request/_requestdata.py +++ b/telegram/request/_requestdata.py @@ -131,7 +131,7 @@ class RequestData: def multipart_data(self) -> UploadFileDict: """Gives the files contained in this object as mapping of part name to encoded content. - .. versionchanged:: NEXT.VERSION + .. versionchanged:: 21.5 Content may now be a file handle. """ multipart_data: UploadFileDict = {} diff --git a/telegram/request/_requestparameter.py b/telegram/request/_requestparameter.py index c3d19bdbd..88ed231c0 100644 --- a/telegram/request/_requestparameter.py +++ b/telegram/request/_requestparameter.py @@ -79,7 +79,7 @@ class RequestParameter: def multipart_data(self) -> Optional[UploadFileDict]: """A dict with the file data to upload, if any. - .. versionchanged:: NEXT.VERSION + .. versionchanged:: 21.5 Content may now be a file handle. """ if not self.input_files: diff --git a/tests/_files/test_animation.py b/tests/_files/test_animation.py index 5e991eaba..493d9bfae 100644 --- a/tests/_files/test_animation.py +++ b/tests/_files/test_animation.py @@ -51,7 +51,7 @@ async def animation(bot, chat_id): ).animation -class TestAnimationBase: +class AnimationTestBase: animation_file_id = "CgADAQADngIAAuyVeEez0xRovKi9VAI" animation_file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e" width = 320 @@ -66,7 +66,7 @@ class TestAnimationBase: caption = "Test *animation*" -class TestAnimationWithoutRequest(TestAnimationBase): +class TestAnimationWithoutRequest(AnimationTestBase): def test_slot_behaviour(self, animation): for attr in animation.__slots__: assert getattr(animation, attr, "err") != "err", f"got extra slot '{attr}'" @@ -219,7 +219,7 @@ class TestAnimationWithoutRequest(TestAnimationBase): ) -class TestAnimationWithRequest(TestAnimationBase): +class TestAnimationWithRequest(AnimationTestBase): async def test_send_all_args(self, bot, chat_id, animation_file, animation, thumb_file): message = await bot.send_animation( chat_id, diff --git a/tests/_files/test_audio.py b/tests/_files/test_audio.py index ced1a1d5d..f6b76c1f0 100644 --- a/tests/_files/test_audio.py +++ b/tests/_files/test_audio.py @@ -49,7 +49,7 @@ async def audio(bot, chat_id): return (await bot.send_audio(chat_id, audio=f, read_timeout=50, thumbnail=thumb)).audio -class TestAudioBase: +class AudioTestBase: caption = "Test *audio*" performer = "Leandro Toledo" title = "Teste" @@ -67,7 +67,7 @@ class TestAudioBase: audio_file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e" -class TestAudioWithoutRequest(TestAudioBase): +class TestAudioWithoutRequest(AudioTestBase): def test_slot_behaviour(self, audio): for attr in audio.__slots__: assert getattr(audio, attr, "err") != "err", f"got extra slot '{attr}'" @@ -222,7 +222,7 @@ class TestAudioWithoutRequest(TestAudioBase): await default_bot.send_audio(chat_id, audio, reply_parameters=ReplyParameters(**kwargs)) -class TestAudioWithRequest(TestAudioBase): +class TestAudioWithRequest(AudioTestBase): async def test_send_all_args(self, bot, chat_id, audio_file, thumb_file): message = await bot.send_audio( chat_id, diff --git a/tests/_files/test_chatphoto.py b/tests/_files/test_chatphoto.py index 27f3a26ba..5deaae38f 100644 --- a/tests/_files/test_chatphoto.py +++ b/tests/_files/test_chatphoto.py @@ -52,7 +52,7 @@ async def chat_photo(bot, super_group_id): ) -class TestChatPhotoBase: +class ChatPhotoTestBase: chatphoto_small_file_id = "smallCgADAQADngIAAuyVeEez0xRovKi9VAI" chatphoto_big_file_id = "bigCgADAQADngIAAuyVeEez0xRovKi9VAI" chatphoto_small_file_unique_id = "smalladc3145fd2e84d95b64d68eaa22aa33e" @@ -60,7 +60,7 @@ class TestChatPhotoBase: chatphoto_file_url = "https://python-telegram-bot.org/static/testfiles/telegram.jpg" -class TestChatPhotoWithoutRequest(TestChatPhotoBase): +class TestChatPhotoWithoutRequest(ChatPhotoTestBase): def test_slot_behaviour(self, chat_photo): for attr in chat_photo.__slots__: assert getattr(chat_photo, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/_files/test_contact.py b/tests/_files/test_contact.py index a4793c3fa..cb5777eb4 100644 --- a/tests/_files/test_contact.py +++ b/tests/_files/test_contact.py @@ -32,21 +32,21 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def contact(): return Contact( - TestContactBase.phone_number, - TestContactBase.first_name, - TestContactBase.last_name, - TestContactBase.user_id, + ContactTestBase.phone_number, + ContactTestBase.first_name, + ContactTestBase.last_name, + ContactTestBase.user_id, ) -class TestContactBase: +class ContactTestBase: phone_number = "+11234567890" first_name = "Leandro" last_name = "Toledo" user_id = 23 -class TestContactWithoutRequest(TestContactBase): +class TestContactWithoutRequest(ContactTestBase): def test_slot_behaviour(self, contact): for attr in contact.__slots__: assert getattr(contact, attr, "err") != "err", f"got extra slot '{attr}'" @@ -156,7 +156,7 @@ class TestContactWithoutRequest(TestContactBase): ) -class TestContactWithRequest(TestContactBase): +class TestContactWithRequest(ContactTestBase): @pytest.mark.parametrize( ("default_bot", "custom"), [ diff --git a/tests/_files/test_document.py b/tests/_files/test_document.py index 913e290f9..02f60ac46 100644 --- a/tests/_files/test_document.py +++ b/tests/_files/test_document.py @@ -49,7 +49,7 @@ async def document(bot, chat_id): return (await bot.send_document(chat_id, document=f, read_timeout=50)).document -class TestDocumentBase: +class DocumentTestBase: caption = "DocumentTest - *Caption*" document_file_url = "https://python-telegram-bot.org/static/testfiles/telegram.gif" file_size = 12948 @@ -62,7 +62,7 @@ class TestDocumentBase: document_file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e" -class TestDocumentWithoutRequest(TestDocumentBase): +class TestDocumentWithoutRequest(DocumentTestBase): def test_slot_behaviour(self, document): for attr in document.__slots__: assert getattr(document, attr, "err") != "err", f"got extra slot '{attr}'" @@ -218,7 +218,7 @@ class TestDocumentWithoutRequest(TestDocumentBase): assert await document.get_file() -class TestDocumentWithRequest(TestDocumentBase): +class TestDocumentWithRequest(DocumentTestBase): async def test_error_send_empty_file(self, bot, chat_id): with Path(os.devnull).open("rb") as f, pytest.raises(TelegramError): await bot.send_document(chat_id=chat_id, document=f) diff --git a/tests/_files/test_file.py b/tests/_files/test_file.py index 86979e418..ae9d92c04 100644 --- a/tests/_files/test_file.py +++ b/tests/_files/test_file.py @@ -31,10 +31,10 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def file(bot): file = File( - TestFileBase.file_id, - TestFileBase.file_unique_id, - file_path=TestFileBase.file_path, - file_size=TestFileBase.file_size, + FileTestBase.file_id, + FileTestBase.file_unique_id, + file_path=FileTestBase.file_path, + file_size=FileTestBase.file_size, ) file.set_bot(bot) file._unfreeze() @@ -51,10 +51,10 @@ def encrypted_file(bot): "Pt7fKPgYWKA/7a8E64Ea1X8C+Wf7Ky1tF4ANBl63vl4=", ) ef = File( - TestFileBase.file_id, - TestFileBase.file_unique_id, - TestFileBase.file_size, - TestFileBase.file_path, + FileTestBase.file_id, + FileTestBase.file_unique_id, + FileTestBase.file_size, + FileTestBase.file_path, ) ef.set_bot(bot) ef.set_credentials(fc) @@ -69,9 +69,9 @@ def encrypted_local_file(bot): "Pt7fKPgYWKA/7a8E64Ea1X8C+Wf7Ky1tF4ANBl63vl4=", ) ef = File( - TestFileBase.file_id, - TestFileBase.file_unique_id, - TestFileBase.file_size, + FileTestBase.file_id, + FileTestBase.file_unique_id, + FileTestBase.file_size, file_path=str(data_file("image_encrypted.jpg")), ) ef.set_bot(bot) @@ -82,16 +82,16 @@ def encrypted_local_file(bot): @pytest.fixture(scope="module") def local_file(bot): file = File( - TestFileBase.file_id, - TestFileBase.file_unique_id, + FileTestBase.file_id, + FileTestBase.file_unique_id, file_path=str(data_file("local_file.txt")), - file_size=TestFileBase.file_size, + file_size=FileTestBase.file_size, ) file.set_bot(bot) return file -class TestFileBase: +class FileTestBase: file_id = "NOTVALIDDOESNOTMATTER" file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e" file_path = ( @@ -101,7 +101,7 @@ class TestFileBase: file_content = "Saint-Saëns".encode() # Intentionally contains unicode chars. -class TestFileWithoutRequest(TestFileBase): +class TestFileWithoutRequest(FileTestBase): def test_slot_behaviour(self, file): for attr in file.__slots__: assert getattr(file, attr, "err") != "err", f"got extra slot '{attr}'" @@ -273,7 +273,7 @@ class TestFileWithoutRequest(TestFileBase): assert buf2[: len(buf)] == buf -class TestFileWithRequest(TestFileBase): +class TestFileWithRequest(FileTestBase): async def test_error_get_empty_file_id(self, bot): with pytest.raises(TelegramError): await bot.get_file(file_id="") diff --git a/tests/_files/test_inputmedia.py b/tests/_files/test_inputmedia.py index d25a679ff..ff398113a 100644 --- a/tests/_files/test_inputmedia.py +++ b/tests/_files/test_inputmedia.py @@ -68,94 +68,94 @@ from .test_video import video, video_file # noqa: F401 @pytest.fixture(scope="module") def input_media_video(class_thumb_file): return InputMediaVideo( - media=TestInputMediaVideoBase.media, - caption=TestInputMediaVideoBase.caption, - width=TestInputMediaVideoBase.width, - height=TestInputMediaVideoBase.height, - duration=TestInputMediaVideoBase.duration, - parse_mode=TestInputMediaVideoBase.parse_mode, - caption_entities=TestInputMediaVideoBase.caption_entities, + media=InputMediaVideoTestBase.media, + caption=InputMediaVideoTestBase.caption, + width=InputMediaVideoTestBase.width, + height=InputMediaVideoTestBase.height, + duration=InputMediaVideoTestBase.duration, + parse_mode=InputMediaVideoTestBase.parse_mode, + caption_entities=InputMediaVideoTestBase.caption_entities, thumbnail=class_thumb_file, - supports_streaming=TestInputMediaVideoBase.supports_streaming, - has_spoiler=TestInputMediaVideoBase.has_spoiler, - show_caption_above_media=TestInputMediaVideoBase.show_caption_above_media, + supports_streaming=InputMediaVideoTestBase.supports_streaming, + has_spoiler=InputMediaVideoTestBase.has_spoiler, + show_caption_above_media=InputMediaVideoTestBase.show_caption_above_media, ) @pytest.fixture(scope="module") def input_media_photo(): return InputMediaPhoto( - media=TestInputMediaPhotoBase.media, - caption=TestInputMediaPhotoBase.caption, - parse_mode=TestInputMediaPhotoBase.parse_mode, - caption_entities=TestInputMediaPhotoBase.caption_entities, - has_spoiler=TestInputMediaPhotoBase.has_spoiler, - show_caption_above_media=TestInputMediaPhotoBase.show_caption_above_media, + media=InputMediaPhotoTestBase.media, + caption=InputMediaPhotoTestBase.caption, + parse_mode=InputMediaPhotoTestBase.parse_mode, + caption_entities=InputMediaPhotoTestBase.caption_entities, + has_spoiler=InputMediaPhotoTestBase.has_spoiler, + show_caption_above_media=InputMediaPhotoTestBase.show_caption_above_media, ) @pytest.fixture(scope="module") def input_media_animation(class_thumb_file): return InputMediaAnimation( - media=TestInputMediaAnimationBase.media, - caption=TestInputMediaAnimationBase.caption, - parse_mode=TestInputMediaAnimationBase.parse_mode, - caption_entities=TestInputMediaAnimationBase.caption_entities, - width=TestInputMediaAnimationBase.width, - height=TestInputMediaAnimationBase.height, + media=InputMediaAnimationTestBase.media, + caption=InputMediaAnimationTestBase.caption, + parse_mode=InputMediaAnimationTestBase.parse_mode, + caption_entities=InputMediaAnimationTestBase.caption_entities, + width=InputMediaAnimationTestBase.width, + height=InputMediaAnimationTestBase.height, thumbnail=class_thumb_file, - duration=TestInputMediaAnimationBase.duration, - has_spoiler=TestInputMediaAnimationBase.has_spoiler, - show_caption_above_media=TestInputMediaAnimationBase.show_caption_above_media, + duration=InputMediaAnimationTestBase.duration, + has_spoiler=InputMediaAnimationTestBase.has_spoiler, + show_caption_above_media=InputMediaAnimationTestBase.show_caption_above_media, ) @pytest.fixture(scope="module") def input_media_audio(class_thumb_file): return InputMediaAudio( - media=TestInputMediaAudioBase.media, - caption=TestInputMediaAudioBase.caption, - duration=TestInputMediaAudioBase.duration, - performer=TestInputMediaAudioBase.performer, - title=TestInputMediaAudioBase.title, + media=InputMediaAudioTestBase.media, + caption=InputMediaAudioTestBase.caption, + duration=InputMediaAudioTestBase.duration, + performer=InputMediaAudioTestBase.performer, + title=InputMediaAudioTestBase.title, thumbnail=class_thumb_file, - parse_mode=TestInputMediaAudioBase.parse_mode, - caption_entities=TestInputMediaAudioBase.caption_entities, + parse_mode=InputMediaAudioTestBase.parse_mode, + caption_entities=InputMediaAudioTestBase.caption_entities, ) @pytest.fixture(scope="module") def input_media_document(class_thumb_file): return InputMediaDocument( - media=TestInputMediaDocumentBase.media, - caption=TestInputMediaDocumentBase.caption, + media=InputMediaDocumentTestBase.media, + caption=InputMediaDocumentTestBase.caption, thumbnail=class_thumb_file, - parse_mode=TestInputMediaDocumentBase.parse_mode, - caption_entities=TestInputMediaDocumentBase.caption_entities, - disable_content_type_detection=TestInputMediaDocumentBase.disable_content_type_detection, + parse_mode=InputMediaDocumentTestBase.parse_mode, + caption_entities=InputMediaDocumentTestBase.caption_entities, + disable_content_type_detection=InputMediaDocumentTestBase.disable_content_type_detection, ) @pytest.fixture(scope="module") def input_paid_media_photo(): return InputPaidMediaPhoto( - media=TestInputMediaPhotoBase.media, + media=InputMediaPhotoTestBase.media, ) @pytest.fixture(scope="module") def input_paid_media_video(class_thumb_file): return InputPaidMediaVideo( - media=TestInputMediaVideoBase.media, + media=InputMediaVideoTestBase.media, thumbnail=class_thumb_file, - width=TestInputMediaVideoBase.width, - height=TestInputMediaVideoBase.height, - duration=TestInputMediaVideoBase.duration, - supports_streaming=TestInputMediaVideoBase.supports_streaming, + width=InputMediaVideoTestBase.width, + height=InputMediaVideoTestBase.height, + duration=InputMediaVideoTestBase.duration, + supports_streaming=InputMediaVideoTestBase.supports_streaming, ) -class TestInputMediaVideoBase: +class InputMediaVideoTestBase: type_ = "video" media = "NOTAREALFILEID" caption = "My Caption" @@ -169,7 +169,7 @@ class TestInputMediaVideoBase: show_caption_above_media = True -class TestInputMediaVideoWithoutRequest(TestInputMediaVideoBase): +class TestInputMediaVideoWithoutRequest(InputMediaVideoTestBase): def test_slot_behaviour(self, input_media_video): inst = input_media_video for attr in inst.__slots__: @@ -258,7 +258,7 @@ class TestInputMediaVideoWithoutRequest(TestInputMediaVideoBase): ) -class TestInputMediaPhotoBase: +class InputMediaPhotoTestBase: type_ = "photo" media = "NOTAREALFILEID" caption = "My Caption" @@ -268,7 +268,7 @@ class TestInputMediaPhotoBase: show_caption_above_media = True -class TestInputMediaPhotoWithoutRequest(TestInputMediaPhotoBase): +class TestInputMediaPhotoWithoutRequest(InputMediaPhotoTestBase): def test_slot_behaviour(self, input_media_photo): inst = input_media_photo for attr in inst.__slots__: @@ -322,7 +322,7 @@ class TestInputMediaPhotoWithoutRequest(TestInputMediaPhotoBase): assert input_media_photo.media == data_file("telegram.mp4").as_uri() -class TestInputMediaAnimationBase: +class InputMediaAnimationTestBase: type_ = "animation" media = "NOTAREALFILEID" caption = "My Caption" @@ -335,7 +335,7 @@ class TestInputMediaAnimationBase: show_caption_above_media = True -class TestInputMediaAnimationWithoutRequest(TestInputMediaAnimationBase): +class TestInputMediaAnimationWithoutRequest(InputMediaAnimationTestBase): def test_slot_behaviour(self, input_media_animation): inst = input_media_animation for attr in inst.__slots__: @@ -396,7 +396,7 @@ class TestInputMediaAnimationWithoutRequest(TestInputMediaAnimationBase): assert input_media_animation.thumbnail == data_file("telegram.jpg").as_uri() -class TestInputMediaAudioBase: +class InputMediaAudioTestBase: type_ = "audio" media = "NOTAREALFILEID" caption = "My Caption" @@ -407,7 +407,7 @@ class TestInputMediaAudioBase: caption_entities = [MessageEntity(MessageEntity.BOLD, 0, 2)] -class TestInputMediaAudioWithoutRequest(TestInputMediaAudioBase): +class TestInputMediaAudioWithoutRequest(InputMediaAudioTestBase): def test_slot_behaviour(self, input_media_audio): inst = input_media_audio for attr in inst.__slots__: @@ -467,7 +467,7 @@ class TestInputMediaAudioWithoutRequest(TestInputMediaAudioBase): assert input_media_audio.thumbnail == data_file("telegram.jpg").as_uri() -class TestInputMediaDocumentBase: +class InputMediaDocumentTestBase: type_ = "document" media = "NOTAREALFILEID" caption = "My Caption" @@ -476,7 +476,7 @@ class TestInputMediaDocumentBase: disable_content_type_detection = True -class TestInputMediaDocumentWithoutRequest(TestInputMediaDocumentBase): +class TestInputMediaDocumentWithoutRequest(InputMediaDocumentTestBase): def test_slot_behaviour(self, input_media_document): inst = input_media_document for attr in inst.__slots__: @@ -535,7 +535,7 @@ class TestInputMediaDocumentWithoutRequest(TestInputMediaDocumentBase): assert input_media_document.thumbnail == data_file("telegram.jpg").as_uri() -class TestInputPaidMediaPhotoWithoutRequest(TestInputMediaPhotoBase): +class TestInputPaidMediaPhotoWithoutRequest(InputMediaPhotoTestBase): def test_slot_behaviour(self, input_paid_media_photo): inst = input_paid_media_photo for attr in inst.__slots__: @@ -568,7 +568,7 @@ class TestInputPaidMediaPhotoWithoutRequest(TestInputMediaPhotoBase): assert input_paid_media_photo.media == data_file("telegram.jpg").as_uri() -class TestInputPaidMediaVideoWithoutRequest(TestInputMediaVideoBase): +class TestInputPaidMediaVideoWithoutRequest(InputMediaVideoTestBase): def test_slot_behaviour(self, input_paid_media_video): inst = input_paid_media_video for attr in inst.__slots__: diff --git a/tests/_files/test_inputsticker.py b/tests/_files/test_inputsticker.py index 680a01670..bd45bbdea 100644 --- a/tests/_files/test_inputsticker.py +++ b/tests/_files/test_inputsticker.py @@ -29,15 +29,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def input_sticker(): return InputSticker( - sticker=TestInputStickerBase.sticker, - emoji_list=TestInputStickerBase.emoji_list, - mask_position=TestInputStickerBase.mask_position, - keywords=TestInputStickerBase.keywords, - format=TestInputStickerBase.format, + sticker=InputStickerTestBase.sticker, + emoji_list=InputStickerTestBase.emoji_list, + mask_position=InputStickerTestBase.mask_position, + keywords=InputStickerTestBase.keywords, + format=InputStickerTestBase.format, ) -class TestInputStickerBase: +class InputStickerTestBase: sticker = "fake_file_id" emoji_list = ("👍", "👎") mask_position = MaskPosition("forehead", 0.5, 0.5, 0.5) @@ -45,7 +45,7 @@ class TestInputStickerBase: format = "static" -class TestInputStickerWithoutRequest(TestInputStickerBase): +class TestInputStickerWithoutRequest(InputStickerTestBase): def test_slot_behaviour(self, input_sticker): inst = input_sticker for attr in inst.__slots__: diff --git a/tests/_files/test_location.py b/tests/_files/test_location.py index f9a7e4c6a..72c6f7200 100644 --- a/tests/_files/test_location.py +++ b/tests/_files/test_location.py @@ -31,16 +31,16 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def location(): return Location( - latitude=TestLocationBase.latitude, - longitude=TestLocationBase.longitude, - horizontal_accuracy=TestLocationBase.horizontal_accuracy, - live_period=TestLocationBase.live_period, - heading=TestLocationBase.live_period, - proximity_alert_radius=TestLocationBase.proximity_alert_radius, + latitude=LocationTestBase.latitude, + longitude=LocationTestBase.longitude, + horizontal_accuracy=LocationTestBase.horizontal_accuracy, + live_period=LocationTestBase.live_period, + heading=LocationTestBase.live_period, + proximity_alert_radius=LocationTestBase.proximity_alert_radius, ) -class TestLocationBase: +class LocationTestBase: latitude = -23.691288 longitude = -46.788279 horizontal_accuracy = 999 @@ -49,7 +49,7 @@ class TestLocationBase: proximity_alert_radius = 50 -class TestLocationWithoutRequest(TestLocationBase): +class TestLocationWithoutRequest(LocationTestBase): def test_slot_behaviour(self, location): for attr in location.__slots__: assert getattr(location, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/_files/test_photo.py b/tests/_files/test_photo.py index 1d48bba86..6ba9e46ac 100644 --- a/tests/_files/test_photo.py +++ b/tests/_files/test_photo.py @@ -65,7 +65,7 @@ def photo(photolist): return photolist[-1] -class TestPhotoBase: +class PhotoTestBase: width = 800 height = 800 caption = "PhotoTest - *Caption*" @@ -75,7 +75,7 @@ class TestPhotoBase: file_size = [29176, 27662] -class TestPhotoWithoutRequest(TestPhotoBase): +class TestPhotoWithoutRequest(PhotoTestBase): def test_slot_behaviour(self, photo): for attr in photo.__slots__: assert getattr(photo, attr, "err") != "err", f"got extra slot '{attr}'" @@ -237,7 +237,7 @@ class TestPhotoWithoutRequest(TestPhotoBase): await default_bot.send_photo(chat_id, photo, reply_parameters=ReplyParameters(**kwargs)) -class TestPhotoWithRequest(TestPhotoBase): +class TestPhotoWithRequest(PhotoTestBase): async def test_send_photo_all_args(self, bot, chat_id, photo_file): message = await bot.send_photo( chat_id, diff --git a/tests/_files/test_sticker.py b/tests/_files/test_sticker.py index a994325e1..3f374cc2e 100644 --- a/tests/_files/test_sticker.py +++ b/tests/_files/test_sticker.py @@ -61,7 +61,7 @@ async def sticker(bot, chat_id): sticker = (await bot.send_sticker(chat_id, sticker=f, read_timeout=50)).sticker # necessary to properly test needs_repainting with sticker._unfrozen(): - sticker.needs_repainting = TestStickerBase.needs_repainting + sticker.needs_repainting = StickerTestBase.needs_repainting return sticker @@ -89,7 +89,7 @@ def video_sticker(bot, chat_id): return bot.send_sticker(chat_id, sticker=f, timeout=50).sticker -class TestStickerBase: +class StickerTestBase: # sticker_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.webp' # Serving sticker from gh since our server sends wrong content_type sticker_file_url = ( @@ -116,7 +116,7 @@ class TestStickerBase: premium_animation = File("this_is_an_id", "this_is_an_unique_id") -class TestStickerWithoutRequest(TestStickerBase): +class TestStickerWithoutRequest(StickerTestBase): def test_slot_behaviour(self, sticker): for attr in sticker.__slots__: assert getattr(sticker, attr, "err") != "err", f"got extra slot '{attr}'" @@ -345,7 +345,7 @@ class TestStickerWithoutRequest(TestStickerBase): ) -class TestStickerWithRequest(TestStickerBase): +class TestStickerWithRequest(StickerTestBase): async def test_send_all_args(self, bot, chat_id, sticker_file, sticker): message = await bot.send_sticker( chat_id, sticker=sticker_file, disable_notification=False, protect_content=True @@ -572,7 +572,7 @@ def sticker_set_thumb_file(): yield file -class TestStickerSetBase: +class StickerSetTestBase: title = "Test stickers" stickers = [Sticker("file_id", "file_un_id", 512, 512, True, True, Sticker.REGULAR)] name = "NOTAREALNAME" @@ -580,7 +580,7 @@ class TestStickerSetBase: contains_masks = True -class TestStickerSetWithoutRequest(TestStickerSetBase): +class TestStickerSetWithoutRequest(StickerSetTestBase): def test_slot_behaviour(self): inst = StickerSet("this", "is", self.stickers, "not") for attr in inst.__slots__: @@ -1064,21 +1064,21 @@ class TestStickerSetWithRequest: @pytest.fixture(scope="module") def mask_position(): return MaskPosition( - TestMaskPositionBase.point, - TestMaskPositionBase.x_shift, - TestMaskPositionBase.y_shift, - TestMaskPositionBase.scale, + MaskPositionTestBase.point, + MaskPositionTestBase.x_shift, + MaskPositionTestBase.y_shift, + MaskPositionTestBase.scale, ) -class TestMaskPositionBase: +class MaskPositionTestBase: point = MaskPosition.EYES x_shift = -1 y_shift = 1 scale = 2 -class TestMaskPositionWithoutRequest(TestMaskPositionBase): +class TestMaskPositionWithoutRequest(MaskPositionTestBase): def test_slot_behaviour(self, mask_position): inst = mask_position for attr in inst.__slots__: @@ -1130,7 +1130,7 @@ class TestMaskPositionWithoutRequest(TestMaskPositionBase): assert hash(a) != hash(e) -class TestMaskPositionWithRequest(TestMaskPositionBase): +class TestMaskPositionWithRequest(MaskPositionTestBase): async def test_create_new_mask_sticker_set(self, bot, chat_id, sticker_file, mask_position): name = f"masks_by_{bot.username}" try: diff --git a/tests/_files/test_venue.py b/tests/_files/test_venue.py index 0cb8f500b..b78223bbf 100644 --- a/tests/_files/test_venue.py +++ b/tests/_files/test_venue.py @@ -31,17 +31,17 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def venue(): return Venue( - TestVenueBase.location, - TestVenueBase.title, - TestVenueBase.address, - foursquare_id=TestVenueBase.foursquare_id, - foursquare_type=TestVenueBase.foursquare_type, - google_place_id=TestVenueBase.google_place_id, - google_place_type=TestVenueBase.google_place_type, + VenueTestBase.location, + VenueTestBase.title, + VenueTestBase.address, + foursquare_id=VenueTestBase.foursquare_id, + foursquare_type=VenueTestBase.foursquare_type, + google_place_id=VenueTestBase.google_place_id, + google_place_type=VenueTestBase.google_place_type, ) -class TestVenueBase: +class VenueTestBase: location = Location(longitude=-46.788279, latitude=-23.691288) title = "title" address = "address" @@ -51,7 +51,7 @@ class TestVenueBase: google_place_type = "google place type" -class TestVenueWithoutRequest(TestVenueBase): +class TestVenueWithoutRequest(VenueTestBase): def test_slot_behaviour(self, venue): for attr in venue.__slots__: assert getattr(venue, attr, "err") != "err", f"got extra slot '{attr}'" @@ -171,7 +171,7 @@ class TestVenueWithoutRequest(TestVenueBase): ) -class TestVenueWithRequest(TestVenueBase): +class TestVenueWithRequest(VenueTestBase): @pytest.mark.parametrize( ("default_bot", "custom"), [ diff --git a/tests/_files/test_video.py b/tests/_files/test_video.py index 29a80930f..06666ea16 100644 --- a/tests/_files/test_video.py +++ b/tests/_files/test_video.py @@ -49,7 +49,7 @@ async def video(bot, chat_id): return (await bot.send_video(chat_id, video=f, read_timeout=50)).video -class TestVideoBase: +class VideoTestBase: width = 360 height = 640 duration = 5 @@ -66,7 +66,7 @@ class TestVideoBase: video_file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e" -class TestVideoWithoutRequest(TestVideoBase): +class TestVideoWithoutRequest(VideoTestBase): def test_slot_behaviour(self, video): for attr in video.__slots__: assert getattr(video, attr, "err") != "err", f"got extra slot '{attr}'" @@ -229,7 +229,7 @@ class TestVideoWithoutRequest(TestVideoBase): await default_bot.send_video(chat_id, video, reply_parameters=ReplyParameters(**kwargs)) -class TestVideoWithRequest(TestVideoBase): +class TestVideoWithRequest(VideoTestBase): async def test_send_all_args(self, bot, chat_id, video_file, video, thumb_file): message = await bot.send_video( chat_id, diff --git a/tests/_files/test_videonote.py b/tests/_files/test_videonote.py index 5f07936ca..b86355e44 100644 --- a/tests/_files/test_videonote.py +++ b/tests/_files/test_videonote.py @@ -48,7 +48,7 @@ async def video_note(bot, chat_id): return (await bot.send_video_note(chat_id, video_note=f, read_timeout=50)).video_note -class TestVideoNoteBase: +class VideoNoteTestBase: length = 240 duration = 3 file_size = 132084 @@ -60,7 +60,7 @@ class TestVideoNoteBase: videonote_file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e" -class TestVideoNoteWithoutRequest(TestVideoNoteBase): +class TestVideoNoteWithoutRequest(VideoNoteTestBase): def test_slot_behaviour(self, video_note): for attr in video_note.__slots__: assert getattr(video_note, attr, "err") != "err", f"got extra slot '{attr}'" @@ -218,7 +218,7 @@ class TestVideoNoteWithoutRequest(TestVideoNoteBase): ) -class TestVideoNoteWithRequest(TestVideoNoteBase): +class TestVideoNoteWithRequest(VideoNoteTestBase): async def test_send_all_args(self, bot, chat_id, video_note_file, video_note, thumb_file): message = await bot.send_video_note( chat_id, diff --git a/tests/_files/test_voice.py b/tests/_files/test_voice.py index 0c92b5390..454db0aae 100644 --- a/tests/_files/test_voice.py +++ b/tests/_files/test_voice.py @@ -49,7 +49,7 @@ async def voice(bot, chat_id): return (await bot.send_voice(chat_id, voice=f, read_timeout=50)).voice -class TestVoiceBase: +class VoiceTestBase: duration = 3 mime_type = "audio/ogg" file_size = 9199 @@ -59,7 +59,7 @@ class TestVoiceBase: voice_file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e" -class TestVoiceWithoutRequest(TestVoiceBase): +class TestVoiceWithoutRequest(VoiceTestBase): def test_slot_behaviour(self, voice): for attr in voice.__slots__: assert getattr(voice, attr, "err") != "err", f"got extra slot '{attr}'" @@ -203,7 +203,7 @@ class TestVoiceWithoutRequest(TestVoiceBase): await default_bot.send_voice(chat_id, voice, reply_parameters=ReplyParameters(**kwargs)) -class TestVoiceWithRequest(TestVoiceBase): +class TestVoiceWithRequest(VoiceTestBase): async def test_send_all_args(self, bot, chat_id, voice_file, voice): message = await bot.send_voice( chat_id, diff --git a/tests/_games/test_game.py b/tests/_games/test_game.py index 49067a800..23e0d5e9c 100644 --- a/tests/_games/test_game.py +++ b/tests/_games/test_game.py @@ -26,18 +26,18 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def game(): game = Game( - TestGameBase.title, - TestGameBase.description, - TestGameBase.photo, - text=TestGameBase.text, - text_entities=TestGameBase.text_entities, - animation=TestGameBase.animation, + GameTestBase.title, + GameTestBase.description, + GameTestBase.photo, + text=GameTestBase.text, + text_entities=GameTestBase.text_entities, + animation=GameTestBase.animation, ) game._unfreeze() return game -class TestGameBase: +class GameTestBase: title = "Python-telegram-bot Test Game" description = "description" photo = [PhotoSize("Blah", "ElseBlah", 640, 360, file_size=0)] @@ -49,7 +49,7 @@ class TestGameBase: animation = Animation("blah", "unique_id", 320, 180, 1) -class TestGameWithoutRequest(TestGameBase): +class TestGameWithoutRequest(GameTestBase): def test_slot_behaviour(self, game): for attr in game.__slots__: assert getattr(game, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/_games/test_gamehighscore.py b/tests/_games/test_gamehighscore.py index 02738be21..fc76867b4 100644 --- a/tests/_games/test_gamehighscore.py +++ b/tests/_games/test_gamehighscore.py @@ -26,17 +26,17 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def game_highscore(): return GameHighScore( - TestGameHighScoreBase.position, TestGameHighScoreBase.user, TestGameHighScoreBase.score + GameHighScoreTestBase.position, GameHighScoreTestBase.user, GameHighScoreTestBase.score ) -class TestGameHighScoreBase: +class GameHighScoreTestBase: position = 12 user = User(2, "test user", False) score = 42 -class TestGameHighScoreWithoutRequest(TestGameHighScoreBase): +class TestGameHighScoreWithoutRequest(GameHighScoreTestBase): def test_slot_behaviour(self, game_highscore): for attr in game_highscore.__slots__: assert getattr(game_highscore, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/_inline/test_inlinekeyboardbutton.py b/tests/_inline/test_inlinekeyboardbutton.py index 9eb1eff49..2569a8902 100644 --- a/tests/_inline/test_inlinekeyboardbutton.py +++ b/tests/_inline/test_inlinekeyboardbutton.py @@ -32,24 +32,24 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_keyboard_button(): return InlineKeyboardButton( - TestInlineKeyboardButtonBase.text, - url=TestInlineKeyboardButtonBase.url, - callback_data=TestInlineKeyboardButtonBase.callback_data, - switch_inline_query=TestInlineKeyboardButtonBase.switch_inline_query, + InlineKeyboardButtonTestBase.text, + url=InlineKeyboardButtonTestBase.url, + callback_data=InlineKeyboardButtonTestBase.callback_data, + switch_inline_query=InlineKeyboardButtonTestBase.switch_inline_query, switch_inline_query_current_chat=( - TestInlineKeyboardButtonBase.switch_inline_query_current_chat + InlineKeyboardButtonTestBase.switch_inline_query_current_chat ), - callback_game=TestInlineKeyboardButtonBase.callback_game, - pay=TestInlineKeyboardButtonBase.pay, - login_url=TestInlineKeyboardButtonBase.login_url, - web_app=TestInlineKeyboardButtonBase.web_app, + callback_game=InlineKeyboardButtonTestBase.callback_game, + pay=InlineKeyboardButtonTestBase.pay, + login_url=InlineKeyboardButtonTestBase.login_url, + web_app=InlineKeyboardButtonTestBase.web_app, switch_inline_query_chosen_chat=( - TestInlineKeyboardButtonBase.switch_inline_query_chosen_chat + InlineKeyboardButtonTestBase.switch_inline_query_chosen_chat ), ) -class TestInlineKeyboardButtonBase: +class InlineKeyboardButtonTestBase: text = "text" url = "url" callback_data = "callback data" @@ -62,7 +62,7 @@ class TestInlineKeyboardButtonBase: switch_inline_query_chosen_chat = SwitchInlineQueryChosenChat("a_bot", True, False, True, True) -class TestInlineKeyboardButtonWithoutRequest(TestInlineKeyboardButtonBase): +class TestInlineKeyboardButtonWithoutRequest(InlineKeyboardButtonTestBase): def test_slot_behaviour(self, inline_keyboard_button): inst = inline_keyboard_button for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinekeyboardmarkup.py b/tests/_inline/test_inlinekeyboardmarkup.py index d7e8700dd..2f5bd2a5a 100644 --- a/tests/_inline/test_inlinekeyboardmarkup.py +++ b/tests/_inline/test_inlinekeyboardmarkup.py @@ -31,10 +31,10 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_keyboard_markup(): - return InlineKeyboardMarkup(TestInlineKeyboardMarkupBase.inline_keyboard) + return InlineKeyboardMarkup(InlineKeyboardMarkupTestBase.inline_keyboard) -class TestInlineKeyboardMarkupBase: +class InlineKeyboardMarkupTestBase: inline_keyboard = [ [ InlineKeyboardButton(text="button1", callback_data="data1"), @@ -43,7 +43,7 @@ class TestInlineKeyboardMarkupBase: ] -class TestInlineKeyboardMarkupWithoutRequest(TestInlineKeyboardMarkupBase): +class TestInlineKeyboardMarkupWithoutRequest(InlineKeyboardMarkupTestBase): def test_slot_behaviour(self, inline_keyboard_markup): inst = inline_keyboard_markup for attr in inst.__slots__: @@ -228,7 +228,7 @@ class TestInlineKeyboardMarkupWithoutRequest(TestInlineKeyboardMarkupBase): await bot.send_message(123, "test", reply_markup=inline_keyboard_markup) -class TestInlineKeyborardMarkupWithRequest(TestInlineKeyboardMarkupBase): +class TestInlineKeyborardMarkupWithRequest(InlineKeyboardMarkupTestBase): async def test_send_message_with_inline_keyboard_markup( self, bot, chat_id, inline_keyboard_markup ): diff --git a/tests/_inline/test_inlinequery.py b/tests/_inline/test_inlinequery.py index e5c8562c5..4d2e73ffb 100644 --- a/tests/_inline/test_inlinequery.py +++ b/tests/_inline/test_inlinequery.py @@ -31,17 +31,17 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query(bot): ilq = InlineQuery( - TestInlineQueryBase.id_, - TestInlineQueryBase.from_user, - TestInlineQueryBase.query, - TestInlineQueryBase.offset, - location=TestInlineQueryBase.location, + InlineQueryTestBase.id_, + InlineQueryTestBase.from_user, + InlineQueryTestBase.query, + InlineQueryTestBase.offset, + location=InlineQueryTestBase.location, ) ilq.set_bot(bot) return ilq -class TestInlineQueryBase: +class InlineQueryTestBase: id_ = 1234 from_user = User(1, "First name", False) query = "query text" @@ -49,7 +49,7 @@ class TestInlineQueryBase: location = Location(8.8, 53.1) -class TestInlineQueryWithoutRequest(TestInlineQueryBase): +class TestInlineQueryWithoutRequest(InlineQueryTestBase): def test_slot_behaviour(self, inline_query): for attr in inline_query.__slots__: assert getattr(inline_query, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/_inline/test_inlinequeryresultarticle.py b/tests/_inline/test_inlinequeryresultarticle.py index 4bc56c92d..0692c425d 100644 --- a/tests/_inline/test_inlinequeryresultarticle.py +++ b/tests/_inline/test_inlinequeryresultarticle.py @@ -34,20 +34,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_article(): return InlineQueryResultArticle( - TestInlineQueryResultArticleBase.id_, - TestInlineQueryResultArticleBase.title, - input_message_content=TestInlineQueryResultArticleBase.input_message_content, - reply_markup=TestInlineQueryResultArticleBase.reply_markup, - url=TestInlineQueryResultArticleBase.url, - hide_url=TestInlineQueryResultArticleBase.hide_url, - description=TestInlineQueryResultArticleBase.description, - thumbnail_url=TestInlineQueryResultArticleBase.thumbnail_url, - thumbnail_height=TestInlineQueryResultArticleBase.thumbnail_height, - thumbnail_width=TestInlineQueryResultArticleBase.thumbnail_width, + InlineQueryResultArticleTestBase.id_, + InlineQueryResultArticleTestBase.title, + input_message_content=InlineQueryResultArticleTestBase.input_message_content, + reply_markup=InlineQueryResultArticleTestBase.reply_markup, + url=InlineQueryResultArticleTestBase.url, + hide_url=InlineQueryResultArticleTestBase.hide_url, + description=InlineQueryResultArticleTestBase.description, + thumbnail_url=InlineQueryResultArticleTestBase.thumbnail_url, + thumbnail_height=InlineQueryResultArticleTestBase.thumbnail_height, + thumbnail_width=InlineQueryResultArticleTestBase.thumbnail_width, ) -class TestInlineQueryResultArticleBase: +class InlineQueryResultArticleTestBase: id_ = "id" type_ = "article" title = "title" @@ -61,7 +61,7 @@ class TestInlineQueryResultArticleBase: thumbnail_width = 15 -class TestInlineQueryResultArticleWithoutRequest(TestInlineQueryResultArticleBase): +class TestInlineQueryResultArticleWithoutRequest(InlineQueryResultArticleTestBase): def test_slot_behaviour(self, inline_query_result_article): inst = inline_query_result_article for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultaudio.py b/tests/_inline/test_inlinequeryresultaudio.py index 33542787e..251b3f6a4 100644 --- a/tests/_inline/test_inlinequeryresultaudio.py +++ b/tests/_inline/test_inlinequeryresultaudio.py @@ -33,20 +33,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_audio(): return InlineQueryResultAudio( - TestInlineQueryResultAudioBase.id_, - TestInlineQueryResultAudioBase.audio_url, - TestInlineQueryResultAudioBase.title, - performer=TestInlineQueryResultAudioBase.performer, - audio_duration=TestInlineQueryResultAudioBase.audio_duration, - caption=TestInlineQueryResultAudioBase.caption, - parse_mode=TestInlineQueryResultAudioBase.parse_mode, - caption_entities=TestInlineQueryResultAudioBase.caption_entities, - input_message_content=TestInlineQueryResultAudioBase.input_message_content, - reply_markup=TestInlineQueryResultAudioBase.reply_markup, + InlineQueryResultAudioTestBase.id_, + InlineQueryResultAudioTestBase.audio_url, + InlineQueryResultAudioTestBase.title, + performer=InlineQueryResultAudioTestBase.performer, + audio_duration=InlineQueryResultAudioTestBase.audio_duration, + caption=InlineQueryResultAudioTestBase.caption, + parse_mode=InlineQueryResultAudioTestBase.parse_mode, + caption_entities=InlineQueryResultAudioTestBase.caption_entities, + input_message_content=InlineQueryResultAudioTestBase.input_message_content, + reply_markup=InlineQueryResultAudioTestBase.reply_markup, ) -class TestInlineQueryResultAudioBase: +class InlineQueryResultAudioTestBase: id_ = "id" type_ = "audio" audio_url = "audio url" @@ -60,7 +60,7 @@ class TestInlineQueryResultAudioBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultAudioWithoutRequest(TestInlineQueryResultAudioBase): +class TestInlineQueryResultAudioWithoutRequest(InlineQueryResultAudioTestBase): def test_slot_behaviour(self, inline_query_result_audio): inst = inline_query_result_audio for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcachedaudio.py b/tests/_inline/test_inlinequeryresultcachedaudio.py index efa0cb06e..363580bd6 100644 --- a/tests/_inline/test_inlinequeryresultcachedaudio.py +++ b/tests/_inline/test_inlinequeryresultcachedaudio.py @@ -33,17 +33,17 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_cached_audio(): return InlineQueryResultCachedAudio( - TestInlineQueryResultCachedAudioBase.id_, - TestInlineQueryResultCachedAudioBase.audio_file_id, - caption=TestInlineQueryResultCachedAudioBase.caption, - parse_mode=TestInlineQueryResultCachedAudioBase.parse_mode, - caption_entities=TestInlineQueryResultCachedAudioBase.caption_entities, - input_message_content=TestInlineQueryResultCachedAudioBase.input_message_content, - reply_markup=TestInlineQueryResultCachedAudioBase.reply_markup, + InlineQueryResultCachedAudioTestBase.id_, + InlineQueryResultCachedAudioTestBase.audio_file_id, + caption=InlineQueryResultCachedAudioTestBase.caption, + parse_mode=InlineQueryResultCachedAudioTestBase.parse_mode, + caption_entities=InlineQueryResultCachedAudioTestBase.caption_entities, + input_message_content=InlineQueryResultCachedAudioTestBase.input_message_content, + reply_markup=InlineQueryResultCachedAudioTestBase.reply_markup, ) -class TestInlineQueryResultCachedAudioBase: +class InlineQueryResultCachedAudioTestBase: id_ = "id" type_ = "audio" audio_file_id = "audio file id" @@ -54,7 +54,7 @@ class TestInlineQueryResultCachedAudioBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultCachedAudioWithoutRequest(TestInlineQueryResultCachedAudioBase): +class TestInlineQueryResultCachedAudioWithoutRequest(InlineQueryResultCachedAudioTestBase): def test_slot_behaviour(self, inline_query_result_cached_audio): inst = inline_query_result_cached_audio for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcacheddocument.py b/tests/_inline/test_inlinequeryresultcacheddocument.py index 48c9eef25..c3d6a19ac 100644 --- a/tests/_inline/test_inlinequeryresultcacheddocument.py +++ b/tests/_inline/test_inlinequeryresultcacheddocument.py @@ -33,19 +33,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_cached_document(): return InlineQueryResultCachedDocument( - TestInlineQueryResultCachedDocumentBase.id_, - TestInlineQueryResultCachedDocumentBase.title, - TestInlineQueryResultCachedDocumentBase.document_file_id, - caption=TestInlineQueryResultCachedDocumentBase.caption, - parse_mode=TestInlineQueryResultCachedDocumentBase.parse_mode, - caption_entities=TestInlineQueryResultCachedDocumentBase.caption_entities, - description=TestInlineQueryResultCachedDocumentBase.description, - input_message_content=TestInlineQueryResultCachedDocumentBase.input_message_content, - reply_markup=TestInlineQueryResultCachedDocumentBase.reply_markup, + InlineQueryResultCachedDocumentTestBase.id_, + InlineQueryResultCachedDocumentTestBase.title, + InlineQueryResultCachedDocumentTestBase.document_file_id, + caption=InlineQueryResultCachedDocumentTestBase.caption, + parse_mode=InlineQueryResultCachedDocumentTestBase.parse_mode, + caption_entities=InlineQueryResultCachedDocumentTestBase.caption_entities, + description=InlineQueryResultCachedDocumentTestBase.description, + input_message_content=InlineQueryResultCachedDocumentTestBase.input_message_content, + reply_markup=InlineQueryResultCachedDocumentTestBase.reply_markup, ) -class TestInlineQueryResultCachedDocumentBase: +class InlineQueryResultCachedDocumentTestBase: id_ = "id" type_ = "document" document_file_id = "document file id" @@ -58,7 +58,7 @@ class TestInlineQueryResultCachedDocumentBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultCachedDocumentWithoutRequest(TestInlineQueryResultCachedDocumentBase): +class TestInlineQueryResultCachedDocumentWithoutRequest(InlineQueryResultCachedDocumentTestBase): def test_slot_behaviour(self, inline_query_result_cached_document): inst = inline_query_result_cached_document for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcachedgif.py b/tests/_inline/test_inlinequeryresultcachedgif.py index 62b908a63..8128dc7b6 100644 --- a/tests/_inline/test_inlinequeryresultcachedgif.py +++ b/tests/_inline/test_inlinequeryresultcachedgif.py @@ -32,19 +32,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_cached_gif(): return InlineQueryResultCachedGif( - TestInlineQueryResultCachedGifBase.id_, - TestInlineQueryResultCachedGifBase.gif_file_id, - title=TestInlineQueryResultCachedGifBase.title, - caption=TestInlineQueryResultCachedGifBase.caption, - parse_mode=TestInlineQueryResultCachedGifBase.parse_mode, - caption_entities=TestInlineQueryResultCachedGifBase.caption_entities, - input_message_content=TestInlineQueryResultCachedGifBase.input_message_content, - reply_markup=TestInlineQueryResultCachedGifBase.reply_markup, - show_caption_above_media=TestInlineQueryResultCachedGifBase.show_caption_above_media, + InlineQueryResultCachedGifTestBase.id_, + InlineQueryResultCachedGifTestBase.gif_file_id, + title=InlineQueryResultCachedGifTestBase.title, + caption=InlineQueryResultCachedGifTestBase.caption, + parse_mode=InlineQueryResultCachedGifTestBase.parse_mode, + caption_entities=InlineQueryResultCachedGifTestBase.caption_entities, + input_message_content=InlineQueryResultCachedGifTestBase.input_message_content, + reply_markup=InlineQueryResultCachedGifTestBase.reply_markup, + show_caption_above_media=InlineQueryResultCachedGifTestBase.show_caption_above_media, ) -class TestInlineQueryResultCachedGifBase: +class InlineQueryResultCachedGifTestBase: id_ = "id" type_ = "gif" gif_file_id = "gif file id" @@ -57,7 +57,7 @@ class TestInlineQueryResultCachedGifBase: show_caption_above_media = True -class TestInlineQueryResultCachedGifWithoutRequest(TestInlineQueryResultCachedGifBase): +class TestInlineQueryResultCachedGifWithoutRequest(InlineQueryResultCachedGifTestBase): def test_slot_behaviour(self, inline_query_result_cached_gif): inst = inline_query_result_cached_gif for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcachedmpeg4gif.py b/tests/_inline/test_inlinequeryresultcachedmpeg4gif.py index 3d4b5d3ca..fb1db70ce 100644 --- a/tests/_inline/test_inlinequeryresultcachedmpeg4gif.py +++ b/tests/_inline/test_inlinequeryresultcachedmpeg4gif.py @@ -32,19 +32,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_cached_mpeg4_gif(): return InlineQueryResultCachedMpeg4Gif( - TestInlineQueryResultCachedMpeg4GifBase.id_, - TestInlineQueryResultCachedMpeg4GifBase.mpeg4_file_id, - title=TestInlineQueryResultCachedMpeg4GifBase.title, - caption=TestInlineQueryResultCachedMpeg4GifBase.caption, - parse_mode=TestInlineQueryResultCachedMpeg4GifBase.parse_mode, - caption_entities=TestInlineQueryResultCachedMpeg4GifBase.caption_entities, - input_message_content=TestInlineQueryResultCachedMpeg4GifBase.input_message_content, - reply_markup=TestInlineQueryResultCachedMpeg4GifBase.reply_markup, - show_caption_above_media=TestInlineQueryResultCachedMpeg4GifBase.show_caption_above_media, + InlineQueryResultCachedMpeg4GifTestBase.id_, + InlineQueryResultCachedMpeg4GifTestBase.mpeg4_file_id, + title=InlineQueryResultCachedMpeg4GifTestBase.title, + caption=InlineQueryResultCachedMpeg4GifTestBase.caption, + parse_mode=InlineQueryResultCachedMpeg4GifTestBase.parse_mode, + caption_entities=InlineQueryResultCachedMpeg4GifTestBase.caption_entities, + input_message_content=InlineQueryResultCachedMpeg4GifTestBase.input_message_content, + reply_markup=InlineQueryResultCachedMpeg4GifTestBase.reply_markup, + show_caption_above_media=InlineQueryResultCachedMpeg4GifTestBase.show_caption_above_media, ) -class TestInlineQueryResultCachedMpeg4GifBase: +class InlineQueryResultCachedMpeg4GifTestBase: id_ = "id" type_ = "mpeg4_gif" mpeg4_file_id = "mpeg4 file id" @@ -57,7 +57,7 @@ class TestInlineQueryResultCachedMpeg4GifBase: show_caption_above_media = True -class TestInlineQueryResultCachedMpeg4GifWithoutRequest(TestInlineQueryResultCachedMpeg4GifBase): +class TestInlineQueryResultCachedMpeg4GifWithoutRequest(InlineQueryResultCachedMpeg4GifTestBase): def test_slot_behaviour(self, inline_query_result_cached_mpeg4_gif): inst = inline_query_result_cached_mpeg4_gif for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcachedphoto.py b/tests/_inline/test_inlinequeryresultcachedphoto.py index b5ed6153b..e3159acf3 100644 --- a/tests/_inline/test_inlinequeryresultcachedphoto.py +++ b/tests/_inline/test_inlinequeryresultcachedphoto.py @@ -32,20 +32,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_cached_photo(): return InlineQueryResultCachedPhoto( - TestInlineQueryResultCachedPhotoBase.id_, - TestInlineQueryResultCachedPhotoBase.photo_file_id, - title=TestInlineQueryResultCachedPhotoBase.title, - description=TestInlineQueryResultCachedPhotoBase.description, - caption=TestInlineQueryResultCachedPhotoBase.caption, - parse_mode=TestInlineQueryResultCachedPhotoBase.parse_mode, - caption_entities=TestInlineQueryResultCachedPhotoBase.caption_entities, - input_message_content=TestInlineQueryResultCachedPhotoBase.input_message_content, - reply_markup=TestInlineQueryResultCachedPhotoBase.reply_markup, - show_caption_above_media=TestInlineQueryResultCachedPhotoBase.show_caption_above_media, + InlineQueryResultCachedPhotoTestBase.id_, + InlineQueryResultCachedPhotoTestBase.photo_file_id, + title=InlineQueryResultCachedPhotoTestBase.title, + description=InlineQueryResultCachedPhotoTestBase.description, + caption=InlineQueryResultCachedPhotoTestBase.caption, + parse_mode=InlineQueryResultCachedPhotoTestBase.parse_mode, + caption_entities=InlineQueryResultCachedPhotoTestBase.caption_entities, + input_message_content=InlineQueryResultCachedPhotoTestBase.input_message_content, + reply_markup=InlineQueryResultCachedPhotoTestBase.reply_markup, + show_caption_above_media=InlineQueryResultCachedPhotoTestBase.show_caption_above_media, ) -class TestInlineQueryResultCachedPhotoBase: +class InlineQueryResultCachedPhotoTestBase: id_ = "id" type_ = "photo" photo_file_id = "photo file id" @@ -59,7 +59,7 @@ class TestInlineQueryResultCachedPhotoBase: show_caption_above_media = True -class TestInlineQueryResultCachedPhotoWithoutRequest(TestInlineQueryResultCachedPhotoBase): +class TestInlineQueryResultCachedPhotoWithoutRequest(InlineQueryResultCachedPhotoTestBase): def test_slot_behaviour(self, inline_query_result_cached_photo): inst = inline_query_result_cached_photo for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcachedsticker.py b/tests/_inline/test_inlinequeryresultcachedsticker.py index 63b7f2425..ee4d5e3e8 100644 --- a/tests/_inline/test_inlinequeryresultcachedsticker.py +++ b/tests/_inline/test_inlinequeryresultcachedsticker.py @@ -31,14 +31,14 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_cached_sticker(): return InlineQueryResultCachedSticker( - TestInlineQueryResultCachedStickerBase.id_, - TestInlineQueryResultCachedStickerBase.sticker_file_id, - input_message_content=TestInlineQueryResultCachedStickerBase.input_message_content, - reply_markup=TestInlineQueryResultCachedStickerBase.reply_markup, + InlineQueryResultCachedStickerTestBase.id_, + InlineQueryResultCachedStickerTestBase.sticker_file_id, + input_message_content=InlineQueryResultCachedStickerTestBase.input_message_content, + reply_markup=InlineQueryResultCachedStickerTestBase.reply_markup, ) -class TestInlineQueryResultCachedStickerBase: +class InlineQueryResultCachedStickerTestBase: id_ = "id" type_ = "sticker" sticker_file_id = "sticker file id" @@ -46,7 +46,7 @@ class TestInlineQueryResultCachedStickerBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultCachedStickerWithoutRequest(TestInlineQueryResultCachedStickerBase): +class TestInlineQueryResultCachedStickerWithoutRequest(InlineQueryResultCachedStickerTestBase): def test_slot_behaviour(self, inline_query_result_cached_sticker): inst = inline_query_result_cached_sticker for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcachedvideo.py b/tests/_inline/test_inlinequeryresultcachedvideo.py index d520b3c7c..efd0f624d 100644 --- a/tests/_inline/test_inlinequeryresultcachedvideo.py +++ b/tests/_inline/test_inlinequeryresultcachedvideo.py @@ -32,20 +32,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_cached_video(): return InlineQueryResultCachedVideo( - TestInlineQueryResultCachedVideoBase.id_, - TestInlineQueryResultCachedVideoBase.video_file_id, - TestInlineQueryResultCachedVideoBase.title, - caption=TestInlineQueryResultCachedVideoBase.caption, - parse_mode=TestInlineQueryResultCachedVideoBase.parse_mode, - caption_entities=TestInlineQueryResultCachedVideoBase.caption_entities, - description=TestInlineQueryResultCachedVideoBase.description, - input_message_content=TestInlineQueryResultCachedVideoBase.input_message_content, - reply_markup=TestInlineQueryResultCachedVideoBase.reply_markup, - show_caption_above_media=TestInlineQueryResultCachedVideoBase.show_caption_above_media, + InlineQueryResultCachedVideoTestBase.id_, + InlineQueryResultCachedVideoTestBase.video_file_id, + InlineQueryResultCachedVideoTestBase.title, + caption=InlineQueryResultCachedVideoTestBase.caption, + parse_mode=InlineQueryResultCachedVideoTestBase.parse_mode, + caption_entities=InlineQueryResultCachedVideoTestBase.caption_entities, + description=InlineQueryResultCachedVideoTestBase.description, + input_message_content=InlineQueryResultCachedVideoTestBase.input_message_content, + reply_markup=InlineQueryResultCachedVideoTestBase.reply_markup, + show_caption_above_media=InlineQueryResultCachedVideoTestBase.show_caption_above_media, ) -class TestInlineQueryResultCachedVideoBase: +class InlineQueryResultCachedVideoTestBase: id_ = "id" type_ = "video" video_file_id = "video file id" @@ -59,7 +59,7 @@ class TestInlineQueryResultCachedVideoBase: show_caption_above_media = True -class TestInlineQueryResultCachedVideoWithoutRequest(TestInlineQueryResultCachedVideoBase): +class TestInlineQueryResultCachedVideoWithoutRequest(InlineQueryResultCachedVideoTestBase): def test_slot_behaviour(self, inline_query_result_cached_video): inst = inline_query_result_cached_video for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcachedvoice.py b/tests/_inline/test_inlinequeryresultcachedvoice.py index de6810b2b..916364ab9 100644 --- a/tests/_inline/test_inlinequeryresultcachedvoice.py +++ b/tests/_inline/test_inlinequeryresultcachedvoice.py @@ -32,18 +32,18 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_cached_voice(): return InlineQueryResultCachedVoice( - TestInlineQueryResultCachedVoiceBase.id_, - TestInlineQueryResultCachedVoiceBase.voice_file_id, - TestInlineQueryResultCachedVoiceBase.title, - caption=TestInlineQueryResultCachedVoiceBase.caption, - parse_mode=TestInlineQueryResultCachedVoiceBase.parse_mode, - caption_entities=TestInlineQueryResultCachedVoiceBase.caption_entities, - input_message_content=TestInlineQueryResultCachedVoiceBase.input_message_content, - reply_markup=TestInlineQueryResultCachedVoiceBase.reply_markup, + InlineQueryResultCachedVoiceTestBase.id_, + InlineQueryResultCachedVoiceTestBase.voice_file_id, + InlineQueryResultCachedVoiceTestBase.title, + caption=InlineQueryResultCachedVoiceTestBase.caption, + parse_mode=InlineQueryResultCachedVoiceTestBase.parse_mode, + caption_entities=InlineQueryResultCachedVoiceTestBase.caption_entities, + input_message_content=InlineQueryResultCachedVoiceTestBase.input_message_content, + reply_markup=InlineQueryResultCachedVoiceTestBase.reply_markup, ) -class TestInlineQueryResultCachedVoiceBase: +class InlineQueryResultCachedVoiceTestBase: id_ = "id" type_ = "voice" voice_file_id = "voice file id" @@ -55,7 +55,7 @@ class TestInlineQueryResultCachedVoiceBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultCachedVoiceWithoutRequest(TestInlineQueryResultCachedVoiceBase): +class TestInlineQueryResultCachedVoiceWithoutRequest(InlineQueryResultCachedVoiceTestBase): def test_slot_behaviour(self, inline_query_result_cached_voice): inst = inline_query_result_cached_voice for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultcontact.py b/tests/_inline/test_inlinequeryresultcontact.py index 4b691f380..bb8c8c181 100644 --- a/tests/_inline/test_inlinequeryresultcontact.py +++ b/tests/_inline/test_inlinequeryresultcontact.py @@ -31,19 +31,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_contact(): return InlineQueryResultContact( - TestInlineQueryResultContactBase.id_, - TestInlineQueryResultContactBase.phone_number, - TestInlineQueryResultContactBase.first_name, - last_name=TestInlineQueryResultContactBase.last_name, - thumbnail_url=TestInlineQueryResultContactBase.thumbnail_url, - thumbnail_width=TestInlineQueryResultContactBase.thumbnail_width, - thumbnail_height=TestInlineQueryResultContactBase.thumbnail_height, - input_message_content=TestInlineQueryResultContactBase.input_message_content, - reply_markup=TestInlineQueryResultContactBase.reply_markup, + InlineQueryResultContactTestBase.id_, + InlineQueryResultContactTestBase.phone_number, + InlineQueryResultContactTestBase.first_name, + last_name=InlineQueryResultContactTestBase.last_name, + thumbnail_url=InlineQueryResultContactTestBase.thumbnail_url, + thumbnail_width=InlineQueryResultContactTestBase.thumbnail_width, + thumbnail_height=InlineQueryResultContactTestBase.thumbnail_height, + input_message_content=InlineQueryResultContactTestBase.input_message_content, + reply_markup=InlineQueryResultContactTestBase.reply_markup, ) -class TestInlineQueryResultContactBase: +class InlineQueryResultContactTestBase: id_ = "id" type_ = "contact" phone_number = "phone_number" @@ -56,7 +56,7 @@ class TestInlineQueryResultContactBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultContactWithoutRequest(TestInlineQueryResultContactBase): +class TestInlineQueryResultContactWithoutRequest(InlineQueryResultContactTestBase): def test_slot_behaviour(self, inline_query_result_contact): inst = inline_query_result_contact for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultdocument.py b/tests/_inline/test_inlinequeryresultdocument.py index aacf9d858..024d714c7 100644 --- a/tests/_inline/test_inlinequeryresultdocument.py +++ b/tests/_inline/test_inlinequeryresultdocument.py @@ -32,23 +32,23 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_document(): return InlineQueryResultDocument( - TestInlineQueryResultDocumentBase.id_, - TestInlineQueryResultDocumentBase.document_url, - TestInlineQueryResultDocumentBase.title, - TestInlineQueryResultDocumentBase.mime_type, - caption=TestInlineQueryResultDocumentBase.caption, - parse_mode=TestInlineQueryResultDocumentBase.parse_mode, - caption_entities=TestInlineQueryResultDocumentBase.caption_entities, - description=TestInlineQueryResultDocumentBase.description, - thumbnail_url=TestInlineQueryResultDocumentBase.thumbnail_url, - thumbnail_width=TestInlineQueryResultDocumentBase.thumbnail_width, - thumbnail_height=TestInlineQueryResultDocumentBase.thumbnail_height, - input_message_content=TestInlineQueryResultDocumentBase.input_message_content, - reply_markup=TestInlineQueryResultDocumentBase.reply_markup, + InlineQueryResultDocumentTestBase.id_, + InlineQueryResultDocumentTestBase.document_url, + InlineQueryResultDocumentTestBase.title, + InlineQueryResultDocumentTestBase.mime_type, + caption=InlineQueryResultDocumentTestBase.caption, + parse_mode=InlineQueryResultDocumentTestBase.parse_mode, + caption_entities=InlineQueryResultDocumentTestBase.caption_entities, + description=InlineQueryResultDocumentTestBase.description, + thumbnail_url=InlineQueryResultDocumentTestBase.thumbnail_url, + thumbnail_width=InlineQueryResultDocumentTestBase.thumbnail_width, + thumbnail_height=InlineQueryResultDocumentTestBase.thumbnail_height, + input_message_content=InlineQueryResultDocumentTestBase.input_message_content, + reply_markup=InlineQueryResultDocumentTestBase.reply_markup, ) -class TestInlineQueryResultDocumentBase: +class InlineQueryResultDocumentTestBase: id_ = "id" type_ = "document" document_url = "document url" @@ -65,7 +65,7 @@ class TestInlineQueryResultDocumentBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultDocumentWithoutRequest(TestInlineQueryResultDocumentBase): +class TestInlineQueryResultDocumentWithoutRequest(InlineQueryResultDocumentTestBase): def test_slot_behaviour(self, inline_query_result_document): inst = inline_query_result_document for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultgame.py b/tests/_inline/test_inlinequeryresultgame.py index 8a72ae401..2efb7ead8 100644 --- a/tests/_inline/test_inlinequeryresultgame.py +++ b/tests/_inline/test_inlinequeryresultgame.py @@ -30,20 +30,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_game(): return InlineQueryResultGame( - TestInlineQueryResultGameBase.id_, - TestInlineQueryResultGameBase.game_short_name, - reply_markup=TestInlineQueryResultGameBase.reply_markup, + InlineQueryResultGameTestBase.id_, + InlineQueryResultGameTestBase.game_short_name, + reply_markup=InlineQueryResultGameTestBase.reply_markup, ) -class TestInlineQueryResultGameBase: +class InlineQueryResultGameTestBase: id_ = "id" type_ = "game" game_short_name = "game short name" reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultGameWithoutRequest(TestInlineQueryResultGameBase): +class TestInlineQueryResultGameWithoutRequest(InlineQueryResultGameTestBase): def test_slot_behaviour(self, inline_query_result_game): inst = inline_query_result_game for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultgif.py b/tests/_inline/test_inlinequeryresultgif.py index 86ac8574a..efd995ac3 100644 --- a/tests/_inline/test_inlinequeryresultgif.py +++ b/tests/_inline/test_inlinequeryresultgif.py @@ -32,24 +32,24 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_gif(): return InlineQueryResultGif( - TestInlineQueryResultGifBase.id_, - TestInlineQueryResultGifBase.gif_url, - TestInlineQueryResultGifBase.thumbnail_url, - gif_width=TestInlineQueryResultGifBase.gif_width, - gif_height=TestInlineQueryResultGifBase.gif_height, - gif_duration=TestInlineQueryResultGifBase.gif_duration, - title=TestInlineQueryResultGifBase.title, - caption=TestInlineQueryResultGifBase.caption, - parse_mode=TestInlineQueryResultGifBase.parse_mode, - caption_entities=TestInlineQueryResultGifBase.caption_entities, - input_message_content=TestInlineQueryResultGifBase.input_message_content, - reply_markup=TestInlineQueryResultGifBase.reply_markup, - thumbnail_mime_type=TestInlineQueryResultGifBase.thumbnail_mime_type, - show_caption_above_media=TestInlineQueryResultGifBase.show_caption_above_media, + InlineQueryResultGifTestBase.id_, + InlineQueryResultGifTestBase.gif_url, + InlineQueryResultGifTestBase.thumbnail_url, + gif_width=InlineQueryResultGifTestBase.gif_width, + gif_height=InlineQueryResultGifTestBase.gif_height, + gif_duration=InlineQueryResultGifTestBase.gif_duration, + title=InlineQueryResultGifTestBase.title, + caption=InlineQueryResultGifTestBase.caption, + parse_mode=InlineQueryResultGifTestBase.parse_mode, + caption_entities=InlineQueryResultGifTestBase.caption_entities, + input_message_content=InlineQueryResultGifTestBase.input_message_content, + reply_markup=InlineQueryResultGifTestBase.reply_markup, + thumbnail_mime_type=InlineQueryResultGifTestBase.thumbnail_mime_type, + show_caption_above_media=InlineQueryResultGifTestBase.show_caption_above_media, ) -class TestInlineQueryResultGifBase: +class InlineQueryResultGifTestBase: id_ = "id" type_ = "gif" gif_url = "gif url" @@ -67,7 +67,7 @@ class TestInlineQueryResultGifBase: show_caption_above_media = True -class TestInlineQueryResultGifWithoutRequest(TestInlineQueryResultGifBase): +class TestInlineQueryResultGifWithoutRequest(InlineQueryResultGifTestBase): def test_slot_behaviour(self, inline_query_result_gif): inst = inline_query_result_gif for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultlocation.py b/tests/_inline/test_inlinequeryresultlocation.py index 2f5023d51..76320ddda 100644 --- a/tests/_inline/test_inlinequeryresultlocation.py +++ b/tests/_inline/test_inlinequeryresultlocation.py @@ -31,23 +31,23 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_location(): return InlineQueryResultLocation( - TestInlineQueryResultLocationBase.id_, - TestInlineQueryResultLocationBase.latitude, - TestInlineQueryResultLocationBase.longitude, - TestInlineQueryResultLocationBase.title, - live_period=TestInlineQueryResultLocationBase.live_period, - thumbnail_url=TestInlineQueryResultLocationBase.thumbnail_url, - thumbnail_width=TestInlineQueryResultLocationBase.thumbnail_width, - thumbnail_height=TestInlineQueryResultLocationBase.thumbnail_height, - input_message_content=TestInlineQueryResultLocationBase.input_message_content, - reply_markup=TestInlineQueryResultLocationBase.reply_markup, - horizontal_accuracy=TestInlineQueryResultLocationBase.horizontal_accuracy, - heading=TestInlineQueryResultLocationBase.heading, - proximity_alert_radius=TestInlineQueryResultLocationBase.proximity_alert_radius, + InlineQueryResultLocationTestBase.id_, + InlineQueryResultLocationTestBase.latitude, + InlineQueryResultLocationTestBase.longitude, + InlineQueryResultLocationTestBase.title, + live_period=InlineQueryResultLocationTestBase.live_period, + thumbnail_url=InlineQueryResultLocationTestBase.thumbnail_url, + thumbnail_width=InlineQueryResultLocationTestBase.thumbnail_width, + thumbnail_height=InlineQueryResultLocationTestBase.thumbnail_height, + input_message_content=InlineQueryResultLocationTestBase.input_message_content, + reply_markup=InlineQueryResultLocationTestBase.reply_markup, + horizontal_accuracy=InlineQueryResultLocationTestBase.horizontal_accuracy, + heading=InlineQueryResultLocationTestBase.heading, + proximity_alert_radius=InlineQueryResultLocationTestBase.proximity_alert_radius, ) -class TestInlineQueryResultLocationBase: +class InlineQueryResultLocationTestBase: id_ = "id" type_ = "location" latitude = 0.0 @@ -64,7 +64,7 @@ class TestInlineQueryResultLocationBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultLocationWithoutRequest(TestInlineQueryResultLocationBase): +class TestInlineQueryResultLocationWithoutRequest(InlineQueryResultLocationTestBase): def test_slot_behaviour(self, inline_query_result_location): inst = inline_query_result_location for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultmpeg4gif.py b/tests/_inline/test_inlinequeryresultmpeg4gif.py index 2a1bfc2cf..4c0f0f1d3 100644 --- a/tests/_inline/test_inlinequeryresultmpeg4gif.py +++ b/tests/_inline/test_inlinequeryresultmpeg4gif.py @@ -32,24 +32,24 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_mpeg4_gif(): return InlineQueryResultMpeg4Gif( - TestInlineQueryResultMpeg4GifBase.id_, - TestInlineQueryResultMpeg4GifBase.mpeg4_url, - TestInlineQueryResultMpeg4GifBase.thumbnail_url, - mpeg4_width=TestInlineQueryResultMpeg4GifBase.mpeg4_width, - mpeg4_height=TestInlineQueryResultMpeg4GifBase.mpeg4_height, - mpeg4_duration=TestInlineQueryResultMpeg4GifBase.mpeg4_duration, - title=TestInlineQueryResultMpeg4GifBase.title, - caption=TestInlineQueryResultMpeg4GifBase.caption, - parse_mode=TestInlineQueryResultMpeg4GifBase.parse_mode, - caption_entities=TestInlineQueryResultMpeg4GifBase.caption_entities, - input_message_content=TestInlineQueryResultMpeg4GifBase.input_message_content, - reply_markup=TestInlineQueryResultMpeg4GifBase.reply_markup, - thumbnail_mime_type=TestInlineQueryResultMpeg4GifBase.thumbnail_mime_type, - show_caption_above_media=TestInlineQueryResultMpeg4GifBase.show_caption_above_media, + InlineQueryResultMpeg4GifTestBase.id_, + InlineQueryResultMpeg4GifTestBase.mpeg4_url, + InlineQueryResultMpeg4GifTestBase.thumbnail_url, + mpeg4_width=InlineQueryResultMpeg4GifTestBase.mpeg4_width, + mpeg4_height=InlineQueryResultMpeg4GifTestBase.mpeg4_height, + mpeg4_duration=InlineQueryResultMpeg4GifTestBase.mpeg4_duration, + title=InlineQueryResultMpeg4GifTestBase.title, + caption=InlineQueryResultMpeg4GifTestBase.caption, + parse_mode=InlineQueryResultMpeg4GifTestBase.parse_mode, + caption_entities=InlineQueryResultMpeg4GifTestBase.caption_entities, + input_message_content=InlineQueryResultMpeg4GifTestBase.input_message_content, + reply_markup=InlineQueryResultMpeg4GifTestBase.reply_markup, + thumbnail_mime_type=InlineQueryResultMpeg4GifTestBase.thumbnail_mime_type, + show_caption_above_media=InlineQueryResultMpeg4GifTestBase.show_caption_above_media, ) -class TestInlineQueryResultMpeg4GifBase: +class InlineQueryResultMpeg4GifTestBase: id_ = "id" type_ = "mpeg4_gif" mpeg4_url = "mpeg4 url" @@ -67,7 +67,7 @@ class TestInlineQueryResultMpeg4GifBase: show_caption_above_media = True -class TestInlineQueryResultMpeg4GifWithoutRequest(TestInlineQueryResultMpeg4GifBase): +class TestInlineQueryResultMpeg4GifWithoutRequest(InlineQueryResultMpeg4GifTestBase): def test_slot_behaviour(self, inline_query_result_mpeg4_gif): inst = inline_query_result_mpeg4_gif for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultphoto.py b/tests/_inline/test_inlinequeryresultphoto.py index 323cf7b71..2abec4a3b 100644 --- a/tests/_inline/test_inlinequeryresultphoto.py +++ b/tests/_inline/test_inlinequeryresultphoto.py @@ -32,23 +32,23 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_photo(): return InlineQueryResultPhoto( - TestInlineQueryResultPhotoBase.id_, - TestInlineQueryResultPhotoBase.photo_url, - TestInlineQueryResultPhotoBase.thumbnail_url, - photo_width=TestInlineQueryResultPhotoBase.photo_width, - photo_height=TestInlineQueryResultPhotoBase.photo_height, - title=TestInlineQueryResultPhotoBase.title, - description=TestInlineQueryResultPhotoBase.description, - caption=TestInlineQueryResultPhotoBase.caption, - parse_mode=TestInlineQueryResultPhotoBase.parse_mode, - caption_entities=TestInlineQueryResultPhotoBase.caption_entities, - input_message_content=TestInlineQueryResultPhotoBase.input_message_content, - reply_markup=TestInlineQueryResultPhotoBase.reply_markup, - show_caption_above_media=TestInlineQueryResultPhotoBase.show_caption_above_media, + InlineQueryResultPhotoTestBase.id_, + InlineQueryResultPhotoTestBase.photo_url, + InlineQueryResultPhotoTestBase.thumbnail_url, + photo_width=InlineQueryResultPhotoTestBase.photo_width, + photo_height=InlineQueryResultPhotoTestBase.photo_height, + title=InlineQueryResultPhotoTestBase.title, + description=InlineQueryResultPhotoTestBase.description, + caption=InlineQueryResultPhotoTestBase.caption, + parse_mode=InlineQueryResultPhotoTestBase.parse_mode, + caption_entities=InlineQueryResultPhotoTestBase.caption_entities, + input_message_content=InlineQueryResultPhotoTestBase.input_message_content, + reply_markup=InlineQueryResultPhotoTestBase.reply_markup, + show_caption_above_media=InlineQueryResultPhotoTestBase.show_caption_above_media, ) -class TestInlineQueryResultPhotoBase: +class InlineQueryResultPhotoTestBase: id_ = "id" type_ = "photo" photo_url = "photo url" @@ -66,7 +66,7 @@ class TestInlineQueryResultPhotoBase: show_caption_above_media = True -class TestInlineQueryResultPhotoWithoutRequest(TestInlineQueryResultPhotoBase): +class TestInlineQueryResultPhotoWithoutRequest(InlineQueryResultPhotoTestBase): def test_slot_behaviour(self, inline_query_result_photo): inst = inline_query_result_photo for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultvenue.py b/tests/_inline/test_inlinequeryresultvenue.py index ba09ad7d1..cb5ad760a 100644 --- a/tests/_inline/test_inlinequeryresultvenue.py +++ b/tests/_inline/test_inlinequeryresultvenue.py @@ -31,24 +31,24 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_venue(): return InlineQueryResultVenue( - TestInlineQueryResultVenueBase.id_, - TestInlineQueryResultVenueBase.latitude, - TestInlineQueryResultVenueBase.longitude, - TestInlineQueryResultVenueBase.title, - TestInlineQueryResultVenueBase.address, - foursquare_id=TestInlineQueryResultVenueBase.foursquare_id, - foursquare_type=TestInlineQueryResultVenueBase.foursquare_type, - thumbnail_url=TestInlineQueryResultVenueBase.thumbnail_url, - thumbnail_width=TestInlineQueryResultVenueBase.thumbnail_width, - thumbnail_height=TestInlineQueryResultVenueBase.thumbnail_height, - input_message_content=TestInlineQueryResultVenueBase.input_message_content, - reply_markup=TestInlineQueryResultVenueBase.reply_markup, - google_place_id=TestInlineQueryResultVenueBase.google_place_id, - google_place_type=TestInlineQueryResultVenueBase.google_place_type, + InlineQueryResultVenueTestBase.id_, + InlineQueryResultVenueTestBase.latitude, + InlineQueryResultVenueTestBase.longitude, + InlineQueryResultVenueTestBase.title, + InlineQueryResultVenueTestBase.address, + foursquare_id=InlineQueryResultVenueTestBase.foursquare_id, + foursquare_type=InlineQueryResultVenueTestBase.foursquare_type, + thumbnail_url=InlineQueryResultVenueTestBase.thumbnail_url, + thumbnail_width=InlineQueryResultVenueTestBase.thumbnail_width, + thumbnail_height=InlineQueryResultVenueTestBase.thumbnail_height, + input_message_content=InlineQueryResultVenueTestBase.input_message_content, + reply_markup=InlineQueryResultVenueTestBase.reply_markup, + google_place_id=InlineQueryResultVenueTestBase.google_place_id, + google_place_type=InlineQueryResultVenueTestBase.google_place_type, ) -class TestInlineQueryResultVenueBase: +class InlineQueryResultVenueTestBase: id_ = "id" type_ = "venue" latitude = "latitude" @@ -66,7 +66,7 @@ class TestInlineQueryResultVenueBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultVenueWithoutRequest(TestInlineQueryResultVenueBase): +class TestInlineQueryResultVenueWithoutRequest(InlineQueryResultVenueTestBase): def test_slot_behaviour(self, inline_query_result_venue): inst = inline_query_result_venue for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultvideo.py b/tests/_inline/test_inlinequeryresultvideo.py index 68709e396..7534ad043 100644 --- a/tests/_inline/test_inlinequeryresultvideo.py +++ b/tests/_inline/test_inlinequeryresultvideo.py @@ -32,25 +32,25 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_video(): return InlineQueryResultVideo( - TestInlineQueryResultVideoBase.id_, - TestInlineQueryResultVideoBase.video_url, - TestInlineQueryResultVideoBase.mime_type, - TestInlineQueryResultVideoBase.thumbnail_url, - TestInlineQueryResultVideoBase.title, - video_width=TestInlineQueryResultVideoBase.video_width, - video_height=TestInlineQueryResultVideoBase.video_height, - video_duration=TestInlineQueryResultVideoBase.video_duration, - caption=TestInlineQueryResultVideoBase.caption, - parse_mode=TestInlineQueryResultVideoBase.parse_mode, - caption_entities=TestInlineQueryResultVideoBase.caption_entities, - description=TestInlineQueryResultVideoBase.description, - input_message_content=TestInlineQueryResultVideoBase.input_message_content, - reply_markup=TestInlineQueryResultVideoBase.reply_markup, - show_caption_above_media=TestInlineQueryResultVideoBase.show_caption_above_media, + InlineQueryResultVideoTestBase.id_, + InlineQueryResultVideoTestBase.video_url, + InlineQueryResultVideoTestBase.mime_type, + InlineQueryResultVideoTestBase.thumbnail_url, + InlineQueryResultVideoTestBase.title, + video_width=InlineQueryResultVideoTestBase.video_width, + video_height=InlineQueryResultVideoTestBase.video_height, + video_duration=InlineQueryResultVideoTestBase.video_duration, + caption=InlineQueryResultVideoTestBase.caption, + parse_mode=InlineQueryResultVideoTestBase.parse_mode, + caption_entities=InlineQueryResultVideoTestBase.caption_entities, + description=InlineQueryResultVideoTestBase.description, + input_message_content=InlineQueryResultVideoTestBase.input_message_content, + reply_markup=InlineQueryResultVideoTestBase.reply_markup, + show_caption_above_media=InlineQueryResultVideoTestBase.show_caption_above_media, ) -class TestInlineQueryResultVideoBase: +class InlineQueryResultVideoTestBase: id_ = "id" type_ = "video" video_url = "video url" @@ -69,7 +69,7 @@ class TestInlineQueryResultVideoBase: show_caption_above_media = True -class TestInlineQueryResultVideoWithoutRequest(TestInlineQueryResultVideoBase): +class TestInlineQueryResultVideoWithoutRequest(InlineQueryResultVideoTestBase): def test_slot_behaviour(self, inline_query_result_video): inst = inline_query_result_video for attr in inst.__slots__: diff --git a/tests/_inline/test_inlinequeryresultvoice.py b/tests/_inline/test_inlinequeryresultvoice.py index 34ea013cb..cddbc9d7e 100644 --- a/tests/_inline/test_inlinequeryresultvoice.py +++ b/tests/_inline/test_inlinequeryresultvoice.py @@ -32,19 +32,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_result_voice(): return InlineQueryResultVoice( - id=TestInlineQueryResultVoiceBase.id_, - voice_url=TestInlineQueryResultVoiceBase.voice_url, - title=TestInlineQueryResultVoiceBase.title, - voice_duration=TestInlineQueryResultVoiceBase.voice_duration, - caption=TestInlineQueryResultVoiceBase.caption, - parse_mode=TestInlineQueryResultVoiceBase.parse_mode, - caption_entities=TestInlineQueryResultVoiceBase.caption_entities, - input_message_content=TestInlineQueryResultVoiceBase.input_message_content, - reply_markup=TestInlineQueryResultVoiceBase.reply_markup, + id=InlineQueryResultVoiceTestBase.id_, + voice_url=InlineQueryResultVoiceTestBase.voice_url, + title=InlineQueryResultVoiceTestBase.title, + voice_duration=InlineQueryResultVoiceTestBase.voice_duration, + caption=InlineQueryResultVoiceTestBase.caption, + parse_mode=InlineQueryResultVoiceTestBase.parse_mode, + caption_entities=InlineQueryResultVoiceTestBase.caption_entities, + input_message_content=InlineQueryResultVoiceTestBase.input_message_content, + reply_markup=InlineQueryResultVoiceTestBase.reply_markup, ) -class TestInlineQueryResultVoiceBase: +class InlineQueryResultVoiceTestBase: id_ = "id" type_ = "voice" voice_url = "voice url" @@ -57,7 +57,7 @@ class TestInlineQueryResultVoiceBase: reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("reply_markup")]]) -class TestInlineQueryResultVoiceWithoutRequest(TestInlineQueryResultVoiceBase): +class TestInlineQueryResultVoiceWithoutRequest(InlineQueryResultVoiceTestBase): def test_slot_behaviour(self, inline_query_result_voice): inst = inline_query_result_voice for attr in inst.__slots__: diff --git a/tests/_inline/test_inputcontactmessagecontent.py b/tests/_inline/test_inputcontactmessagecontent.py index 5a48f7dc5..afd1b15f0 100644 --- a/tests/_inline/test_inputcontactmessagecontent.py +++ b/tests/_inline/test_inputcontactmessagecontent.py @@ -25,19 +25,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def input_contact_message_content(): return InputContactMessageContent( - TestInputContactMessageContentBase.phone_number, - TestInputContactMessageContentBase.first_name, - TestInputContactMessageContentBase.last_name, + InputContactMessageContentTestBase.phone_number, + InputContactMessageContentTestBase.first_name, + InputContactMessageContentTestBase.last_name, ) -class TestInputContactMessageContentBase: +class InputContactMessageContentTestBase: phone_number = "phone number" first_name = "first name" last_name = "last name" -class TestInputContactMessageContentWithoutRequest(TestInputContactMessageContentBase): +class TestInputContactMessageContentWithoutRequest(InputContactMessageContentTestBase): def test_slot_behaviour(self, input_contact_message_content): inst = input_contact_message_content for attr in inst.__slots__: diff --git a/tests/_inline/test_inputinvoicemessagecontent.py b/tests/_inline/test_inputinvoicemessagecontent.py index 577ba6775..17bfad013 100644 --- a/tests/_inline/test_inputinvoicemessagecontent.py +++ b/tests/_inline/test_inputinvoicemessagecontent.py @@ -26,32 +26,32 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def input_invoice_message_content(): return InputInvoiceMessageContent( - title=TestInputInvoiceMessageContentBase.title, - description=TestInputInvoiceMessageContentBase.description, - payload=TestInputInvoiceMessageContentBase.payload, - provider_token=TestInputInvoiceMessageContentBase.provider_token, - currency=TestInputInvoiceMessageContentBase.currency, - prices=TestInputInvoiceMessageContentBase.prices, - max_tip_amount=TestInputInvoiceMessageContentBase.max_tip_amount, - suggested_tip_amounts=TestInputInvoiceMessageContentBase.suggested_tip_amounts, - provider_data=TestInputInvoiceMessageContentBase.provider_data, - photo_url=TestInputInvoiceMessageContentBase.photo_url, - photo_size=TestInputInvoiceMessageContentBase.photo_size, - photo_width=TestInputInvoiceMessageContentBase.photo_width, - photo_height=TestInputInvoiceMessageContentBase.photo_height, - need_name=TestInputInvoiceMessageContentBase.need_name, - need_phone_number=TestInputInvoiceMessageContentBase.need_phone_number, - need_email=TestInputInvoiceMessageContentBase.need_email, - need_shipping_address=TestInputInvoiceMessageContentBase.need_shipping_address, + title=InputInvoiceMessageContentTestBase.title, + description=InputInvoiceMessageContentTestBase.description, + payload=InputInvoiceMessageContentTestBase.payload, + provider_token=InputInvoiceMessageContentTestBase.provider_token, + currency=InputInvoiceMessageContentTestBase.currency, + prices=InputInvoiceMessageContentTestBase.prices, + max_tip_amount=InputInvoiceMessageContentTestBase.max_tip_amount, + suggested_tip_amounts=InputInvoiceMessageContentTestBase.suggested_tip_amounts, + provider_data=InputInvoiceMessageContentTestBase.provider_data, + photo_url=InputInvoiceMessageContentTestBase.photo_url, + photo_size=InputInvoiceMessageContentTestBase.photo_size, + photo_width=InputInvoiceMessageContentTestBase.photo_width, + photo_height=InputInvoiceMessageContentTestBase.photo_height, + need_name=InputInvoiceMessageContentTestBase.need_name, + need_phone_number=InputInvoiceMessageContentTestBase.need_phone_number, + need_email=InputInvoiceMessageContentTestBase.need_email, + need_shipping_address=InputInvoiceMessageContentTestBase.need_shipping_address, send_phone_number_to_provider=( - TestInputInvoiceMessageContentBase.send_phone_number_to_provider + InputInvoiceMessageContentTestBase.send_phone_number_to_provider ), - send_email_to_provider=TestInputInvoiceMessageContentBase.send_email_to_provider, - is_flexible=TestInputInvoiceMessageContentBase.is_flexible, + send_email_to_provider=InputInvoiceMessageContentTestBase.send_email_to_provider, + is_flexible=InputInvoiceMessageContentTestBase.is_flexible, ) -class TestInputInvoiceMessageContentBase: +class InputInvoiceMessageContentTestBase: title = "invoice title" description = "invoice description" payload = "invoice payload" @@ -74,7 +74,7 @@ class TestInputInvoiceMessageContentBase: is_flexible = True -class TestInputInvoiceMessageContentWithoutRequest(TestInputInvoiceMessageContentBase): +class TestInputInvoiceMessageContentWithoutRequest(InputInvoiceMessageContentTestBase): def test_slot_behaviour(self, input_invoice_message_content): inst = input_invoice_message_content for attr in inst.__slots__: diff --git a/tests/_inline/test_inputlocationmessagecontent.py b/tests/_inline/test_inputlocationmessagecontent.py index 61d311cae..f2101fca2 100644 --- a/tests/_inline/test_inputlocationmessagecontent.py +++ b/tests/_inline/test_inputlocationmessagecontent.py @@ -25,16 +25,16 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def input_location_message_content(): return InputLocationMessageContent( - TestInputLocationMessageContentBase.latitude, - TestInputLocationMessageContentBase.longitude, - live_period=TestInputLocationMessageContentBase.live_period, - horizontal_accuracy=TestInputLocationMessageContentBase.horizontal_accuracy, - heading=TestInputLocationMessageContentBase.heading, - proximity_alert_radius=TestInputLocationMessageContentBase.proximity_alert_radius, + InputLocationMessageContentTestBase.latitude, + InputLocationMessageContentTestBase.longitude, + live_period=InputLocationMessageContentTestBase.live_period, + horizontal_accuracy=InputLocationMessageContentTestBase.horizontal_accuracy, + heading=InputLocationMessageContentTestBase.heading, + proximity_alert_radius=InputLocationMessageContentTestBase.proximity_alert_radius, ) -class TestInputLocationMessageContentBase: +class InputLocationMessageContentTestBase: latitude = -23.691288 longitude = -46.788279 live_period = 80 @@ -43,7 +43,7 @@ class TestInputLocationMessageContentBase: proximity_alert_radius = 999 -class TestInputLocationMessageContentWithoutRequest(TestInputLocationMessageContentBase): +class TestInputLocationMessageContentWithoutRequest(InputLocationMessageContentTestBase): def test_slot_behaviour(self, input_location_message_content): inst = input_location_message_content for attr in inst.__slots__: diff --git a/tests/_inline/test_inputtextmessagecontent.py b/tests/_inline/test_inputtextmessagecontent.py index 632a29db1..227e0737d 100644 --- a/tests/_inline/test_inputtextmessagecontent.py +++ b/tests/_inline/test_inputtextmessagecontent.py @@ -26,14 +26,14 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def input_text_message_content(): return InputTextMessageContent( - TestInputTextMessageContentBase.message_text, - parse_mode=TestInputTextMessageContentBase.parse_mode, - entities=TestInputTextMessageContentBase.entities, - link_preview_options=TestInputTextMessageContentBase.link_preview_options, + InputTextMessageContentTestBase.message_text, + parse_mode=InputTextMessageContentTestBase.parse_mode, + entities=InputTextMessageContentTestBase.entities, + link_preview_options=InputTextMessageContentTestBase.link_preview_options, ) -class TestInputTextMessageContentBase: +class InputTextMessageContentTestBase: message_text = "*message text*" parse_mode = ParseMode.MARKDOWN entities = [MessageEntity(MessageEntity.ITALIC, 0, 7)] @@ -41,7 +41,7 @@ class TestInputTextMessageContentBase: link_preview_options = LinkPreviewOptions(False, url="https://python-telegram-bot.org") -class TestInputTextMessageContentWithoutRequest(TestInputTextMessageContentBase): +class TestInputTextMessageContentWithoutRequest(InputTextMessageContentTestBase): def test_slot_behaviour(self, input_text_message_content): inst = input_text_message_content for attr in inst.__slots__: diff --git a/tests/_inline/test_inputvenuemessagecontent.py b/tests/_inline/test_inputvenuemessagecontent.py index 8c9d4c62d..d88f9714f 100644 --- a/tests/_inline/test_inputvenuemessagecontent.py +++ b/tests/_inline/test_inputvenuemessagecontent.py @@ -25,18 +25,18 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def input_venue_message_content(): return InputVenueMessageContent( - TestInputVenueMessageContentBase.latitude, - TestInputVenueMessageContentBase.longitude, - TestInputVenueMessageContentBase.title, - TestInputVenueMessageContentBase.address, - foursquare_id=TestInputVenueMessageContentBase.foursquare_id, - foursquare_type=TestInputVenueMessageContentBase.foursquare_type, - google_place_id=TestInputVenueMessageContentBase.google_place_id, - google_place_type=TestInputVenueMessageContentBase.google_place_type, + InputVenueMessageContentTestBase.latitude, + InputVenueMessageContentTestBase.longitude, + InputVenueMessageContentTestBase.title, + InputVenueMessageContentTestBase.address, + foursquare_id=InputVenueMessageContentTestBase.foursquare_id, + foursquare_type=InputVenueMessageContentTestBase.foursquare_type, + google_place_id=InputVenueMessageContentTestBase.google_place_id, + google_place_type=InputVenueMessageContentTestBase.google_place_type, ) -class TestInputVenueMessageContentBase: +class InputVenueMessageContentTestBase: latitude = 1.0 longitude = 2.0 title = "title" @@ -47,7 +47,7 @@ class TestInputVenueMessageContentBase: google_place_type = "google place type" -class TestInputVenueMessageContentWithoutRequest(TestInputVenueMessageContentBase): +class TestInputVenueMessageContentWithoutRequest(InputVenueMessageContentTestBase): def test_slot_behaviour(self, input_venue_message_content): inst = input_venue_message_content for attr in inst.__slots__: diff --git a/tests/_passport/test_encryptedcredentials.py b/tests/_passport/test_encryptedcredentials.py index 3b45ee157..8af9c2cff 100644 --- a/tests/_passport/test_encryptedcredentials.py +++ b/tests/_passport/test_encryptedcredentials.py @@ -26,19 +26,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def encrypted_credentials(): return EncryptedCredentials( - TestEncryptedCredentialsBase.data, - TestEncryptedCredentialsBase.hash, - TestEncryptedCredentialsBase.secret, + EncryptedCredentialsTestBase.data, + EncryptedCredentialsTestBase.hash, + EncryptedCredentialsTestBase.secret, ) -class TestEncryptedCredentialsBase: +class EncryptedCredentialsTestBase: data = "data" hash = "hash" secret = "secret" -class TestEncryptedCredentialsWithoutRequest(TestEncryptedCredentialsBase): +class TestEncryptedCredentialsWithoutRequest(EncryptedCredentialsTestBase): def test_slot_behaviour(self, encrypted_credentials): inst = encrypted_credentials for attr in inst.__slots__: diff --git a/tests/_passport/test_encryptedpassportelement.py b/tests/_passport/test_encryptedpassportelement.py index f12990290..fa79846b6 100644 --- a/tests/_passport/test_encryptedpassportelement.py +++ b/tests/_passport/test_encryptedpassportelement.py @@ -26,19 +26,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def encrypted_passport_element(): return EncryptedPassportElement( - TestEncryptedPassportElementBase.type_, + EncryptedPassportElementTestBase.type_, "this is a hash", - data=TestEncryptedPassportElementBase.data, - phone_number=TestEncryptedPassportElementBase.phone_number, - email=TestEncryptedPassportElementBase.email, - files=TestEncryptedPassportElementBase.files, - front_side=TestEncryptedPassportElementBase.front_side, - reverse_side=TestEncryptedPassportElementBase.reverse_side, - selfie=TestEncryptedPassportElementBase.selfie, + data=EncryptedPassportElementTestBase.data, + phone_number=EncryptedPassportElementTestBase.phone_number, + email=EncryptedPassportElementTestBase.email, + files=EncryptedPassportElementTestBase.files, + front_side=EncryptedPassportElementTestBase.front_side, + reverse_side=EncryptedPassportElementTestBase.reverse_side, + selfie=EncryptedPassportElementTestBase.selfie, ) -class TestEncryptedPassportElementBase: +class EncryptedPassportElementTestBase: type_ = "type" hash = "this is a hash" data = "data" @@ -50,7 +50,7 @@ class TestEncryptedPassportElementBase: selfie = PassportFile("file_id", 50, 0, 25) -class TestEncryptedPassportElementWithoutRequest(TestEncryptedPassportElementBase): +class TestEncryptedPassportElementWithoutRequest(EncryptedPassportElementTestBase): def test_slot_behaviour(self, encrypted_passport_element): inst = encrypted_passport_element for attr in inst.__slots__: diff --git a/tests/_passport/test_passport.py b/tests/_passport/test_passport.py index c35eeaf17..9303ae7eb 100644 --- a/tests/_passport/test_passport.py +++ b/tests/_passport/test_passport.py @@ -220,7 +220,7 @@ def passport_data(bot): return PassportData.de_json(RAW_PASSPORT_DATA, bot=bot) -class TestPassportBase: +class PassportTestBase: driver_license_selfie_file_id = "DgADBAADEQQAAkopgFNr6oi-wISRtAI" driver_license_selfie_file_unique_id = "d4e390cca57b4da5a65322b304762a12" driver_license_front_side_file_id = "DgADBAADxwMAApnQgVPK2-ckL2eXVAI" @@ -243,7 +243,7 @@ class TestPassportBase: driver_license_selfie_credentials_secret = "tivdId6RNYNsvXYPppdzrbxOBuBOr9wXRPDcCvnXU7E=" -class TestPassportWithoutRequest(TestPassportBase): +class TestPassportWithoutRequest(PassportTestBase): def test_slot_behaviour(self, passport_data): inst = passport_data for attr in inst.__slots__: diff --git a/tests/_passport/test_passportelementerrordatafield.py b/tests/_passport/test_passportelementerrordatafield.py index 0d49359a3..5bbf1e7a4 100644 --- a/tests/_passport/test_passportelementerrordatafield.py +++ b/tests/_passport/test_passportelementerrordatafield.py @@ -25,14 +25,14 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_data_field(): return PassportElementErrorDataField( - TestPassportElementErrorDataFieldBase.type_, - TestPassportElementErrorDataFieldBase.field_name, - TestPassportElementErrorDataFieldBase.data_hash, - TestPassportElementErrorDataFieldBase.message, + PassportElementErrorDataFieldTestBase.type_, + PassportElementErrorDataFieldTestBase.field_name, + PassportElementErrorDataFieldTestBase.data_hash, + PassportElementErrorDataFieldTestBase.message, ) -class TestPassportElementErrorDataFieldBase: +class PassportElementErrorDataFieldTestBase: source = "data" type_ = "test_type" field_name = "test_field" @@ -40,7 +40,7 @@ class TestPassportElementErrorDataFieldBase: message = "Error message" -class TestPassportElementErrorDataFieldWithoutRequest(TestPassportElementErrorDataFieldBase): +class TestPassportElementErrorDataFieldWithoutRequest(PassportElementErrorDataFieldTestBase): def test_slot_behaviour(self, passport_element_error_data_field): inst = passport_element_error_data_field for attr in inst.__slots__: diff --git a/tests/_passport/test_passportelementerrorfile.py b/tests/_passport/test_passportelementerrorfile.py index ef892b183..39d4b0449 100644 --- a/tests/_passport/test_passportelementerrorfile.py +++ b/tests/_passport/test_passportelementerrorfile.py @@ -25,20 +25,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_file(): return PassportElementErrorFile( - TestPassportElementErrorFileBase.type_, - TestPassportElementErrorFileBase.file_hash, - TestPassportElementErrorFileBase.message, + PassportElementErrorFileTestBase.type_, + PassportElementErrorFileTestBase.file_hash, + PassportElementErrorFileTestBase.message, ) -class TestPassportElementErrorFileBase: +class PassportElementErrorFileTestBase: source = "file" type_ = "test_type" file_hash = "file_hash" message = "Error message" -class TestPassportElementErrorFileWithoutRequest(TestPassportElementErrorFileBase): +class TestPassportElementErrorFileWithoutRequest(PassportElementErrorFileTestBase): def test_slot_behaviour(self, passport_element_error_file): inst = passport_element_error_file for attr in inst.__slots__: diff --git a/tests/_passport/test_passportelementerrorfiles.py b/tests/_passport/test_passportelementerrorfiles.py index 43ee7cb5d..97bb059ca 100644 --- a/tests/_passport/test_passportelementerrorfiles.py +++ b/tests/_passport/test_passportelementerrorfiles.py @@ -26,20 +26,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_files(): return PassportElementErrorFiles( - TestPassportElementErrorFilesBase.type_, - TestPassportElementErrorFilesBase.file_hashes, - TestPassportElementErrorFilesBase.message, + PassportElementErrorFilesTestBase.type_, + PassportElementErrorFilesTestBase.file_hashes, + PassportElementErrorFilesTestBase.message, ) -class TestPassportElementErrorFilesBase: +class PassportElementErrorFilesTestBase: source = "files" type_ = "test_type" file_hashes = ["hash1", "hash2"] message = "Error message" -class TestPassportElementErrorFilesWithoutRequest(TestPassportElementErrorFilesBase): +class TestPassportElementErrorFilesWithoutRequest(PassportElementErrorFilesTestBase): def test_slot_behaviour(self, passport_element_error_files): inst = passport_element_error_files for attr in inst.__slots__: diff --git a/tests/_passport/test_passportelementerrorfrontside.py b/tests/_passport/test_passportelementerrorfrontside.py index 6a29052d3..3a5694fc8 100644 --- a/tests/_passport/test_passportelementerrorfrontside.py +++ b/tests/_passport/test_passportelementerrorfrontside.py @@ -25,20 +25,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_front_side(): return PassportElementErrorFrontSide( - TestPassportElementErrorFrontSideBase.type_, - TestPassportElementErrorFrontSideBase.file_hash, - TestPassportElementErrorFrontSideBase.message, + PassportElementErrorFrontSideTestBase.type_, + PassportElementErrorFrontSideTestBase.file_hash, + PassportElementErrorFrontSideTestBase.message, ) -class TestPassportElementErrorFrontSideBase: +class PassportElementErrorFrontSideTestBase: source = "front_side" type_ = "test_type" file_hash = "file_hash" message = "Error message" -class TestPassportElementErrorFrontSideWithoutRequest(TestPassportElementErrorFrontSideBase): +class TestPassportElementErrorFrontSideWithoutRequest(PassportElementErrorFrontSideTestBase): def test_slot_behaviour(self, passport_element_error_front_side): inst = passport_element_error_front_side for attr in inst.__slots__: diff --git a/tests/_passport/test_passportelementerrorreverseside.py b/tests/_passport/test_passportelementerrorreverseside.py index bda4cd731..e6b1bae9e 100644 --- a/tests/_passport/test_passportelementerrorreverseside.py +++ b/tests/_passport/test_passportelementerrorreverseside.py @@ -25,20 +25,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_reverse_side(): return PassportElementErrorReverseSide( - TestPassportElementErrorReverseSideBase.type_, - TestPassportElementErrorReverseSideBase.file_hash, - TestPassportElementErrorReverseSideBase.message, + PassportElementErrorReverseSideTestBase.type_, + PassportElementErrorReverseSideTestBase.file_hash, + PassportElementErrorReverseSideTestBase.message, ) -class TestPassportElementErrorReverseSideBase: +class PassportElementErrorReverseSideTestBase: source = "reverse_side" type_ = "test_type" file_hash = "file_hash" message = "Error message" -class TestPassportElementErrorReverseSideWithoutRequest(TestPassportElementErrorReverseSideBase): +class TestPassportElementErrorReverseSideWithoutRequest(PassportElementErrorReverseSideTestBase): def test_slot_behaviour(self, passport_element_error_reverse_side): inst = passport_element_error_reverse_side for attr in inst.__slots__: diff --git a/tests/_passport/test_passportelementerrorselfie.py b/tests/_passport/test_passportelementerrorselfie.py index 9580e24ae..a7af4ecdc 100644 --- a/tests/_passport/test_passportelementerrorselfie.py +++ b/tests/_passport/test_passportelementerrorselfie.py @@ -25,20 +25,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_selfie(): return PassportElementErrorSelfie( - TestPassportElementErrorSelfieBase.type_, - TestPassportElementErrorSelfieBase.file_hash, - TestPassportElementErrorSelfieBase.message, + PassportElementErrorSelfieTestBase.type_, + PassportElementErrorSelfieTestBase.file_hash, + PassportElementErrorSelfieTestBase.message, ) -class TestPassportElementErrorSelfieBase: +class PassportElementErrorSelfieTestBase: source = "selfie" type_ = "test_type" file_hash = "file_hash" message = "Error message" -class TestPassportElementErrorSelfieWithoutRequest(TestPassportElementErrorSelfieBase): +class TestPassportElementErrorSelfieWithoutRequest(PassportElementErrorSelfieTestBase): def test_slot_behaviour(self, passport_element_error_selfie): inst = passport_element_error_selfie for attr in inst.__slots__: diff --git a/tests/_passport/test_passportelementerrortranslationfile.py b/tests/_passport/test_passportelementerrortranslationfile.py index f55a8ad70..0493f7e3f 100644 --- a/tests/_passport/test_passportelementerrortranslationfile.py +++ b/tests/_passport/test_passportelementerrortranslationfile.py @@ -25,13 +25,13 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_translation_file(): return PassportElementErrorTranslationFile( - TestPassportElementErrorTranslationFileBase.type_, - TestPassportElementErrorTranslationFileBase.file_hash, - TestPassportElementErrorTranslationFileBase.message, + PassportElementErrorTranslationFileTestBase.type_, + PassportElementErrorTranslationFileTestBase.file_hash, + PassportElementErrorTranslationFileTestBase.message, ) -class TestPassportElementErrorTranslationFileBase: +class PassportElementErrorTranslationFileTestBase: source = "translation_file" type_ = "test_type" file_hash = "file_hash" @@ -39,7 +39,7 @@ class TestPassportElementErrorTranslationFileBase: class TestPassportElementErrorTranslationFileWithoutRequest( - TestPassportElementErrorTranslationFileBase + PassportElementErrorTranslationFileTestBase ): def test_slot_behaviour(self, passport_element_error_translation_file): inst = passport_element_error_translation_file diff --git a/tests/_passport/test_passportelementerrortranslationfiles.py b/tests/_passport/test_passportelementerrortranslationfiles.py index eb62aa5d1..8412ef300 100644 --- a/tests/_passport/test_passportelementerrortranslationfiles.py +++ b/tests/_passport/test_passportelementerrortranslationfiles.py @@ -26,13 +26,13 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_translation_files(): return PassportElementErrorTranslationFiles( - TestPassportElementErrorTranslationFilesBase.type_, - TestPassportElementErrorTranslationFilesBase.file_hashes, - TestPassportElementErrorTranslationFilesBase.message, + PassportElementErrorTranslationFilesTestBase.type_, + PassportElementErrorTranslationFilesTestBase.file_hashes, + PassportElementErrorTranslationFilesTestBase.message, ) -class TestPassportElementErrorTranslationFilesBase: +class PassportElementErrorTranslationFilesTestBase: source = "translation_files" type_ = "test_type" file_hashes = ["hash1", "hash2"] @@ -40,7 +40,7 @@ class TestPassportElementErrorTranslationFilesBase: class TestPassportElementErrorTranslationFilesWithoutRequest( - TestPassportElementErrorTranslationFilesBase + PassportElementErrorTranslationFilesTestBase ): def test_slot_behaviour(self, passport_element_error_translation_files): inst = passport_element_error_translation_files diff --git a/tests/_passport/test_passportelementerrorunspecified.py b/tests/_passport/test_passportelementerrorunspecified.py index 260192e18..d3b6105b2 100644 --- a/tests/_passport/test_passportelementerrorunspecified.py +++ b/tests/_passport/test_passportelementerrorunspecified.py @@ -25,20 +25,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def passport_element_error_unspecified(): return PassportElementErrorUnspecified( - TestPassportElementErrorUnspecifiedBase.type_, - TestPassportElementErrorUnspecifiedBase.element_hash, - TestPassportElementErrorUnspecifiedBase.message, + PassportElementErrorUnspecifiedTestBase.type_, + PassportElementErrorUnspecifiedTestBase.element_hash, + PassportElementErrorUnspecifiedTestBase.message, ) -class TestPassportElementErrorUnspecifiedBase: +class PassportElementErrorUnspecifiedTestBase: source = "unspecified" type_ = "test_type" element_hash = "element_hash" message = "Error message" -class TestPassportElementErrorUnspecifiedWithoutRequest(TestPassportElementErrorUnspecifiedBase): +class TestPassportElementErrorUnspecifiedWithoutRequest(PassportElementErrorUnspecifiedTestBase): def test_slot_behaviour(self, passport_element_error_unspecified): inst = passport_element_error_unspecified for attr in inst.__slots__: diff --git a/tests/_passport/test_passportfile.py b/tests/_passport/test_passportfile.py index d12e0ce9f..8fef970be 100644 --- a/tests/_passport/test_passportfile.py +++ b/tests/_passport/test_passportfile.py @@ -31,23 +31,23 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="class") def passport_file(bot): pf = PassportFile( - file_id=TestPassportFileBase.file_id, - file_unique_id=TestPassportFileBase.file_unique_id, - file_size=TestPassportFileBase.file_size, - file_date=TestPassportFileBase.file_date, + file_id=PassportFileTestBase.file_id, + file_unique_id=PassportFileTestBase.file_unique_id, + file_size=PassportFileTestBase.file_size, + file_date=PassportFileTestBase.file_date, ) pf.set_bot(bot) return pf -class TestPassportFileBase: +class PassportFileTestBase: file_id = "data" file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e" file_size = 50 file_date = 1532879128 -class TestPassportFileWithoutRequest(TestPassportFileBase): +class TestPassportFileWithoutRequest(PassportFileTestBase): def test_slot_behaviour(self, passport_file): inst = passport_file for attr in inst.__slots__: diff --git a/tests/_payment/test_invoice.py b/tests/_payment/test_invoice.py index 65a39aeb3..2293fe587 100644 --- a/tests/_payment/test_invoice.py +++ b/tests/_payment/test_invoice.py @@ -31,15 +31,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def invoice(): return Invoice( - TestInvoiceBase.title, - TestInvoiceBase.description, - TestInvoiceBase.start_parameter, - TestInvoiceBase.currency, - TestInvoiceBase.total_amount, + InvoiceTestBase.title, + InvoiceTestBase.description, + InvoiceTestBase.start_parameter, + InvoiceTestBase.currency, + InvoiceTestBase.total_amount, ) -class TestInvoiceBase: +class InvoiceTestBase: payload = "payload" prices = [LabeledPrice("Fish", 100), LabeledPrice("Fish Tax", 1000)] provider_data = """{"test":"test"}""" @@ -52,7 +52,7 @@ class TestInvoiceBase: suggested_tip_amounts = [13, 42] -class TestInvoiceWithoutRequest(TestInvoiceBase): +class TestInvoiceWithoutRequest(InvoiceTestBase): def test_slot_behaviour(self, invoice): for attr in invoice.__slots__: assert getattr(invoice, attr, "err") != "err", f"got extra slot '{attr}'" @@ -219,7 +219,7 @@ class TestInvoiceWithoutRequest(TestInvoiceBase): assert hash(a) != hash(d) -class TestInvoiceWithRequest(TestInvoiceBase): +class TestInvoiceWithRequest(InvoiceTestBase): async def test_send_required_args_only(self, bot, chat_id, provider_token): message = await bot.send_invoice( chat_id=chat_id, diff --git a/tests/_payment/test_labeledprice.py b/tests/_payment/test_labeledprice.py index c05672de3..7647a704c 100644 --- a/tests/_payment/test_labeledprice.py +++ b/tests/_payment/test_labeledprice.py @@ -24,15 +24,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def labeled_price(): - return LabeledPrice(TestLabeledPriceBase.label, TestLabeledPriceBase.amount) + return LabeledPrice(LabeledPriceTestBase.label, LabeledPriceTestBase.amount) -class TestLabeledPriceBase: +class LabeledPriceTestBase: label = "label" amount = 100 -class TestLabeledPriceWithoutRequest(TestLabeledPriceBase): +class TestLabeledPriceWithoutRequest(LabeledPriceTestBase): def test_slot_behaviour(self, labeled_price): inst = labeled_price for attr in inst.__slots__: diff --git a/tests/_payment/test_orderinfo.py b/tests/_payment/test_orderinfo.py index a8a01fb5e..8e27ed343 100644 --- a/tests/_payment/test_orderinfo.py +++ b/tests/_payment/test_orderinfo.py @@ -25,21 +25,21 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def order_info(): return OrderInfo( - TestOrderInfoBase.name, - TestOrderInfoBase.phone_number, - TestOrderInfoBase.email, - TestOrderInfoBase.shipping_address, + OrderInfoTestBase.name, + OrderInfoTestBase.phone_number, + OrderInfoTestBase.email, + OrderInfoTestBase.shipping_address, ) -class TestOrderInfoBase: +class OrderInfoTestBase: name = "name" phone_number = "phone_number" email = "email" shipping_address = ShippingAddress("GB", "", "London", "12 Grimmauld Place", "", "WC1") -class TestOrderInfoWithoutRequest(TestOrderInfoBase): +class TestOrderInfoWithoutRequest(OrderInfoTestBase): def test_slot_behaviour(self, order_info): for attr in order_info.__slots__: assert getattr(order_info, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/_payment/test_precheckoutquery.py b/tests/_payment/test_precheckoutquery.py index 57637187d..aaca70407 100644 --- a/tests/_payment/test_precheckoutquery.py +++ b/tests/_payment/test_precheckoutquery.py @@ -31,19 +31,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def pre_checkout_query(bot): pcq = PreCheckoutQuery( - TestPreCheckoutQueryBase.id_, - TestPreCheckoutQueryBase.from_user, - TestPreCheckoutQueryBase.currency, - TestPreCheckoutQueryBase.total_amount, - TestPreCheckoutQueryBase.invoice_payload, - shipping_option_id=TestPreCheckoutQueryBase.shipping_option_id, - order_info=TestPreCheckoutQueryBase.order_info, + PreCheckoutQueryTestBase.id_, + PreCheckoutQueryTestBase.from_user, + PreCheckoutQueryTestBase.currency, + PreCheckoutQueryTestBase.total_amount, + PreCheckoutQueryTestBase.invoice_payload, + shipping_option_id=PreCheckoutQueryTestBase.shipping_option_id, + order_info=PreCheckoutQueryTestBase.order_info, ) pcq.set_bot(bot) return pcq -class TestPreCheckoutQueryBase: +class PreCheckoutQueryTestBase: id_ = 5 invoice_payload = "invoice_payload" shipping_option_id = "shipping_option_id" @@ -53,7 +53,7 @@ class TestPreCheckoutQueryBase: order_info = OrderInfo() -class TestPreCheckoutQueryWithoutRequest(TestPreCheckoutQueryBase): +class TestPreCheckoutQueryWithoutRequest(PreCheckoutQueryTestBase): def test_slot_behaviour(self, pre_checkout_query): inst = pre_checkout_query for attr in inst.__slots__: diff --git a/tests/_payment/test_refundedpayment.py b/tests/_payment/test_refundedpayment.py index 75e252660..8ea4d1a50 100644 --- a/tests/_payment/test_refundedpayment.py +++ b/tests/_payment/test_refundedpayment.py @@ -25,15 +25,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def refunded_payment(): return RefundedPayment( - TestRefundedPaymentBase.currency, - TestRefundedPaymentBase.total_amount, - TestRefundedPaymentBase.invoice_payload, - TestRefundedPaymentBase.telegram_payment_charge_id, - TestRefundedPaymentBase.provider_payment_charge_id, + RefundedPaymentTestBase.currency, + RefundedPaymentTestBase.total_amount, + RefundedPaymentTestBase.invoice_payload, + RefundedPaymentTestBase.telegram_payment_charge_id, + RefundedPaymentTestBase.provider_payment_charge_id, ) -class TestRefundedPaymentBase: +class RefundedPaymentTestBase: invoice_payload = "invoice_payload" currency = "EUR" total_amount = 100 @@ -41,7 +41,7 @@ class TestRefundedPaymentBase: provider_payment_charge_id = "provider_payment_charge_id" -class TestRefundedPaymentWithoutRequest(TestRefundedPaymentBase): +class TestRefundedPaymentWithoutRequest(RefundedPaymentTestBase): def test_slot_behaviour(self, refunded_payment): inst = refunded_payment for attr in inst.__slots__: diff --git a/tests/_payment/test_shippingaddress.py b/tests/_payment/test_shippingaddress.py index ee69fded9..41fbeba5a 100644 --- a/tests/_payment/test_shippingaddress.py +++ b/tests/_payment/test_shippingaddress.py @@ -25,16 +25,16 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def shipping_address(): return ShippingAddress( - TestShippingAddressBase.country_code, - TestShippingAddressBase.state, - TestShippingAddressBase.city, - TestShippingAddressBase.street_line1, - TestShippingAddressBase.street_line2, - TestShippingAddressBase.post_code, + ShippingAddressTestBase.country_code, + ShippingAddressTestBase.state, + ShippingAddressTestBase.city, + ShippingAddressTestBase.street_line1, + ShippingAddressTestBase.street_line2, + ShippingAddressTestBase.post_code, ) -class TestShippingAddressBase: +class ShippingAddressTestBase: country_code = "GB" state = "state" city = "London" @@ -43,7 +43,7 @@ class TestShippingAddressBase: post_code = "WC1" -class TestShippingAddressWithoutRequest(TestShippingAddressBase): +class TestShippingAddressWithoutRequest(ShippingAddressTestBase): def test_slot_behaviour(self, shipping_address): inst = shipping_address for attr in inst.__slots__: diff --git a/tests/_payment/test_shippingoption.py b/tests/_payment/test_shippingoption.py index cc9698790..5ce619488 100644 --- a/tests/_payment/test_shippingoption.py +++ b/tests/_payment/test_shippingoption.py @@ -25,17 +25,17 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def shipping_option(): return ShippingOption( - TestShippingOptionBase.id_, TestShippingOptionBase.title, TestShippingOptionBase.prices + ShippingOptionTestBase.id_, ShippingOptionTestBase.title, ShippingOptionTestBase.prices ) -class TestShippingOptionBase: +class ShippingOptionTestBase: id_ = "id" title = "title" prices = [LabeledPrice("Fish Container", 100), LabeledPrice("Premium Fish Container", 1000)] -class TestShippingOptionWithoutRequest(TestShippingOptionBase): +class TestShippingOptionWithoutRequest(ShippingOptionTestBase): def test_slot_behaviour(self, shipping_option): inst = shipping_option for attr in inst.__slots__: diff --git a/tests/_payment/test_shippingquery.py b/tests/_payment/test_shippingquery.py index bf8fc820d..4821cbae9 100644 --- a/tests/_payment/test_shippingquery.py +++ b/tests/_payment/test_shippingquery.py @@ -31,23 +31,23 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def shipping_query(bot): sq = ShippingQuery( - TestShippingQueryBase.id_, - TestShippingQueryBase.from_user, - TestShippingQueryBase.invoice_payload, - TestShippingQueryBase.shipping_address, + ShippingQueryTestBase.id_, + ShippingQueryTestBase.from_user, + ShippingQueryTestBase.invoice_payload, + ShippingQueryTestBase.shipping_address, ) sq.set_bot(bot) return sq -class TestShippingQueryBase: +class ShippingQueryTestBase: id_ = "5" invoice_payload = "invoice_payload" from_user = User(0, "", False) shipping_address = ShippingAddress("GB", "", "London", "12 Grimmauld Place", "", "WC1") -class TestShippingQueryWithoutRequest(TestShippingQueryBase): +class TestShippingQueryWithoutRequest(ShippingQueryTestBase): def test_slot_behaviour(self, shipping_query): inst = shipping_query for attr in inst.__slots__: diff --git a/tests/_payment/test_successfulpayment.py b/tests/_payment/test_successfulpayment.py index a93238c53..c4562d0a8 100644 --- a/tests/_payment/test_successfulpayment.py +++ b/tests/_payment/test_successfulpayment.py @@ -25,17 +25,17 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def successful_payment(): return SuccessfulPayment( - TestSuccessfulPaymentBase.currency, - TestSuccessfulPaymentBase.total_amount, - TestSuccessfulPaymentBase.invoice_payload, - TestSuccessfulPaymentBase.telegram_payment_charge_id, - TestSuccessfulPaymentBase.provider_payment_charge_id, - shipping_option_id=TestSuccessfulPaymentBase.shipping_option_id, - order_info=TestSuccessfulPaymentBase.order_info, + SuccessfulPaymentTestBase.currency, + SuccessfulPaymentTestBase.total_amount, + SuccessfulPaymentTestBase.invoice_payload, + SuccessfulPaymentTestBase.telegram_payment_charge_id, + SuccessfulPaymentTestBase.provider_payment_charge_id, + shipping_option_id=SuccessfulPaymentTestBase.shipping_option_id, + order_info=SuccessfulPaymentTestBase.order_info, ) -class TestSuccessfulPaymentBase: +class SuccessfulPaymentTestBase: invoice_payload = "invoice_payload" shipping_option_id = "shipping_option_id" currency = "EUR" @@ -45,7 +45,7 @@ class TestSuccessfulPaymentBase: provider_payment_charge_id = "provider_payment_charge_id" -class TestSuccessfulPaymentWithoutRequest(TestSuccessfulPaymentBase): +class TestSuccessfulPaymentWithoutRequest(SuccessfulPaymentTestBase): def test_slot_behaviour(self, successful_payment): inst = successful_payment for attr in inst.__slots__: diff --git a/tests/auxil/ci_bots.py b/tests/auxil/ci_bots.py index bdb25a2f0..069a65cce 100644 --- a/tests/auxil/ci_bots.py +++ b/tests/auxil/ci_bots.py @@ -29,15 +29,16 @@ from telegram._utils.strings import TextEncoding # purposes than testing. FALLBACKS = ( "W3sidG9rZW4iOiAiNTc5Njk0NzE0OkFBRnBLOHc2emtrVXJENHhTZVl3RjNNTzhlLTRHcm1jeTdjIiwgInBheW1lbnRfc" - "HJvdmlkZXJfdG9rZW4iOiAiMjg0Njg1MDYzOlRFU1Q6TmpRME5qWmxOekk1WWpKaSIsICJjaGF0X2 lkIjogIjY3NTY2N" - "jIyNCIsICJzdXBlcl9ncm91cF9pZCI6ICItMTAwMTMxMDkxMTEzNSIsICJmb3J1bV9ncm91cF9pZCI6ICItMTAwMTgzOD" - "AwNDU3NyIsICJjaGFubmVsX2lkIjogIkBweXRob250ZWxlZ3JhbWJvdHRlc3RzIi wgIm5hbWUiOiAiUFRCIHRlc3RzIG" - "ZhbGxiYWNrIDEiLCAidXNlcm5hbWUiOiAiQHB0Yl9mYWxsYmFja18xX2JvdCJ9LCB7InRva2VuIjogIjU1ODE5NDA2Njp" - "BQUZ3RFBJRmx6R1VsQ2FXSHRUT0VYNFJGclg4dTlETXFmbyIsIC JwYXltZW50X3Byb3ZpZGVyX3Rva2VuIjogIjI4NDY" - "4NTA2MzpURVNUOllqRXdPRFF3TVRGbU5EY3kiLCAiY2hhdF9pZCI6ICI2NzU2NjYyMjQiLCAic3VwZXJfZ3JvdXBfaWQi" - "OiAiLTEwMDEyMjEyMTY4MzAiLCAiZm9ydW1fZ3 JvdXBfaWQiOiAiLTEwMDE4NTc4NDgzMTQiLCAiY2hhbm5lbF9pZCI6" - "ICJAcHl0aG9udGVsZWdyYW1ib3R0ZXN0cyIsICJuYW1lIjogIlBUQiB0ZXN0cyBmYWxsYmFjayAyIiwgInVzZXJuYW1lI" - "jogIkBwdGJfZmFsbGJhY2tfMl9ib3QifV0=" + "HJvdmlkZXJfdG9rZW4iOiAiMjg0Njg1MDYzOlRFU1Q6TmpRME5qWmxOekk1WWpKaSIsICJjaGF0X2lkIjogIjY3NTY2Nj" + "IyNCIsICJzdXBlcl9ncm91cF9pZCI6ICItMTAwMTMxMDkxMTEzNSIsICJmb3J1bV9ncm91cF9pZCI6ICItMTAwMTgzODA" + "wNDU3NyIsICJjaGFubmVsX2lkIjogIkBweXRob250ZWxlZ3JhbWJvdHRlc3RzIiwgIm5hbWUiOiAiUFRCIHRlc3RzIGZh" + "bGxiYWNrIDEiLCAidXNlcm5hbWUiOiAiQHB0Yl9mYWxsYmFja18xX2JvdCIsICJzdWJzY3JpcHRpb25fY2hhbm5lbF9pZ" + "CI6IC0xMDAyMjI5NjQ5MzAzfSwgeyJ0b2tlbiI6ICI1NTgxOTQwNjY6QUFGd0RQSUZsekdVbENhV0h0VE9FWDRSRnJYOH" + "U5RE1xZm8iLCAicGF5bWVudF9wcm92aWRlcl90b2tlbiI6ICIyODQ2ODUwNjM6VEVTVDpZakV3T0RRd01URm1ORGN5Iiw" + "gImNoYXRfaWQiOiAiNjc1NjY2MjI0IiwgInN1cGVyX2dyb3VwX2lkIjogIi0xMDAxMjIxMjE2ODMwIiwgImZvcnVtX2dy" + "b3VwX2lkIjogIi0xMDAxODU3ODQ4MzE0IiwgImNoYW5uZWxfaWQiOiAiQHB5dGhvbnRlbGVncmFtYm90dGVzdHMiLCAib" + "mFtZSI6ICJQVEIgdGVzdHMgZmFsbGJhY2sgMiIsICJ1c2VybmFtZSI6ICJAcHRiX2ZhbGxiYWNrXzJfYm90IiwgInN1Yn" + "NjcmlwdGlvbl9jaGFubmVsX2lkIjogLTEwMDIyMjk2NDkzMDN9XQ==" ) GITHUB_ACTION = os.getenv("GITHUB_ACTION", None) diff --git a/tests/conftest.py b/tests/conftest.py index dd553f9fe..c721605bd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -206,6 +206,11 @@ def provider_token(bot_info): return bot_info["payment_provider_token"] +@pytest.fixture(scope="session") +def subscription_channel_id(bot_info): + return bot_info["subscription_channel_id"] + + @pytest.fixture async def app(bot_info): # We build a new bot each time so that we use `app` in a context manager without problems diff --git a/tests/ext/test_updater.py b/tests/ext/test_updater.py index f72161008..84a86c988 100644 --- a/tests/ext/test_updater.py +++ b/tests/ext/test_updater.py @@ -571,7 +571,7 @@ class TestUpdater: else: assert len(caplog.records) > 0 assert any( - "Error while getting Updates:" in record.getMessage() + "Exception happened while polling for updates." in record.getMessage() and record.name == "telegram.ext.Updater" for record in caplog.records ) @@ -593,7 +593,7 @@ class TestUpdater: else: assert len(caplog.records) > 0 assert any( - "Error while getting Updates:" in record.getMessage() + "Exception happened while polling for updates." in record.getMessage() and record.name == "telegram.ext.Updater" for record in caplog.records ) diff --git a/tests/test_birthdate.py b/tests/test_birthdate.py index a5e90d413..c22ebd9af 100644 --- a/tests/test_birthdate.py +++ b/tests/test_birthdate.py @@ -24,7 +24,7 @@ from telegram import Birthdate from tests.auxil.slots import mro_slots -class TestBirthdateBase: +class BirthdateTestBase: day = 1 month = 1 year = 2022 @@ -32,10 +32,10 @@ class TestBirthdateBase: @pytest.fixture(scope="module") def birthdate(): - return Birthdate(TestBirthdateBase.day, TestBirthdateBase.month, TestBirthdateBase.year) + return Birthdate(BirthdateTestBase.day, BirthdateTestBase.month, BirthdateTestBase.year) -class TestBirthdateWithoutRequest(TestBirthdateBase): +class TestBirthdateWithoutRequest(BirthdateTestBase): def test_slot_behaviour(self, birthdate): for attr in birthdate.__slots__: assert getattr(birthdate, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_bot.py b/tests/test_bot.py index cdf00082d..705b14c6d 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -2265,6 +2265,21 @@ class TestBotWithoutRequest: obj = await bot.get_star_transactions(offset=3) assert isinstance(obj, StarTransactions) + async def test_create_chat_subscription_invite_link( + self, + monkeypatch, + bot, + ): + # Since the chat invite link object does not say if the sub args are passed we can + # only check here + async def make_assertion(url, request_data: RequestData, *args, **kwargs): + assert request_data.parameters.get("subscription_period") == 2592000 + assert request_data.parameters.get("subscription_price") == 6 + + monkeypatch.setattr(bot.request, "post", make_assertion) + + await bot.create_chat_subscription_invite_link(1234, 2592000, 6) + class TestBotWithRequest: """ @@ -3093,7 +3108,7 @@ class TestBotWithRequest: async def test_get_chat_member(self, bot, channel_id, chat_id): chat_member = await bot.get_chat_member(channel_id, chat_id) - assert chat_member.status == "administrator" + assert chat_member.status == "creator" assert chat_member.user.first_name == "PTB" assert chat_member.user.last_name == "Test user" @@ -3267,7 +3282,7 @@ class TestBotWithRequest: with pytest.raises(BadRequest, match="Not enough rights"): assert await bot.promote_chat_member( channel_id, - 95205500, + 1325859552, is_anonymous=True, can_change_info=True, can_post_messages=True, @@ -3290,7 +3305,7 @@ class TestBotWithRequest: data = args[1] return ( data.get("chat_id") == channel_id - and data.get("user_id") == 95205500 + and data.get("user_id") == 1325859552 and data.get("is_anonymous") == 1 and data.get("can_change_info") == 2 and data.get("can_post_messages") == 3 @@ -3311,7 +3326,7 @@ class TestBotWithRequest: monkeypatch.setattr(bot, "_post", make_assertion) assert await bot.promote_chat_member( channel_id, - 95205500, + 1325859552, is_anonymous=1, can_change_info=2, can_post_messages=3, @@ -4261,3 +4276,23 @@ class TestBotWithRequest: transactions = await bot.get_star_transactions(limit=1) assert isinstance(transactions, StarTransactions) assert len(transactions.transactions) == 0 + + async def test_create_edit_chat_subscription_link( + self, bot, subscription_channel_id, channel_id + ): + sub_link = await bot.create_chat_subscription_invite_link( + subscription_channel_id, + name="sub_name", + subscription_period=2592000, + subscription_price=13, + ) + assert sub_link.name == "sub_name" + assert sub_link.subscription_period == 2592000 + assert sub_link.subscription_price == 13 + + edited_link = await bot.edit_chat_subscription_invite_link( + chat_id=subscription_channel_id, invite_link=sub_link, name="sub_name_2" + ) + assert edited_link.name == "sub_name_2" + assert sub_link.subscription_period == 2592000 + assert sub_link.subscription_price == 13 diff --git a/tests/test_botdescription.py b/tests/test_botdescription.py index 4e84eb558..a75a88cb1 100644 --- a/tests/test_botdescription.py +++ b/tests/test_botdescription.py @@ -24,20 +24,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def bot_description(bot): - return BotDescription(TestBotDescriptionBase.description) + return BotDescription(BotDescriptionTestBase.description) @pytest.fixture(scope="module") def bot_short_description(bot): - return BotShortDescription(TestBotDescriptionBase.short_description) + return BotShortDescription(BotDescriptionTestBase.short_description) -class TestBotDescriptionBase: +class BotDescriptionTestBase: description = "This is a test description" short_description = "This is a test short description" -class TestBotDescriptionWithoutRequest(TestBotDescriptionBase): +class TestBotDescriptionWithoutRequest(BotDescriptionTestBase): def test_slot_behaviour(self, bot_description): for attr in bot_description.__slots__: assert getattr(bot_description, attr, "err") != "err", f"got extra slot '{attr}'" @@ -64,7 +64,7 @@ class TestBotDescriptionWithoutRequest(TestBotDescriptionBase): assert hash(a) != hash(c) -class TestBotShortDescriptionWithoutRequest(TestBotDescriptionBase): +class TestBotShortDescriptionWithoutRequest(BotDescriptionTestBase): def test_slot_behaviour(self, bot_short_description): for attr in bot_short_description.__slots__: assert getattr(bot_short_description, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_botname.py b/tests/test_botname.py index 3fadfa76b..4edefae39 100644 --- a/tests/test_botname.py +++ b/tests/test_botname.py @@ -24,14 +24,14 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def bot_name(bot): - return BotName(TestBotNameBase.name) + return BotName(BotNameTestBase.name) -class TestBotNameBase: +class BotNameTestBase: name = "This is a test name" -class TestBotNameWithoutRequest(TestBotNameBase): +class TestBotNameWithoutRequest(BotNameTestBase): def test_slot_behaviour(self, bot_name): for attr in bot_name.__slots__: assert getattr(bot_name, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_business.py b/tests/test_business.py index da6838d6d..735f2e717 100644 --- a/tests/test_business.py +++ b/tests/test_business.py @@ -36,7 +36,7 @@ from telegram._utils.datetime import UTC, to_timestamp from tests.auxil.slots import mro_slots -class TestBusinessBase: +class BusinessTestBase: id_ = "123" user = User(123, "test_user", False) user_chat_id = 123 @@ -62,58 +62,58 @@ class TestBusinessBase: @pytest.fixture(scope="module") def business_connection(): return BusinessConnection( - TestBusinessBase.id_, - TestBusinessBase.user, - TestBusinessBase.user_chat_id, - TestBusinessBase.date, - TestBusinessBase.can_reply, - TestBusinessBase.is_enabled, + BusinessTestBase.id_, + BusinessTestBase.user, + BusinessTestBase.user_chat_id, + BusinessTestBase.date, + BusinessTestBase.can_reply, + BusinessTestBase.is_enabled, ) @pytest.fixture(scope="module") def business_messages_deleted(): return BusinessMessagesDeleted( - TestBusinessBase.business_connection_id, - TestBusinessBase.chat, - TestBusinessBase.message_ids, + BusinessTestBase.business_connection_id, + BusinessTestBase.chat, + BusinessTestBase.message_ids, ) @pytest.fixture(scope="module") def business_intro(): return BusinessIntro( - TestBusinessBase.title, - TestBusinessBase.message, - TestBusinessBase.sticker, + BusinessTestBase.title, + BusinessTestBase.message, + BusinessTestBase.sticker, ) @pytest.fixture(scope="module") def business_location(): return BusinessLocation( - TestBusinessBase.address, - TestBusinessBase.location, + BusinessTestBase.address, + BusinessTestBase.location, ) @pytest.fixture(scope="module") def business_opening_hours_interval(): return BusinessOpeningHoursInterval( - TestBusinessBase.opening_minute, - TestBusinessBase.closing_minute, + BusinessTestBase.opening_minute, + BusinessTestBase.closing_minute, ) @pytest.fixture(scope="module") def business_opening_hours(): return BusinessOpeningHours( - TestBusinessBase.time_zone_name, - TestBusinessBase.opening_hours, + BusinessTestBase.time_zone_name, + BusinessTestBase.opening_hours, ) -class TestBusinessConnectionWithoutRequest(TestBusinessBase): +class TestBusinessConnectionWithoutRequest(BusinessTestBase): def test_slots(self, business_connection): bc = business_connection for attr in bc.__slots__: @@ -188,7 +188,7 @@ class TestBusinessConnectionWithoutRequest(TestBusinessBase): assert hash(bc1) != hash(bc3) -class TestBusinessMessagesDeleted(TestBusinessBase): +class TestBusinessMessagesDeleted(BusinessTestBase): def test_slots(self, business_messages_deleted): bmd = business_messages_deleted for attr in bmd.__slots__: @@ -227,7 +227,7 @@ class TestBusinessMessagesDeleted(TestBusinessBase): assert hash(bmd1) != hash(bmd3) -class TestBusinessIntroWithoutRequest(TestBusinessBase): +class TestBusinessIntroWithoutRequest(BusinessTestBase): def test_slot_behaviour(self, business_intro): intro = business_intro for attr in intro.__slots__: @@ -267,7 +267,7 @@ class TestBusinessIntroWithoutRequest(TestBusinessBase): assert hash(intro1) != hash(intro3) -class TestBusinessLocationWithoutRequest(TestBusinessBase): +class TestBusinessLocationWithoutRequest(BusinessTestBase): def test_slot_behaviour(self, business_location): inst = business_location for attr in inst.__slots__: @@ -304,7 +304,7 @@ class TestBusinessLocationWithoutRequest(TestBusinessBase): assert hash(blc1) != hash(blc3) -class TestBusinessOpeningHoursIntervalWithoutRequest(TestBusinessBase): +class TestBusinessOpeningHoursIntervalWithoutRequest(BusinessTestBase): def test_slot_behaviour(self, business_opening_hours_interval): inst = business_opening_hours_interval for attr in inst.__slots__: @@ -375,7 +375,7 @@ class TestBusinessOpeningHoursIntervalWithoutRequest(TestBusinessBase): assert cached is closing_time -class TestBusinessOpeningHoursWithoutRequest(TestBusinessBase): +class TestBusinessOpeningHoursWithoutRequest(BusinessTestBase): def test_slot_behaviour(self, business_opening_hours): inst = business_opening_hours for attr in inst.__slots__: diff --git a/tests/test_callbackquery.py b/tests/test_callbackquery.py index 75c7fc63a..3131b34f2 100644 --- a/tests/test_callbackquery.py +++ b/tests/test_callbackquery.py @@ -33,28 +33,28 @@ from tests.auxil.slots import mro_slots @pytest.fixture(params=["message", "inline", "inaccessible_message"]) def callback_query(bot, request): cbq = CallbackQuery( - TestCallbackQueryBase.id_, - TestCallbackQueryBase.from_user, - TestCallbackQueryBase.chat_instance, - data=TestCallbackQueryBase.data, - game_short_name=TestCallbackQueryBase.game_short_name, + CallbackQueryTestBase.id_, + CallbackQueryTestBase.from_user, + CallbackQueryTestBase.chat_instance, + data=CallbackQueryTestBase.data, + game_short_name=CallbackQueryTestBase.game_short_name, ) cbq.set_bot(bot) cbq._unfreeze() if request.param == "message": - cbq.message = TestCallbackQueryBase.message + cbq.message = CallbackQueryTestBase.message cbq.message.set_bot(bot) elif request.param == "inline": - cbq.inline_message_id = TestCallbackQueryBase.inline_message_id + cbq.inline_message_id = CallbackQueryTestBase.inline_message_id elif request.param == "inaccessible_message": cbq.message = InaccessibleMessage( - chat=TestCallbackQueryBase.message.chat, - message_id=TestCallbackQueryBase.message.message_id, + chat=CallbackQueryTestBase.message.chat, + message_id=CallbackQueryTestBase.message.message_id, ) return cbq -class TestCallbackQueryBase: +class CallbackQueryTestBase: id_ = "id" from_user = User(1, "test_user", False) chat_instance = "chat_instance" @@ -64,7 +64,7 @@ class TestCallbackQueryBase: game_short_name = "the_game" -class TestCallbackQueryWithoutRequest(TestCallbackQueryBase): +class TestCallbackQueryWithoutRequest(CallbackQueryTestBase): @staticmethod def skip_params(callback_query: CallbackQuery): if callback_query.inline_message_id: diff --git a/tests/test_chat.py b/tests/test_chat.py index 682bdbe51..a3dcd6aa1 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -34,20 +34,20 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def chat(bot): chat = Chat( - TestChatBase.id_, - title=TestChatBase.title, - type=TestChatBase.type_, - username=TestChatBase.username, + ChatTestBase.id_, + title=ChatTestBase.title, + type=ChatTestBase.type_, + username=ChatTestBase.username, is_forum=True, - first_name=TestChatBase.first_name, - last_name=TestChatBase.last_name, + first_name=ChatTestBase.first_name, + last_name=ChatTestBase.last_name, ) chat.set_bot(bot) chat._unfreeze() return chat -class TestChatBase: +class ChatTestBase: id_ = -28767330 title = "ToledosPalaceBot - Group" type_ = "group" @@ -57,7 +57,7 @@ class TestChatBase: last_name = "last" -class TestChatWithoutRequest(TestChatBase): +class TestChatWithoutRequest(ChatTestBase): def test_slot_behaviour(self, chat): for attr in chat.__slots__: assert getattr(chat, attr, "err") != "err", f"got extra slot '{attr}'" @@ -889,6 +889,54 @@ class TestChatWithoutRequest(TestChatBase): monkeypatch.setattr(chat.get_bot(), "revoke_chat_invite_link", make_assertion) assert await chat.revoke_invite_link(invite_link=link) + async def test_create_subscription_invite_link(self, monkeypatch, chat): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == chat.id + and kwargs["subscription_price"] == 42 + and kwargs["subscription_period"] == 42 + ) + + assert check_shortcut_signature( + Chat.create_subscription_invite_link, + Bot.create_chat_subscription_invite_link, + ["chat_id"], + [], + ) + assert await check_shortcut_call( + chat.create_subscription_invite_link, + chat.get_bot(), + "create_chat_subscription_invite_link", + ) + assert await check_defaults_handling(chat.create_subscription_invite_link, chat.get_bot()) + + monkeypatch.setattr(chat.get_bot(), "create_chat_subscription_invite_link", make_assertion) + assert await chat.create_subscription_invite_link( + subscription_price=42, subscription_period=42 + ) + + async def test_edit_subscription_invite_link(self, monkeypatch, chat): + link = "ThisIsALink" + + async def make_assertion(*_, **kwargs): + return kwargs["chat_id"] == chat.id and kwargs["invite_link"] == link + + assert check_shortcut_signature( + Chat.edit_subscription_invite_link, + Bot.edit_chat_subscription_invite_link, + ["chat_id"], + [], + ) + assert await check_shortcut_call( + chat.edit_subscription_invite_link, + chat.get_bot(), + "edit_chat_subscription_invite_link", + ) + assert await check_defaults_handling(chat.edit_subscription_invite_link, chat.get_bot()) + + monkeypatch.setattr(chat.get_bot(), "edit_chat_subscription_invite_link", make_assertion) + assert await chat.edit_subscription_invite_link(invite_link=link) + async def test_instance_method_get_menu_button(self, monkeypatch, chat): async def make_assertion(*_, **kwargs): return kwargs["chat_id"] == chat.id diff --git a/tests/test_chatfullinfo.py b/tests/test_chatfullinfo.py index ee9d697ca..7e5bc90ba 100644 --- a/tests/test_chatfullinfo.py +++ b/tests/test_chatfullinfo.py @@ -42,47 +42,47 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def chat_full_info(bot): chat = ChatFullInfo( - TestChatFullInfoBase.id_, - type=TestChatFullInfoBase.type_, - accent_color_id=TestChatFullInfoBase.accent_color_id, - max_reaction_count=TestChatFullInfoBase.max_reaction_count, - title=TestChatFullInfoBase.title, - username=TestChatFullInfoBase.username, - sticker_set_name=TestChatFullInfoBase.sticker_set_name, - can_set_sticker_set=TestChatFullInfoBase.can_set_sticker_set, - permissions=TestChatFullInfoBase.permissions, - slow_mode_delay=TestChatFullInfoBase.slow_mode_delay, - bio=TestChatFullInfoBase.bio, - linked_chat_id=TestChatFullInfoBase.linked_chat_id, - location=TestChatFullInfoBase.location, - has_private_forwards=TestChatFullInfoBase.has_private_forwards, - has_protected_content=TestChatFullInfoBase.has_protected_content, - has_visible_history=TestChatFullInfoBase.has_visible_history, - join_to_send_messages=TestChatFullInfoBase.join_to_send_messages, - join_by_request=TestChatFullInfoBase.join_by_request, + ChatFullInfoTestBase.id_, + type=ChatFullInfoTestBase.type_, + accent_color_id=ChatFullInfoTestBase.accent_color_id, + max_reaction_count=ChatFullInfoTestBase.max_reaction_count, + title=ChatFullInfoTestBase.title, + username=ChatFullInfoTestBase.username, + sticker_set_name=ChatFullInfoTestBase.sticker_set_name, + can_set_sticker_set=ChatFullInfoTestBase.can_set_sticker_set, + permissions=ChatFullInfoTestBase.permissions, + slow_mode_delay=ChatFullInfoTestBase.slow_mode_delay, + bio=ChatFullInfoTestBase.bio, + linked_chat_id=ChatFullInfoTestBase.linked_chat_id, + location=ChatFullInfoTestBase.location, + has_private_forwards=ChatFullInfoTestBase.has_private_forwards, + has_protected_content=ChatFullInfoTestBase.has_protected_content, + has_visible_history=ChatFullInfoTestBase.has_visible_history, + join_to_send_messages=ChatFullInfoTestBase.join_to_send_messages, + join_by_request=ChatFullInfoTestBase.join_by_request, has_restricted_voice_and_video_messages=( - TestChatFullInfoBase.has_restricted_voice_and_video_messages + ChatFullInfoTestBase.has_restricted_voice_and_video_messages ), - is_forum=TestChatFullInfoBase.is_forum, - active_usernames=TestChatFullInfoBase.active_usernames, - emoji_status_custom_emoji_id=TestChatFullInfoBase.emoji_status_custom_emoji_id, - emoji_status_expiration_date=TestChatFullInfoBase.emoji_status_expiration_date, - has_aggressive_anti_spam_enabled=TestChatFullInfoBase.has_aggressive_anti_spam_enabled, - has_hidden_members=TestChatFullInfoBase.has_hidden_members, - available_reactions=TestChatFullInfoBase.available_reactions, - background_custom_emoji_id=TestChatFullInfoBase.background_custom_emoji_id, - profile_accent_color_id=TestChatFullInfoBase.profile_accent_color_id, - profile_background_custom_emoji_id=TestChatFullInfoBase.profile_background_custom_emoji_id, - unrestrict_boost_count=TestChatFullInfoBase.unrestrict_boost_count, - custom_emoji_sticker_set_name=TestChatFullInfoBase.custom_emoji_sticker_set_name, - business_intro=TestChatFullInfoBase.business_intro, - business_location=TestChatFullInfoBase.business_location, - business_opening_hours=TestChatFullInfoBase.business_opening_hours, - birthdate=TestChatFullInfoBase.birthdate, - personal_chat=TestChatFullInfoBase.personal_chat, - first_name=TestChatFullInfoBase.first_name, - last_name=TestChatFullInfoBase.last_name, - can_send_paid_media=TestChatFullInfoBase.can_send_paid_media, + is_forum=ChatFullInfoTestBase.is_forum, + active_usernames=ChatFullInfoTestBase.active_usernames, + emoji_status_custom_emoji_id=ChatFullInfoTestBase.emoji_status_custom_emoji_id, + emoji_status_expiration_date=ChatFullInfoTestBase.emoji_status_expiration_date, + has_aggressive_anti_spam_enabled=ChatFullInfoTestBase.has_aggressive_anti_spam_enabled, + has_hidden_members=ChatFullInfoTestBase.has_hidden_members, + available_reactions=ChatFullInfoTestBase.available_reactions, + background_custom_emoji_id=ChatFullInfoTestBase.background_custom_emoji_id, + profile_accent_color_id=ChatFullInfoTestBase.profile_accent_color_id, + profile_background_custom_emoji_id=ChatFullInfoTestBase.profile_background_custom_emoji_id, + unrestrict_boost_count=ChatFullInfoTestBase.unrestrict_boost_count, + custom_emoji_sticker_set_name=ChatFullInfoTestBase.custom_emoji_sticker_set_name, + business_intro=ChatFullInfoTestBase.business_intro, + business_location=ChatFullInfoTestBase.business_location, + business_opening_hours=ChatFullInfoTestBase.business_opening_hours, + birthdate=ChatFullInfoTestBase.birthdate, + personal_chat=ChatFullInfoTestBase.personal_chat, + first_name=ChatFullInfoTestBase.first_name, + last_name=ChatFullInfoTestBase.last_name, + can_send_paid_media=ChatFullInfoTestBase.can_send_paid_media, ) chat.set_bot(bot) chat._unfreeze() @@ -90,7 +90,7 @@ def chat_full_info(bot): # Shortcut methods are tested in test_chat.py. -class TestChatFullInfoBase: +class ChatFullInfoTestBase: id_ = -28767330 max_reaction_count = 2 title = "ToledosPalaceBot - Group" @@ -142,7 +142,7 @@ class TestChatFullInfoBase: can_send_paid_media = True -class TestChatFullInfoWithoutRequest(TestChatFullInfoBase): +class TestChatFullInfoWithoutRequest(ChatFullInfoTestBase): def test_slot_behaviour(self, chat_full_info): cfi = chat_full_info for attr in cfi.__slots__: diff --git a/tests/test_chatinvitelink.py b/tests/test_chatinvitelink.py index 1b95177d9..9331166b4 100644 --- a/tests/test_chatinvitelink.py +++ b/tests/test_chatinvitelink.py @@ -33,19 +33,21 @@ def creator(): @pytest.fixture(scope="module") def invite_link(creator): return ChatInviteLink( - TestChatInviteLinkBase.link, + ChatInviteLinkTestBase.link, creator, - TestChatInviteLinkBase.creates_join_request, - TestChatInviteLinkBase.primary, - TestChatInviteLinkBase.revoked, - expire_date=TestChatInviteLinkBase.expire_date, - member_limit=TestChatInviteLinkBase.member_limit, - name=TestChatInviteLinkBase.name, - pending_join_request_count=TestChatInviteLinkBase.pending_join_request_count, + ChatInviteLinkTestBase.creates_join_request, + ChatInviteLinkTestBase.primary, + ChatInviteLinkTestBase.revoked, + expire_date=ChatInviteLinkTestBase.expire_date, + member_limit=ChatInviteLinkTestBase.member_limit, + name=ChatInviteLinkTestBase.name, + pending_join_request_count=ChatInviteLinkTestBase.pending_join_request_count, + subscription_period=ChatInviteLinkTestBase.subscription_period, + subscription_price=ChatInviteLinkTestBase.subscription_price, ) -class TestChatInviteLinkBase: +class ChatInviteLinkTestBase: link = "thisialink" creates_join_request = False primary = True @@ -54,9 +56,11 @@ class TestChatInviteLinkBase: member_limit = 42 name = "LinkName" pending_join_request_count = 42 + subscription_period = 43 + subscription_price = 44 -class TestChatInviteLinkWithoutRequest(TestChatInviteLinkBase): +class TestChatInviteLinkWithoutRequest(ChatInviteLinkTestBase): def test_slot_behaviour(self, invite_link): for attr in invite_link.__slots__: assert getattr(invite_link, attr, "err") != "err", f"got extra slot '{attr}'" @@ -91,6 +95,8 @@ class TestChatInviteLinkWithoutRequest(TestChatInviteLinkBase): "member_limit": self.member_limit, "name": self.name, "pending_join_request_count": str(self.pending_join_request_count), + "subscription_period": self.subscription_period, + "subscription_price": self.subscription_price, } invite_link = ChatInviteLink.de_json(json_dict, bot) @@ -106,6 +112,8 @@ class TestChatInviteLinkWithoutRequest(TestChatInviteLinkBase): assert invite_link.member_limit == self.member_limit assert invite_link.name == self.name assert invite_link.pending_join_request_count == self.pending_join_request_count + assert invite_link.subscription_period == self.subscription_period + assert invite_link.subscription_price == self.subscription_price def test_de_json_localization(self, tz_bot, bot, raw_bot, creator): json_dict = { @@ -146,6 +154,8 @@ class TestChatInviteLinkWithoutRequest(TestChatInviteLinkBase): assert invite_link_dict["member_limit"] == self.member_limit assert invite_link_dict["name"] == self.name assert invite_link_dict["pending_join_request_count"] == self.pending_join_request_count + assert invite_link_dict["subscription_period"] == self.subscription_period + assert invite_link_dict["subscription_price"] == self.subscription_price def test_equality(self): a = ChatInviteLink("link", User(1, "", False), True, True, True) diff --git a/tests/test_chatjoinrequest.py b/tests/test_chatjoinrequest.py index 3d8b19386..cdf2787e8 100644 --- a/tests/test_chatjoinrequest.py +++ b/tests/test_chatjoinrequest.py @@ -38,18 +38,18 @@ def time(): @pytest.fixture(scope="module") def chat_join_request(bot, time): cjr = ChatJoinRequest( - chat=TestChatJoinRequestBase.chat, - from_user=TestChatJoinRequestBase.from_user, + chat=ChatJoinRequestTestBase.chat, + from_user=ChatJoinRequestTestBase.from_user, date=time, - bio=TestChatJoinRequestBase.bio, - invite_link=TestChatJoinRequestBase.invite_link, - user_chat_id=TestChatJoinRequestBase.from_user.id, + bio=ChatJoinRequestTestBase.bio, + invite_link=ChatJoinRequestTestBase.invite_link, + user_chat_id=ChatJoinRequestTestBase.from_user.id, ) cjr.set_bot(bot) return cjr -class TestChatJoinRequestBase: +class ChatJoinRequestTestBase: chat = Chat(1, Chat.SUPERGROUP) from_user = User(2, "first_name", False) bio = "bio" @@ -63,7 +63,7 @@ class TestChatJoinRequestBase: ) -class TestChatJoinRequestWithoutRequest(TestChatJoinRequestBase): +class TestChatJoinRequestWithoutRequest(ChatJoinRequestTestBase): def test_slot_behaviour(self, chat_join_request): inst = chat_join_request for attr in inst.__slots__: diff --git a/tests/test_chatlocation.py b/tests/test_chatlocation.py index a57d157cc..00481d644 100644 --- a/tests/test_chatlocation.py +++ b/tests/test_chatlocation.py @@ -25,15 +25,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def chat_location(): - return ChatLocation(TestChatLocationBase.location, TestChatLocationBase.address) + return ChatLocation(ChatLocationTestBase.location, ChatLocationTestBase.address) -class TestChatLocationBase: +class ChatLocationTestBase: location = Location(123, 456) address = "The Shire" -class TestChatLocationWithoutRequest(TestChatLocationBase): +class TestChatLocationWithoutRequest(ChatLocationTestBase): def test_slot_behaviour(self, chat_location): inst = chat_location for attr in inst.__slots__: diff --git a/tests/test_chatmember.py b/tests/test_chatmember.py index b4eac51cf..4296fdd27 100644 --- a/tests/test_chatmember.py +++ b/tests/test_chatmember.py @@ -101,7 +101,7 @@ def chat_member_administrator(): def chat_member_member(): - return ChatMemberMember(CMDefaults.user) + return ChatMemberMember(CMDefaults.user, until_date=CMDefaults.until_date) def chat_member_restricted(): @@ -230,7 +230,9 @@ class TestChatMemberTypesWithoutRequest: def test_de_json_chatmemberbanned_localization(self, chat_member_type, tz_bot, bot, raw_bot): # We only test two classes because the other three don't have datetimes in them. - if isinstance(chat_member_type, (ChatMemberBanned, ChatMemberRestricted)): + if isinstance( + chat_member_type, (ChatMemberBanned, ChatMemberRestricted, ChatMemberMember) + ): json_dict = make_json_dict(chat_member_type, include_optional_args=True) chatmember_raw = ChatMember.de_json(json_dict, raw_bot) chatmember_bot = ChatMember.de_json(json_dict, bot) diff --git a/tests/test_chatmemberupdated.py b/tests/test_chatmemberupdated.py index 0efbcd8d0..33b07863a 100644 --- a/tests/test_chatmemberupdated.py +++ b/tests/test_chatmemberupdated.py @@ -47,7 +47,7 @@ def chat(): @pytest.fixture(scope="module") def old_chat_member(user): - return ChatMember(user, TestChatMemberUpdatedBase.old_status) + return ChatMember(user, ChatMemberUpdatedTestBase.old_status) @pytest.fixture(scope="module") @@ -66,7 +66,7 @@ def new_chat_member(user): True, True, True, - custom_title=TestChatMemberUpdatedBase.new_status, + custom_title=ChatMemberUpdatedTestBase.new_status, ) @@ -87,12 +87,12 @@ def chat_member_updated(user, chat, old_chat_member, new_chat_member, invite_lin ) -class TestChatMemberUpdatedBase: +class ChatMemberUpdatedTestBase: old_status = ChatMember.MEMBER new_status = ChatMember.ADMINISTRATOR -class TestChatMemberUpdatedWithoutRequest(TestChatMemberUpdatedBase): +class TestChatMemberUpdatedWithoutRequest(ChatMemberUpdatedTestBase): def test_slot_behaviour(self, chat_member_updated): action = chat_member_updated for attr in action.__slots__: diff --git a/tests/test_chatpermissions.py b/tests/test_chatpermissions.py index 9317de227..79b6bab80 100644 --- a/tests/test_chatpermissions.py +++ b/tests/test_chatpermissions.py @@ -43,7 +43,7 @@ def chat_permissions(): ) -class TestChatPermissionsBase: +class ChatPermissionsTestBase: can_send_messages = True can_send_polls = True can_send_other_messages = False @@ -60,7 +60,7 @@ class TestChatPermissionsBase: can_send_voice_notes = None -class TestChatPermissionsWithoutRequest(TestChatPermissionsBase): +class TestChatPermissionsWithoutRequest(ChatPermissionsTestBase): def test_slot_behaviour(self, chat_permissions): inst = chat_permissions for attr in inst.__slots__: diff --git a/tests/test_choseninlineresult.py b/tests/test_choseninlineresult.py index d1cb36226..2b53b6847 100644 --- a/tests/test_choseninlineresult.py +++ b/tests/test_choseninlineresult.py @@ -33,16 +33,16 @@ def user(): @pytest.fixture(scope="module") def chosen_inline_result(user): return ChosenInlineResult( - TestChosenInlineResultBase.result_id, user, TestChosenInlineResultBase.query + ChosenInlineResultTestBase.result_id, user, ChosenInlineResultTestBase.query ) -class TestChosenInlineResultBase: +class ChosenInlineResultTestBase: result_id = "result id" query = "query text" -class TestChosenInlineResultWithoutRequest(TestChosenInlineResultBase): +class TestChosenInlineResultWithoutRequest(ChosenInlineResultTestBase): def test_slot_behaviour(self, chosen_inline_result): inst = chosen_inline_result for attr in inst.__slots__: diff --git a/tests/test_dice.py b/tests/test_dice.py index 53242efa7..df3c349d4 100644 --- a/tests/test_dice.py +++ b/tests/test_dice.py @@ -28,11 +28,11 @@ def dice(request): return Dice(value=5, emoji=request.param) -class TestDiceBase: +class DiceTestBase: value = 4 -class TestDiceWithoutRequest(TestDiceBase): +class TestDiceWithoutRequest(DiceTestBase): def test_slot_behaviour(self, dice): for attr in dice.__slots__: assert getattr(dice, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_forcereply.py b/tests/test_forcereply.py index ca9d7cae5..e4e2b5b5d 100644 --- a/tests/test_forcereply.py +++ b/tests/test_forcereply.py @@ -25,16 +25,16 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def force_reply(): - return ForceReply(TestForceReplyBase.selective, TestForceReplyBase.input_field_placeholder) + return ForceReply(ForceReplyTestBase.selective, ForceReplyTestBase.input_field_placeholder) -class TestForceReplyBase: +class ForceReplyTestBase: force_reply = True selective = True input_field_placeholder = "force replies can be annoying if not used properly" -class TestForceReplyWithoutRequest(TestForceReplyBase): +class TestForceReplyWithoutRequest(ForceReplyTestBase): def test_slot_behaviour(self, force_reply): for attr in force_reply.__slots__: assert getattr(force_reply, attr, "err") != "err", f"got extra slot '{attr}'" @@ -69,7 +69,7 @@ class TestForceReplyWithoutRequest(TestForceReplyBase): assert hash(a) != hash(d) -class TestForceReplyWithRequest(TestForceReplyBase): +class TestForceReplyWithRequest(ForceReplyTestBase): async def test_send_message_with_force_reply(self, bot, chat_id, force_reply): message = await bot.send_message(chat_id, "text", reply_markup=force_reply) assert message.text == "text" diff --git a/tests/test_inlinequeryresultsbutton.py b/tests/test_inlinequeryresultsbutton.py index 2c6ad4336..90ce2c235 100644 --- a/tests/test_inlinequeryresultsbutton.py +++ b/tests/test_inlinequeryresultsbutton.py @@ -25,19 +25,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def inline_query_results_button(): return InlineQueryResultsButton( - text=TestInlineQueryResultsButtonBase.text, - start_parameter=TestInlineQueryResultsButtonBase.start_parameter, - web_app=TestInlineQueryResultsButtonBase.web_app, + text=InlineQueryResultsButtonTestBase.text, + start_parameter=InlineQueryResultsButtonTestBase.start_parameter, + web_app=InlineQueryResultsButtonTestBase.web_app, ) -class TestInlineQueryResultsButtonBase: +class InlineQueryResultsButtonTestBase: text = "text" start_parameter = "start_parameter" web_app = WebAppInfo(url="https://python-telegram-bot.org") -class TestInlineQueryResultsButtonWithoutRequest(TestInlineQueryResultsButtonBase): +class TestInlineQueryResultsButtonWithoutRequest(InlineQueryResultsButtonTestBase): def test_slot_behaviour(self, inline_query_results_button): inst = inline_query_results_button for attr in inst.__slots__: diff --git a/tests/test_keyboardbutton.py b/tests/test_keyboardbutton.py index edd45cc9a..4493ed223 100644 --- a/tests/test_keyboardbutton.py +++ b/tests/test_keyboardbutton.py @@ -32,17 +32,17 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def keyboard_button(): return KeyboardButton( - TestKeyboardButtonBase.text, - request_location=TestKeyboardButtonBase.request_location, - request_contact=TestKeyboardButtonBase.request_contact, - request_poll=TestKeyboardButtonBase.request_poll, - web_app=TestKeyboardButtonBase.web_app, - request_chat=TestKeyboardButtonBase.request_chat, - request_users=TestKeyboardButtonBase.request_users, + KeyboardButtonTestBase.text, + request_location=KeyboardButtonTestBase.request_location, + request_contact=KeyboardButtonTestBase.request_contact, + request_poll=KeyboardButtonTestBase.request_poll, + web_app=KeyboardButtonTestBase.web_app, + request_chat=KeyboardButtonTestBase.request_chat, + request_users=KeyboardButtonTestBase.request_users, ) -class TestKeyboardButtonBase: +class KeyboardButtonTestBase: text = "text" request_location = True request_contact = True @@ -52,7 +52,7 @@ class TestKeyboardButtonBase: request_users = KeyboardButtonRequestUsers(2) -class TestKeyboardButtonWithoutRequest(TestKeyboardButtonBase): +class TestKeyboardButtonWithoutRequest(KeyboardButtonTestBase): def test_slot_behaviour(self, keyboard_button): inst = keyboard_button for attr in inst.__slots__: diff --git a/tests/test_keyboardbuttonpolltype.py b/tests/test_keyboardbuttonpolltype.py index 2d4f0dd5b..6c4e92bf2 100644 --- a/tests/test_keyboardbuttonpolltype.py +++ b/tests/test_keyboardbuttonpolltype.py @@ -25,14 +25,14 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def keyboard_button_poll_type(): - return KeyboardButtonPollType(TestKeyboardButtonPollTypeBase.type) + return KeyboardButtonPollType(KeyboardButtonPollTypeTestBase.type) -class TestKeyboardButtonPollTypeBase: +class KeyboardButtonPollTypeTestBase: type = Poll.QUIZ -class TestKeyboardButtonPollTypeWithoutRequest(TestKeyboardButtonPollTypeBase): +class TestKeyboardButtonPollTypeWithoutRequest(KeyboardButtonPollTypeTestBase): def test_slot_behaviour(self, keyboard_button_poll_type): inst = keyboard_button_poll_type for attr in inst.__slots__: diff --git a/tests/test_keyboardbuttonrequest.py b/tests/test_keyboardbuttonrequest.py index 8678fd08d..8e42b1cd3 100644 --- a/tests/test_keyboardbuttonrequest.py +++ b/tests/test_keyboardbuttonrequest.py @@ -26,21 +26,21 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="class") def request_users(): return KeyboardButtonRequestUsers( - TestKeyboardButtonRequestUsersBase.request_id, - TestKeyboardButtonRequestUsersBase.user_is_bot, - TestKeyboardButtonRequestUsersBase.user_is_premium, - TestKeyboardButtonRequestUsersBase.max_quantity, + KeyboardButtonRequestUsersTestBase.request_id, + KeyboardButtonRequestUsersTestBase.user_is_bot, + KeyboardButtonRequestUsersTestBase.user_is_premium, + KeyboardButtonRequestUsersTestBase.max_quantity, ) -class TestKeyboardButtonRequestUsersBase: +class KeyboardButtonRequestUsersTestBase: request_id = 123 user_is_bot = True user_is_premium = False max_quantity = 10 -class TestKeyboardButtonRequestUsersWithoutRequest(TestKeyboardButtonRequestUsersBase): +class TestKeyboardButtonRequestUsersWithoutRequest(KeyboardButtonRequestUsersTestBase): def test_slot_behaviour(self, request_users): for attr in request_users.__slots__: assert getattr(request_users, attr, "err") != "err", f"got extra slot '{attr}'" @@ -88,18 +88,18 @@ class TestKeyboardButtonRequestUsersWithoutRequest(TestKeyboardButtonRequestUser @pytest.fixture(scope="class") def request_chat(): return KeyboardButtonRequestChat( - TestKeyboardButtonRequestChatBase.request_id, - TestKeyboardButtonRequestChatBase.chat_is_channel, - TestKeyboardButtonRequestChatBase.chat_is_forum, - TestKeyboardButtonRequestChatBase.chat_has_username, - TestKeyboardButtonRequestChatBase.chat_is_created, - TestKeyboardButtonRequestChatBase.user_administrator_rights, - TestKeyboardButtonRequestChatBase.bot_administrator_rights, - TestKeyboardButtonRequestChatBase.bot_is_member, + KeyboardButtonRequestChatTestBase.request_id, + KeyboardButtonRequestChatTestBase.chat_is_channel, + KeyboardButtonRequestChatTestBase.chat_is_forum, + KeyboardButtonRequestChatTestBase.chat_has_username, + KeyboardButtonRequestChatTestBase.chat_is_created, + KeyboardButtonRequestChatTestBase.user_administrator_rights, + KeyboardButtonRequestChatTestBase.bot_administrator_rights, + KeyboardButtonRequestChatTestBase.bot_is_member, ) -class TestKeyboardButtonRequestChatBase: +class KeyboardButtonRequestChatTestBase: request_id = 456 chat_is_channel = True chat_is_forum = False @@ -134,7 +134,7 @@ class TestKeyboardButtonRequestChatBase: bot_is_member = True -class TestKeyboardButtonRequestChatWithoutRequest(TestKeyboardButtonRequestChatBase): +class TestKeyboardButtonRequestChatWithoutRequest(KeyboardButtonRequestChatTestBase): def test_slot_behaviour(self, request_chat): for attr in request_chat.__slots__: assert getattr(request_chat, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_linkpreviewoptions.py b/tests/test_linkpreviewoptions.py index 7b5bc7beb..a4fa5aea4 100644 --- a/tests/test_linkpreviewoptions.py +++ b/tests/test_linkpreviewoptions.py @@ -25,15 +25,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def link_preview_options(): return LinkPreviewOptions( - is_disabled=TestLinkPreviewOptionsBase.is_disabled, - url=TestLinkPreviewOptionsBase.url, - prefer_small_media=TestLinkPreviewOptionsBase.prefer_small_media, - prefer_large_media=TestLinkPreviewOptionsBase.prefer_large_media, - show_above_text=TestLinkPreviewOptionsBase.show_above_text, + is_disabled=LinkPreviewOptionsTestBase.is_disabled, + url=LinkPreviewOptionsTestBase.url, + prefer_small_media=LinkPreviewOptionsTestBase.prefer_small_media, + prefer_large_media=LinkPreviewOptionsTestBase.prefer_large_media, + show_above_text=LinkPreviewOptionsTestBase.show_above_text, ) -class TestLinkPreviewOptionsBase: +class LinkPreviewOptionsTestBase: is_disabled = True url = "https://www.example.com" prefer_small_media = True @@ -41,7 +41,7 @@ class TestLinkPreviewOptionsBase: show_above_text = True -class TestLinkPreviewOptionsWithoutRequest(TestLinkPreviewOptionsBase): +class TestLinkPreviewOptionsWithoutRequest(LinkPreviewOptionsTestBase): def test_slot_behaviour(self, link_preview_options): a = link_preview_options for attr in a.__slots__: diff --git a/tests/test_loginurl.py b/tests/test_loginurl.py index a9f69699b..2fd84e97e 100644 --- a/tests/test_loginurl.py +++ b/tests/test_loginurl.py @@ -25,21 +25,21 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def login_url(): return LoginUrl( - url=TestLoginUrlBase.url, - forward_text=TestLoginUrlBase.forward_text, - bot_username=TestLoginUrlBase.bot_username, - request_write_access=TestLoginUrlBase.request_write_access, + url=LoginUrlTestBase.url, + forward_text=LoginUrlTestBase.forward_text, + bot_username=LoginUrlTestBase.bot_username, + request_write_access=LoginUrlTestBase.request_write_access, ) -class TestLoginUrlBase: +class LoginUrlTestBase: url = "http://www.google.com" forward_text = "Send me forward!" bot_username = "botname" request_write_access = True -class TestLoginUrlWithoutRequest(TestLoginUrlBase): +class TestLoginUrlWithoutRequest(LoginUrlTestBase): def test_slot_behaviour(self, login_url): for attr in login_url.__slots__: assert getattr(login_url, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_maybeinaccessiblemessage.py b/tests/test_maybeinaccessiblemessage.py index 2c6617af8..da7db43ce 100644 --- a/tests/test_maybeinaccessiblemessage.py +++ b/tests/test_maybeinaccessiblemessage.py @@ -29,19 +29,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="class") def maybe_inaccessible_message(): return MaybeInaccessibleMessage( - TestMaybeInaccessibleMessageBase.chat, - TestMaybeInaccessibleMessageBase.message_id, - TestMaybeInaccessibleMessageBase.date, + MaybeInaccessibleMessageTestBase.chat, + MaybeInaccessibleMessageTestBase.message_id, + MaybeInaccessibleMessageTestBase.date, ) -class TestMaybeInaccessibleMessageBase: +class MaybeInaccessibleMessageTestBase: chat = Chat(1, "title") message_id = 123 date = dtm.datetime.now(dtm.timezone.utc).replace(microsecond=0) -class TestMaybeInaccessibleMessageWithoutRequest(TestMaybeInaccessibleMessageBase): +class TestMaybeInaccessibleMessageWithoutRequest(MaybeInaccessibleMessageTestBase): def test_slot_behaviour(self, maybe_inaccessible_message): for attr in maybe_inaccessible_message.__slots__: assert ( diff --git a/tests/test_menubutton.py b/tests/test_menubutton.py index 48c9c30c9..d5930f805 100644 --- a/tests/test_menubutton.py +++ b/tests/test_menubutton.py @@ -84,20 +84,20 @@ def menu_button(scope_class_and_type): return scope_class_and_type[0].de_json( { "type": scope_class_and_type[1], - "text": TestMenuButtonselfBase.text, - "web_app": TestMenuButtonselfBase.web_app.to_dict(), + "text": MenuButtonTestBase.text, + "web_app": MenuButtonTestBase.web_app.to_dict(), }, bot=None, ) -class TestMenuButtonselfBase: +class MenuButtonTestBase: text = "button_text" web_app = WebAppInfo(url="https://python-telegram-bot.org/web_app") # All the scope types are very similar, so we test everything via parametrization -class TestMenuButtonWithoutRequest(TestMenuButtonselfBase): +class TestMenuButtonWithoutRequest(MenuButtonTestBase): def test_slot_behaviour(self, menu_button): for attr in menu_button.__slots__: assert getattr(menu_button, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_message.py b/tests/test_message.py index 7b4fc0a45..84b2b7c39 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -90,13 +90,13 @@ from tests.auxil.pytest_classes import PytestExtBot, PytestMessage from tests.auxil.slots import mro_slots -@pytest.fixture(scope="module") +@pytest.fixture def message(bot): message = PytestMessage( - message_id=TestMessageBase.id_, - date=TestMessageBase.date, - chat=copy(TestMessageBase.chat), - from_user=copy(TestMessageBase.from_user), + message_id=MessageTestBase.id_, + date=MessageTestBase.date, + chat=copy(MessageTestBase.chat), + from_user=copy(MessageTestBase.from_user), business_connection_id="123456789", ) message.set_bot(bot) @@ -357,17 +357,17 @@ def message(bot): ) def message_params(bot, request): message = Message( - message_id=TestMessageBase.id_, - from_user=TestMessageBase.from_user, - date=TestMessageBase.date, - chat=TestMessageBase.chat, + message_id=MessageTestBase.id_, + from_user=MessageTestBase.from_user, + date=MessageTestBase.date, + chat=MessageTestBase.chat, **request.param, ) message.set_bot(bot) return message -class TestMessageBase: +class MessageTestBase: id_ = 1 from_user = User(2, "testuser", False) date = datetime.utcnow() @@ -439,7 +439,7 @@ class TestMessageBase: ) -class TestMessageWithoutRequest(TestMessageBase): +class TestMessageWithoutRequest(MessageTestBase): @staticmethod async def check_quote_parsing( message: Message, method, bot_method_name: str, args, monkeypatch @@ -559,10 +559,10 @@ class TestMessageWithoutRequest(TestMessageBase): def test_slot_behaviour(self): message = Message( - message_id=TestMessageBase.id_, - date=TestMessageBase.date, - chat=copy(TestMessageBase.chat), - from_user=copy(TestMessageBase.from_user), + message_id=MessageTestBase.id_, + date=MessageTestBase.date, + chat=copy(MessageTestBase.chat), + from_user=copy(MessageTestBase.from_user), ) for attr in message.__slots__: assert getattr(message, attr, "err") != "err", f"got extra slot '{attr}'" @@ -1193,16 +1193,20 @@ class TestMessageWithoutRequest(TestMessageBase): # The leading - for group ids/ -100 for supergroup ids isn't supposed to be in the link assert message.link == f"https://t.me/c/{3}/{message.message_id}" - def test_link_with_topics(self, message): + @pytest.mark.parametrize("type_", argvalues=[Chat.SUPERGROUP, Chat.CHANNEL]) + def test_link_with_topics(self, message, type_): message.chat.username = None message.chat.id = -1003 + message.chat.type = type_ message.is_topic_message = True message.message_thread_id = 123 assert message.link == f"https://t.me/c/3/{message.message_id}?thread=123" - def test_link_with_reply(self, message): + @pytest.mark.parametrize("type_", argvalues=[Chat.SUPERGROUP, Chat.CHANNEL]) + def test_link_with_reply(self, message, type_): message.chat.username = None message.chat.id = -1003 + message.chat.type = type_ message.reply_to_message = Message(7, self.from_user, self.date, self.chat, text="Reply") message.message_thread_id = 123 assert message.link == f"https://t.me/c/3/{message.message_id}?thread=123" diff --git a/tests/test_messageentity.py b/tests/test_messageentity.py index 8bab9fec7..3598454d8 100644 --- a/tests/test_messageentity.py +++ b/tests/test_messageentity.py @@ -41,14 +41,14 @@ def message_entity(request): return MessageEntity(type_, 1, 3, url=url, user=user, language=language) -class TestMessageEntityBase: +class MessageEntityTestBase: type_ = "url" offset = 1 length = 2 url = "url" -class TestMessageEntityWithoutRequest(TestMessageEntityBase): +class TestMessageEntityWithoutRequest(MessageEntityTestBase): def test_slot_behaviour(self, message_entity): inst = message_entity for attr in inst.__slots__: @@ -103,6 +103,54 @@ class TestMessageEntityWithoutRequest(TestMessageEntityBase): assert out_entity.offset == offset assert out_entity.length == length + @pytest.mark.parametrize("by", [6, "prefix", "𝛙𝌢𑁍"]) + def test_shift_entities(self, by): + kwargs = { + "url": "url", + "user": 42, + "language": "python", + "custom_emoji_id": "custom_emoji_id", + } + entities = [ + MessageEntity(MessageEntity.BOLD, 2, 3, **kwargs), + MessageEntity(MessageEntity.BOLD, 5, 6, **kwargs), + ] + shifted = MessageEntity.shift_entities(by, entities) + assert shifted[0].offset == 8 + assert shifted[1].offset == 11 + + assert shifted[0] is not entities[0] + assert shifted[1] is not entities[1] + + for entity in shifted: + for key, value in kwargs.items(): + assert getattr(entity, key) == value + + def test_concatenate(self): + kwargs = { + "url": "url", + "user": 42, + "language": "python", + "custom_emoji_id": "custom_emoji_id", + } + first_entity = MessageEntity(MessageEntity.BOLD, 0, 6, **kwargs) + second_entity = MessageEntity(MessageEntity.ITALIC, 0, 4, **kwargs) + third_entity = MessageEntity(MessageEntity.UNDERLINE, 3, 6, **kwargs) + + first = ("prefix 𝛙𝌢𑁍 | ", [first_entity], True) + second = ("text 𝛙𝌢𑁍", [second_entity], False) + third = (" | suffix 𝛙𝌢𑁍", [third_entity]) + + new_text, new_entities = MessageEntity.concatenate(first, second, third) + + assert new_text == "prefix 𝛙𝌢𑁍 | text 𝛙𝌢𑁍 | suffix 𝛙𝌢𑁍" + assert [entity.offset for entity in new_entities] == [0, 16, 30] + for old, new in zip([first_entity, second_entity, third_entity], new_entities): + assert new is not old + assert new.type == old.type + for key, value in kwargs.items(): + assert getattr(new, key) == value + def test_equality(self): a = MessageEntity(MessageEntity.BOLD, 2, 3) b = MessageEntity(MessageEntity.BOLD, 2, 3) diff --git a/tests/test_paidmedia.py b/tests/test_paidmedia.py index f76bcf631..be9ac1490 100644 --- a/tests/test_paidmedia.py +++ b/tests/test_paidmedia.py @@ -96,33 +96,33 @@ def paid_media(pm_scope_class_and_type): return pm_scope_class_and_type[0].de_json( { "type": pm_scope_class_and_type[1], - "width": TestPaidMediaBase.width, - "height": TestPaidMediaBase.height, - "duration": TestPaidMediaBase.duration, - "video": TestPaidMediaBase.video.to_dict(), - "photo": [p.to_dict() for p in TestPaidMediaBase.photo], + "width": PaidMediaTestBase.width, + "height": PaidMediaTestBase.height, + "duration": PaidMediaTestBase.duration, + "video": PaidMediaTestBase.video.to_dict(), + "photo": [p.to_dict() for p in PaidMediaTestBase.photo], }, bot=None, ) def paid_media_video(): - return PaidMediaVideo(video=TestPaidMediaBase.video) + return PaidMediaVideo(video=PaidMediaTestBase.video) def paid_media_photo(): - return PaidMediaPhoto(photo=TestPaidMediaBase.photo) + return PaidMediaPhoto(photo=PaidMediaTestBase.photo) @pytest.fixture(scope="module") def paid_media_info(): return PaidMediaInfo( - star_count=TestPaidMediaInfoBase.star_count, + star_count=PaidMediaInfoTestBase.star_count, paid_media=[paid_media_video(), paid_media_photo()], ) -class TestPaidMediaBase: +class PaidMediaTestBase: width = 640 height = 480 duration = 60 @@ -143,7 +143,7 @@ class TestPaidMediaBase: ) -class TestPaidMediaWithoutRequest(TestPaidMediaBase): +class TestPaidMediaWithoutRequest(PaidMediaTestBase): def test_slot_behaviour(self, paid_media): inst = paid_media for attr in inst.__slots__: @@ -280,12 +280,12 @@ class TestPaidMediaWithoutRequest(TestPaidMediaBase): assert hash(c) != hash(f) -class TestPaidMediaInfoBase: +class PaidMediaInfoTestBase: star_count = 200 paid_media = [paid_media_video(), paid_media_photo()] -class TestPaidMediaInfoWithoutRequest(TestPaidMediaInfoBase): +class TestPaidMediaInfoWithoutRequest(PaidMediaInfoTestBase): def test_slot_behaviour(self, paid_media_info): inst = paid_media_info for attr in inst.__slots__: diff --git a/tests/test_poll.py b/tests/test_poll.py index 92c58339d..81619a112 100644 --- a/tests/test_poll.py +++ b/tests/test_poll.py @@ -28,15 +28,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def input_poll_option(): out = InputPollOption( - text=TestInputPollOptionBase.text, - text_parse_mode=TestInputPollOptionBase.text_parse_mode, - text_entities=TestInputPollOptionBase.text_entities, + text=InputPollOptionTestBase.text, + text_parse_mode=InputPollOptionTestBase.text_parse_mode, + text_entities=InputPollOptionTestBase.text_entities, ) out._unfreeze() return out -class TestInputPollOptionBase: +class InputPollOptionTestBase: text = "test option" text_parse_mode = "MarkdownV2" text_entities = [ @@ -45,7 +45,7 @@ class TestInputPollOptionBase: ] -class TestInputPollOptionWithoutRequest(TestInputPollOptionBase): +class TestInputPollOptionWithoutRequest(InputPollOptionTestBase): def test_slot_behaviour(self, input_poll_option): for attr in input_poll_option.__slots__: assert getattr(input_poll_option, attr, "err") != "err", f"got extra slot '{attr}'" @@ -106,15 +106,15 @@ class TestInputPollOptionWithoutRequest(TestInputPollOptionBase): @pytest.fixture(scope="module") def poll_option(): out = PollOption( - text=TestPollOptionBase.text, - voter_count=TestPollOptionBase.voter_count, - text_entities=TestPollOptionBase.text_entities, + text=PollOptionTestBase.text, + voter_count=PollOptionTestBase.voter_count, + text_entities=PollOptionTestBase.text_entities, ) out._unfreeze() return out -class TestPollOptionBase: +class PollOptionTestBase: text = "test option" voter_count = 3 text_entities = [ @@ -123,7 +123,7 @@ class TestPollOptionBase: ] -class TestPollOptionWithoutRequest(TestPollOptionBase): +class TestPollOptionWithoutRequest(PollOptionTestBase): def test_slot_behaviour(self, poll_option): for attr in poll_option.__slots__: assert getattr(poll_option, attr, "err") != "err", f"got extra slot '{attr}'" @@ -198,21 +198,21 @@ class TestPollOptionWithoutRequest(TestPollOptionBase): @pytest.fixture(scope="module") def poll_answer(): return PollAnswer( - TestPollAnswerBase.poll_id, - TestPollAnswerBase.option_ids, - TestPollAnswerBase.user, - TestPollAnswerBase.voter_chat, + PollAnswerTestBase.poll_id, + PollAnswerTestBase.option_ids, + PollAnswerTestBase.user, + PollAnswerTestBase.voter_chat, ) -class TestPollAnswerBase: +class PollAnswerTestBase: poll_id = "id" option_ids = [2] user = User(1, "", False) voter_chat = Chat(1, "") -class TestPollAnswerWithoutRequest(TestPollAnswerBase): +class TestPollAnswerWithoutRequest(PollAnswerTestBase): def test_de_json(self): json_dict = { "poll_id": self.poll_id, @@ -264,25 +264,25 @@ class TestPollAnswerWithoutRequest(TestPollAnswerBase): @pytest.fixture(scope="module") def poll(): poll = Poll( - TestPollBase.id_, - TestPollBase.question, - TestPollBase.options, - TestPollBase.total_voter_count, - TestPollBase.is_closed, - TestPollBase.is_anonymous, - TestPollBase.type, - TestPollBase.allows_multiple_answers, - explanation=TestPollBase.explanation, - explanation_entities=TestPollBase.explanation_entities, - open_period=TestPollBase.open_period, - close_date=TestPollBase.close_date, - question_entities=TestPollBase.question_entities, + PollTestBase.id_, + PollTestBase.question, + PollTestBase.options, + PollTestBase.total_voter_count, + PollTestBase.is_closed, + PollTestBase.is_anonymous, + PollTestBase.type, + PollTestBase.allows_multiple_answers, + explanation=PollTestBase.explanation, + explanation_entities=PollTestBase.explanation_entities, + open_period=PollTestBase.open_period, + close_date=PollTestBase.close_date, + question_entities=PollTestBase.question_entities, ) poll._unfreeze() return poll -class TestPollBase: +class PollTestBase: id_ = "id" question = "Test Question?" options = [PollOption("test", 10), PollOption("test2", 11)] @@ -304,7 +304,7 @@ class TestPollBase: ] -class TestPollWithoutRequest(TestPollBase): +class TestPollWithoutRequest(PollTestBase): def test_de_json(self, bot): json_dict = { "id": self.id_, diff --git a/tests/test_proximityalerttriggered.py b/tests/test_proximityalerttriggered.py index 3db91ffbe..de49b699f 100644 --- a/tests/test_proximityalerttriggered.py +++ b/tests/test_proximityalerttriggered.py @@ -25,19 +25,19 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def proximity_alert_triggered(): return ProximityAlertTriggered( - TestProximityAlertTriggeredBase.traveler, - TestProximityAlertTriggeredBase.watcher, - TestProximityAlertTriggeredBase.distance, + ProximityAlertTriggeredTestBase.traveler, + ProximityAlertTriggeredTestBase.watcher, + ProximityAlertTriggeredTestBase.distance, ) -class TestProximityAlertTriggeredBase: +class ProximityAlertTriggeredTestBase: traveler = User(1, "foo", False) watcher = User(2, "bar", False) distance = 42 -class TestProximityAlertTriggeredWithoutRequest(TestProximityAlertTriggeredBase): +class TestProximityAlertTriggeredWithoutRequest(ProximityAlertTriggeredTestBase): def test_slot_behaviour(self, proximity_alert_triggered): inst = proximity_alert_triggered for attr in inst.__slots__: diff --git a/tests/test_reaction.py b/tests/test_reaction.py index 6f3d3cb46..67ece80e3 100644 --- a/tests/test_reaction.py +++ b/tests/test_reaction.py @@ -28,6 +28,7 @@ from telegram import ( ReactionType, ReactionTypeCustomEmoji, ReactionTypeEmoji, + ReactionTypePaid, ) from telegram.constants import ReactionEmoji from tests.auxil.slots import mro_slots @@ -48,6 +49,10 @@ def reaction_type_emoji(): return ReactionTypeEmoji(RTDefaults.normal_emoji) +def reaction_type_paid(): + return ReactionTypePaid() + + def make_json_dict(instance: ReactionType, include_optional_args: bool = False) -> dict: """Used to make the json dict which we use for testing de_json. Similar to iter_args()""" json_dict = {"type": instance.type} @@ -99,6 +104,7 @@ def reaction_type(request): [ reaction_type_custom_emoji, reaction_type_emoji, + reaction_type_paid, ], indirect=True, ) @@ -112,6 +118,7 @@ class TestReactionTypesWithoutRequest: def test_de_json_required_args(self, bot, reaction_type): cls = reaction_type.__class__ assert cls.de_json(None, bot) is None + assert ReactionType.de_json({}, bot) is None json_dict = make_json_dict(reaction_type) const_reaction_type = ReactionType.de_json(json_dict, bot) @@ -155,7 +162,7 @@ class TestReactionTypesWithoutRequest: assert reaction_type_dict["type"] == reaction_type.type if reaction_type.type == ReactionType.EMOJI: assert reaction_type_dict["emoji"] == reaction_type.emoji - else: + elif reaction_type.type == ReactionType.CUSTOM_EMOJI: assert reaction_type_dict["custom_emoji_id"] == reaction_type.custom_emoji_id for slot in reaction_type.__slots__: # additional verification for the optional args diff --git a/tests/test_reply.py b/tests/test_reply.py index f41ed01eb..5cacb7b6b 100644 --- a/tests/test_reply.py +++ b/tests/test_reply.py @@ -41,16 +41,16 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def external_reply_info(): return ExternalReplyInfo( - origin=TestExternalReplyInfoBase.origin, - chat=TestExternalReplyInfoBase.chat, - message_id=TestExternalReplyInfoBase.message_id, - link_preview_options=TestExternalReplyInfoBase.link_preview_options, - giveaway=TestExternalReplyInfoBase.giveaway, - paid_media=TestExternalReplyInfoBase.paid_media, + origin=ExternalReplyInfoTestBase.origin, + chat=ExternalReplyInfoTestBase.chat, + message_id=ExternalReplyInfoTestBase.message_id, + link_preview_options=ExternalReplyInfoTestBase.link_preview_options, + giveaway=ExternalReplyInfoTestBase.giveaway, + paid_media=ExternalReplyInfoTestBase.paid_media, ) -class TestExternalReplyInfoBase: +class ExternalReplyInfoTestBase: origin = MessageOriginUser( dtm.datetime.now(dtm.timezone.utc).replace(microsecond=0), User(1, "user", False) ) @@ -65,7 +65,7 @@ class TestExternalReplyInfoBase: paid_media = PaidMediaInfo(5, [PaidMediaPreview(10, 10, 10)]) -class TestExternalReplyInfoWithoutRequest(TestExternalReplyInfoBase): +class TestExternalReplyInfoWithoutRequest(ExternalReplyInfoTestBase): def test_slot_behaviour(self, external_reply_info): for attr in external_reply_info.__slots__: assert getattr(external_reply_info, attr, "err") != "err", f"got extra slot '{attr}'" @@ -128,14 +128,14 @@ class TestExternalReplyInfoWithoutRequest(TestExternalReplyInfoBase): @pytest.fixture(scope="module") def text_quote(): return TextQuote( - text=TestTextQuoteBase.text, - position=TestTextQuoteBase.position, - entities=TestTextQuoteBase.entities, - is_manual=TestTextQuoteBase.is_manual, + text=TextQuoteTestBase.text, + position=TextQuoteTestBase.position, + entities=TextQuoteTestBase.entities, + is_manual=TextQuoteTestBase.is_manual, ) -class TestTextQuoteBase: +class TextQuoteTestBase: text = "text" position = 1 entities = [ @@ -145,7 +145,7 @@ class TestTextQuoteBase: is_manual = True -class TestTextQuoteWithoutRequest(TestTextQuoteBase): +class TestTextQuoteWithoutRequest(TextQuoteTestBase): def test_slot_behaviour(self, text_quote): for attr in text_quote.__slots__: assert getattr(text_quote, attr, "err") != "err", f"got extra slot '{attr}'" @@ -202,17 +202,17 @@ class TestTextQuoteWithoutRequest(TestTextQuoteBase): @pytest.fixture(scope="module") def reply_parameters(): return ReplyParameters( - message_id=TestReplyParametersBase.message_id, - chat_id=TestReplyParametersBase.chat_id, - allow_sending_without_reply=TestReplyParametersBase.allow_sending_without_reply, - quote=TestReplyParametersBase.quote, - quote_parse_mode=TestReplyParametersBase.quote_parse_mode, - quote_entities=TestReplyParametersBase.quote_entities, - quote_position=TestReplyParametersBase.quote_position, + message_id=ReplyParametersTestBase.message_id, + chat_id=ReplyParametersTestBase.chat_id, + allow_sending_without_reply=ReplyParametersTestBase.allow_sending_without_reply, + quote=ReplyParametersTestBase.quote, + quote_parse_mode=ReplyParametersTestBase.quote_parse_mode, + quote_entities=ReplyParametersTestBase.quote_entities, + quote_position=ReplyParametersTestBase.quote_position, ) -class TestReplyParametersBase: +class ReplyParametersTestBase: message_id = 123 chat_id = 456 allow_sending_without_reply = True @@ -225,7 +225,7 @@ class TestReplyParametersBase: quote_position = 5 -class TestReplyParametersWithoutRequest(TestReplyParametersBase): +class TestReplyParametersWithoutRequest(ReplyParametersTestBase): def test_slot_behaviour(self, reply_parameters): for attr in reply_parameters.__slots__: assert getattr(reply_parameters, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_replykeyboardmarkup.py b/tests/test_replykeyboardmarkup.py index 15654208d..68996a246 100644 --- a/tests/test_replykeyboardmarkup.py +++ b/tests/test_replykeyboardmarkup.py @@ -26,15 +26,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def reply_keyboard_markup(): return ReplyKeyboardMarkup( - TestReplyKeyboardMarkupBase.keyboard, - resize_keyboard=TestReplyKeyboardMarkupBase.resize_keyboard, - one_time_keyboard=TestReplyKeyboardMarkupBase.one_time_keyboard, - selective=TestReplyKeyboardMarkupBase.selective, - is_persistent=TestReplyKeyboardMarkupBase.is_persistent, + ReplyKeyboardMarkupTestBase.keyboard, + resize_keyboard=ReplyKeyboardMarkupTestBase.resize_keyboard, + one_time_keyboard=ReplyKeyboardMarkupTestBase.one_time_keyboard, + selective=ReplyKeyboardMarkupTestBase.selective, + is_persistent=ReplyKeyboardMarkupTestBase.is_persistent, ) -class TestReplyKeyboardMarkupBase: +class ReplyKeyboardMarkupTestBase: keyboard = [[KeyboardButton("button1"), KeyboardButton("button2")]] resize_keyboard = True one_time_keyboard = True @@ -42,7 +42,7 @@ class TestReplyKeyboardMarkupBase: is_persistent = True -class TestReplyKeyboardMarkupWithoutRequest(TestReplyKeyboardMarkupBase): +class TestReplyKeyboardMarkupWithoutRequest(ReplyKeyboardMarkupTestBase): def test_slot_behaviour(self, reply_keyboard_markup): inst = reply_keyboard_markup for attr in inst.__slots__: @@ -154,7 +154,7 @@ class TestReplyKeyboardMarkupWithoutRequest(TestReplyKeyboardMarkupBase): assert len(reply_keyboard_markup[1]) == 1 -class TestReplyKeyboardMarkupWithRequest(TestReplyKeyboardMarkupBase): +class TestReplyKeyboardMarkupWithRequest(ReplyKeyboardMarkupTestBase): async def test_send_message_with_reply_keyboard_markup( self, bot, chat_id, reply_keyboard_markup ): diff --git a/tests/test_replykeyboardremove.py b/tests/test_replykeyboardremove.py index f1a771e7f..f00545881 100644 --- a/tests/test_replykeyboardremove.py +++ b/tests/test_replykeyboardremove.py @@ -24,15 +24,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def reply_keyboard_remove(): - return ReplyKeyboardRemove(selective=TestReplyKeyboardRemoveBase.selective) + return ReplyKeyboardRemove(selective=ReplyKeyboardRemoveTestBase.selective) -class TestReplyKeyboardRemoveBase: +class ReplyKeyboardRemoveTestBase: remove_keyboard = True selective = True -class TestReplyKeyboardRemoveWithoutRequest(TestReplyKeyboardRemoveBase): +class TestReplyKeyboardRemoveWithoutRequest(ReplyKeyboardRemoveTestBase): def test_slot_behaviour(self, reply_keyboard_remove): inst = reply_keyboard_remove for attr in inst.__slots__: @@ -52,7 +52,7 @@ class TestReplyKeyboardRemoveWithoutRequest(TestReplyKeyboardRemoveBase): assert reply_keyboard_remove_dict["selective"] == reply_keyboard_remove.selective -class TestReplyKeyboardRemoveWithRequest(TestReplyKeyboardRemoveBase): +class TestReplyKeyboardRemoveWithRequest(ReplyKeyboardRemoveTestBase): async def test_send_message_with_reply_keyboard_remove( self, bot, chat_id, reply_keyboard_remove ): diff --git a/tests/test_sentwebappmessage.py b/tests/test_sentwebappmessage.py index c523ea09f..e4bc116d0 100644 --- a/tests/test_sentwebappmessage.py +++ b/tests/test_sentwebappmessage.py @@ -25,14 +25,14 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def sent_web_app_message(): - return SentWebAppMessage(inline_message_id=TestSentWebAppMessageBase.inline_message_id) + return SentWebAppMessage(inline_message_id=SentWebAppMessageTestBase.inline_message_id) -class TestSentWebAppMessageBase: +class SentWebAppMessageTestBase: inline_message_id = "123" -class TestSentWebAppMessageWithoutRequest(TestSentWebAppMessageBase): +class TestSentWebAppMessageWithoutRequest(SentWebAppMessageTestBase): def test_slot_behaviour(self, sent_web_app_message): inst = sent_web_app_message for attr in inst.__slots__: diff --git a/tests/test_shared.py b/tests/test_shared.py index 53e5fe4d8..c51bcf5ea 100644 --- a/tests/test_shared.py +++ b/tests/test_shared.py @@ -25,16 +25,16 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="class") def users_shared(): - return UsersShared(TestUsersSharedBase.request_id, users=TestUsersSharedBase.users) + return UsersShared(UsersSharedTestBase.request_id, users=UsersSharedTestBase.users) -class TestUsersSharedBase: +class UsersSharedTestBase: request_id = 789 user_ids = (101112, 101113) users = (SharedUser(101112, "user1"), SharedUser(101113, "user2")) -class TestUsersSharedWithoutRequest(TestUsersSharedBase): +class TestUsersSharedWithoutRequest(UsersSharedTestBase): def test_slot_behaviour(self, users_shared): for attr in users_shared.__slots__: assert getattr(users_shared, attr, "err") != "err", f"got extra slot '{attr}'" @@ -85,17 +85,17 @@ class TestUsersSharedWithoutRequest(TestUsersSharedBase): @pytest.fixture(scope="class") def chat_shared(): return ChatShared( - TestChatSharedBase.request_id, - TestChatSharedBase.chat_id, + ChatSharedTestBase.request_id, + ChatSharedTestBase.chat_id, ) -class TestChatSharedBase: +class ChatSharedTestBase: request_id = 131415 chat_id = 161718 -class TestChatSharedWithoutRequest(TestChatSharedBase): +class TestChatSharedWithoutRequest(ChatSharedTestBase): def test_slot_behaviour(self, chat_shared): for attr in chat_shared.__slots__: assert getattr(chat_shared, attr, "err") != "err", f"got extra slot '{attr}'" @@ -143,15 +143,15 @@ class TestChatSharedWithoutRequest(TestChatSharedBase): @pytest.fixture(scope="class") def shared_user(): return SharedUser( - TestSharedUserBase.user_id, - TestSharedUserBase.first_name, - last_name=TestSharedUserBase.last_name, - username=TestSharedUserBase.username, - photo=TestSharedUserBase.photo, + SharedUserTestBase.user_id, + SharedUserTestBase.first_name, + last_name=SharedUserTestBase.last_name, + username=SharedUserTestBase.username, + photo=SharedUserTestBase.photo, ) -class TestSharedUserBase: +class SharedUserTestBase: user_id = 101112 first_name = "first" last_name = "last" @@ -162,7 +162,7 @@ class TestSharedUserBase: ) -class TestSharedUserWithoutRequest(TestSharedUserBase): +class TestSharedUserWithoutRequest(SharedUserTestBase): def test_slot_behaviour(self, shared_user): for attr in shared_user.__slots__: assert getattr(shared_user, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_stars.py b/tests/test_stars.py index d3560af7d..ef700ae39 100644 --- a/tests/test_stars.py +++ b/tests/test_stars.py @@ -24,6 +24,8 @@ import pytest from telegram import ( Dice, + PaidMediaPhoto, + PhotoSize, RevenueWithdrawalState, RevenueWithdrawalStateFailed, RevenueWithdrawalStatePending, @@ -62,6 +64,16 @@ def withdrawal_state_pending(): def transaction_partner_user(): return TransactionPartnerUser( user=User(id=1, is_bot=False, first_name="first_name", username="username"), + invoice_payload="payload", + paid_media=[ + PaidMediaPhoto( + photo=[ + PhotoSize( + file_id="file_id", width=1, height=1, file_unique_id="file_unique_id" + ) + ] + ) + ], ) @@ -153,9 +165,9 @@ def transaction_partner(tp_scope_class_and_type): return tp_scope_class_and_type[0].de_json( { "type": tp_scope_class_and_type[1], - "invoice_payload": TestTransactionPartnerBase.invoice_payload, - "withdrawal_state": TestTransactionPartnerBase.withdrawal_state.to_dict(), - "user": TestTransactionPartnerBase.user.to_dict(), + "invoice_payload": TransactionPartnerTestBase.invoice_payload, + "withdrawal_state": TransactionPartnerTestBase.withdrawal_state.to_dict(), + "user": TransactionPartnerTestBase.user.to_dict(), }, bot=None, ) @@ -213,14 +225,14 @@ def revenue_withdrawal_state(rws_scope_class_and_type): return rws_scope_class_and_type[0].de_json( { "type": rws_scope_class_and_type[1], - "date": to_timestamp(TestRevenueWithdrawalStateBase.date), - "url": TestRevenueWithdrawalStateBase.url, + "date": to_timestamp(RevenueWithdrawalStateTestBase.date), + "url": RevenueWithdrawalStateTestBase.url, }, bot=None, ) -class TestStarTransactionBase: +class StarTransactionTestBase: id = "2" amount = 2 date = to_timestamp(datetime.datetime(2024, 1, 1, 0, 0, 0, 0, tzinfo=UTC)) @@ -234,7 +246,7 @@ class TestStarTransactionBase: receiver = TransactionPartnerOther() -class TestStarTransactionWithoutRequest(TestStarTransactionBase): +class TestStarTransactionWithoutRequest(StarTransactionTestBase): def test_slot_behaviour(self): inst = star_transaction() for attr in inst.__slots__: @@ -320,11 +332,11 @@ class TestStarTransactionWithoutRequest(TestStarTransactionBase): assert hash(a) != hash(c) -class TestStarTransactionsBase: +class StarTransactionsTestBase: transactions = [star_transaction(), star_transaction()] -class TestStarTransactionsWithoutRequest(TestStarTransactionsBase): +class TestStarTransactionsWithoutRequest(StarTransactionsTestBase): def test_slot_behaviour(self, star_transactions): inst = star_transactions for attr in inst.__slots__: @@ -365,13 +377,13 @@ class TestStarTransactionsWithoutRequest(TestStarTransactionsBase): assert hash(a) != hash(c) -class TestTransactionPartnerBase: +class TransactionPartnerTestBase: withdrawal_state = withdrawal_state_succeeded() user = transaction_partner_user().user invoice_payload = "payload" -class TestTransactionPartnerWithoutRequest(TestTransactionPartnerBase): +class TestTransactionPartnerWithoutRequest(TransactionPartnerTestBase): def test_slot_behaviour(self, transaction_partner): inst = transaction_partner for attr in inst.__slots__: @@ -482,12 +494,12 @@ class TestTransactionPartnerWithoutRequest(TestTransactionPartnerBase): assert hash(c) != hash(f) -class TestRevenueWithdrawalStateBase: +class RevenueWithdrawalStateTestBase: date = datetime.datetime(2024, 1, 1, 0, 0, 0, 0, tzinfo=UTC) url = "url" -class TestRevenueWithdrawalStateWithoutRequest(TestRevenueWithdrawalStateBase): +class TestRevenueWithdrawalStateWithoutRequest(RevenueWithdrawalStateTestBase): def test_slot_behaviour(self, revenue_withdrawal_state): inst = revenue_withdrawal_state for attr in inst.__slots__: diff --git a/tests/test_story.py b/tests/test_story.py index b521bebc5..1aad292cb 100644 --- a/tests/test_story.py +++ b/tests/test_story.py @@ -24,15 +24,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def story(): - return Story(TestStoryBase.chat, TestStoryBase.id) + return Story(StoryTestBase.chat, StoryTestBase.id) -class TestStoryBase: +class StoryTestBase: chat = Chat(1, "") id = 0 -class TestStoryWithoutRequest(TestStoryBase): +class TestStoryWithoutRequest(StoryTestBase): def test_slot_behaviour(self, story): for attr in story.__slots__: assert getattr(story, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_switchinlinequerychosenchat.py b/tests/test_switchinlinequerychosenchat.py index 8a5539860..e522c1644 100644 --- a/tests/test_switchinlinequerychosenchat.py +++ b/tests/test_switchinlinequerychosenchat.py @@ -26,15 +26,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def switch_inline_query_chosen_chat(): return SwitchInlineQueryChosenChat( - query=TestSwitchInlineQueryChosenChatBase.query, - allow_user_chats=TestSwitchInlineQueryChosenChatBase.allow_user_chats, - allow_bot_chats=TestSwitchInlineQueryChosenChatBase.allow_bot_chats, - allow_channel_chats=TestSwitchInlineQueryChosenChatBase.allow_channel_chats, - allow_group_chats=TestSwitchInlineQueryChosenChatBase.allow_group_chats, + query=SwitchInlineQueryChosenChatTestBase.query, + allow_user_chats=SwitchInlineQueryChosenChatTestBase.allow_user_chats, + allow_bot_chats=SwitchInlineQueryChosenChatTestBase.allow_bot_chats, + allow_channel_chats=SwitchInlineQueryChosenChatTestBase.allow_channel_chats, + allow_group_chats=SwitchInlineQueryChosenChatTestBase.allow_group_chats, ) -class TestSwitchInlineQueryChosenChatBase: +class SwitchInlineQueryChosenChatTestBase: query = "query" allow_user_chats = True allow_bot_chats = True @@ -42,7 +42,7 @@ class TestSwitchInlineQueryChosenChatBase: allow_group_chats = True -class TestSwitchInlineQueryChosenChat(TestSwitchInlineQueryChosenChatBase): +class TestSwitchInlineQueryChosenChat(SwitchInlineQueryChosenChatTestBase): def test_slot_behaviour(self, switch_inline_query_chosen_chat): inst = switch_inline_query_chosen_chat for attr in inst.__slots__: diff --git a/tests/test_update.py b/tests/test_update.py index b314c98e8..46619fbfd 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -212,14 +212,14 @@ ids = (*all_types, "callback_query_without_message") @pytest.fixture(scope="module", params=params, ids=ids) def update(request): - return Update(update_id=TestUpdateBase.update_id, **request.param) + return Update(update_id=UpdateTestBase.update_id, **request.param) -class TestUpdateBase: +class UpdateTestBase: update_id = 868573637 -class TestUpdateWithoutRequest(TestUpdateBase): +class TestUpdateWithoutRequest(UpdateTestBase): def test_slot_behaviour(self): update = Update(self.update_id) for attr in update.__slots__: diff --git a/tests/test_user.py b/tests/test_user.py index 8b0ae5df5..073d0af58 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -31,45 +31,45 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def json_dict(): return { - "id": TestUserBase.id_, - "is_bot": TestUserBase.is_bot, - "first_name": TestUserBase.first_name, - "last_name": TestUserBase.last_name, - "username": TestUserBase.username, - "language_code": TestUserBase.language_code, - "can_join_groups": TestUserBase.can_join_groups, - "can_read_all_group_messages": TestUserBase.can_read_all_group_messages, - "supports_inline_queries": TestUserBase.supports_inline_queries, - "is_premium": TestUserBase.is_premium, - "added_to_attachment_menu": TestUserBase.added_to_attachment_menu, - "can_connect_to_business": TestUserBase.can_connect_to_business, - "has_main_web_app": TestUserBase.has_main_web_app, + "id": UserTestBase.id_, + "is_bot": UserTestBase.is_bot, + "first_name": UserTestBase.first_name, + "last_name": UserTestBase.last_name, + "username": UserTestBase.username, + "language_code": UserTestBase.language_code, + "can_join_groups": UserTestBase.can_join_groups, + "can_read_all_group_messages": UserTestBase.can_read_all_group_messages, + "supports_inline_queries": UserTestBase.supports_inline_queries, + "is_premium": UserTestBase.is_premium, + "added_to_attachment_menu": UserTestBase.added_to_attachment_menu, + "can_connect_to_business": UserTestBase.can_connect_to_business, + "has_main_web_app": UserTestBase.has_main_web_app, } @pytest.fixture def user(bot): user = User( - id=TestUserBase.id_, - first_name=TestUserBase.first_name, - is_bot=TestUserBase.is_bot, - last_name=TestUserBase.last_name, - username=TestUserBase.username, - language_code=TestUserBase.language_code, - can_join_groups=TestUserBase.can_join_groups, - can_read_all_group_messages=TestUserBase.can_read_all_group_messages, - supports_inline_queries=TestUserBase.supports_inline_queries, - is_premium=TestUserBase.is_premium, - added_to_attachment_menu=TestUserBase.added_to_attachment_menu, - can_connect_to_business=TestUserBase.can_connect_to_business, - has_main_web_app=TestUserBase.has_main_web_app, + id=UserTestBase.id_, + first_name=UserTestBase.first_name, + is_bot=UserTestBase.is_bot, + last_name=UserTestBase.last_name, + username=UserTestBase.username, + language_code=UserTestBase.language_code, + can_join_groups=UserTestBase.can_join_groups, + can_read_all_group_messages=UserTestBase.can_read_all_group_messages, + supports_inline_queries=UserTestBase.supports_inline_queries, + is_premium=UserTestBase.is_premium, + added_to_attachment_menu=UserTestBase.added_to_attachment_menu, + can_connect_to_business=UserTestBase.can_connect_to_business, + has_main_web_app=UserTestBase.has_main_web_app, ) user.set_bot(bot) user._unfreeze() return user -class TestUserBase: +class UserTestBase: id_ = 1 is_bot = True first_name = "first\u2022name" @@ -85,7 +85,7 @@ class TestUserBase: has_main_web_app = False -class TestUserWithoutRequest(TestUserBase): +class TestUserWithoutRequest(UserTestBase): def test_slot_behaviour(self, user): for attr in user.__slots__: assert getattr(user, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_userprofilephotos.py b/tests/test_userprofilephotos.py index caff6a2a5..f0017ce6c 100644 --- a/tests/test_userprofilephotos.py +++ b/tests/test_userprofilephotos.py @@ -20,7 +20,7 @@ from telegram import PhotoSize, UserProfilePhotos from tests.auxil.slots import mro_slots -class TestUserProfilePhotosBase: +class UserProfilePhotosTestBase: total_count = 2 photos = [ [ @@ -34,7 +34,7 @@ class TestUserProfilePhotosBase: ] -class TestUserProfilePhotosWithoutRequest(TestUserProfilePhotosBase): +class TestUserProfilePhotosWithoutRequest(UserProfilePhotosTestBase): def test_slot_behaviour(self): inst = UserProfilePhotos(self.total_count, self.photos) for attr in inst.__slots__: diff --git a/tests/test_webappdata.py b/tests/test_webappdata.py index 5a1a5c3fc..a13043042 100644 --- a/tests/test_webappdata.py +++ b/tests/test_webappdata.py @@ -25,15 +25,15 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def web_app_data(): - return WebAppData(data=TestWebAppDataBase.data, button_text=TestWebAppDataBase.button_text) + return WebAppData(data=WebAppDataTestBase.data, button_text=WebAppDataTestBase.button_text) -class TestWebAppDataBase: +class WebAppDataTestBase: data = "data" button_text = "button_text" -class TestWebAppDataWithoutRequest(TestWebAppDataBase): +class TestWebAppDataWithoutRequest(WebAppDataTestBase): def test_slot_behaviour(self, web_app_data): for attr in web_app_data.__slots__: assert getattr(web_app_data, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_webappinfo.py b/tests/test_webappinfo.py index b0c8db817..40d658733 100644 --- a/tests/test_webappinfo.py +++ b/tests/test_webappinfo.py @@ -25,14 +25,14 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def web_app_info(): - return WebAppInfo(url=TestWebAppInfoBase.url) + return WebAppInfo(url=WebAppInfoTestBase.url) -class TestWebAppInfoBase: +class WebAppInfoTestBase: url = "https://www.example.com" -class TestWebAppInfoWithoutRequest(TestWebAppInfoBase): +class TestWebAppInfoWithoutRequest(WebAppInfoTestBase): def test_slot_behaviour(self, web_app_info): for attr in web_app_info.__slots__: assert getattr(web_app_info, attr, "err") != "err", f"got extra slot '{attr}'" diff --git a/tests/test_webhookinfo.py b/tests/test_webhookinfo.py index 807509534..48bb5ee38 100644 --- a/tests/test_webhookinfo.py +++ b/tests/test_webhookinfo.py @@ -29,18 +29,18 @@ from tests.auxil.slots import mro_slots @pytest.fixture(scope="module") def webhook_info(): return WebhookInfo( - url=TestWebhookInfoBase.url, - has_custom_certificate=TestWebhookInfoBase.has_custom_certificate, - pending_update_count=TestWebhookInfoBase.pending_update_count, - ip_address=TestWebhookInfoBase.ip_address, - last_error_date=TestWebhookInfoBase.last_error_date, - max_connections=TestWebhookInfoBase.max_connections, - allowed_updates=TestWebhookInfoBase.allowed_updates, - last_synchronization_error_date=TestWebhookInfoBase.last_synchronization_error_date, + url=WebhookInfoTestBase.url, + has_custom_certificate=WebhookInfoTestBase.has_custom_certificate, + pending_update_count=WebhookInfoTestBase.pending_update_count, + ip_address=WebhookInfoTestBase.ip_address, + last_error_date=WebhookInfoTestBase.last_error_date, + max_connections=WebhookInfoTestBase.max_connections, + allowed_updates=WebhookInfoTestBase.allowed_updates, + last_synchronization_error_date=WebhookInfoTestBase.last_synchronization_error_date, ) -class TestWebhookInfoBase: +class WebhookInfoTestBase: url = "http://www.google.com" has_custom_certificate = False pending_update_count = 5 @@ -51,7 +51,7 @@ class TestWebhookInfoBase: last_synchronization_error_date = time.time() -class TestWebhookInfoWithoutRequest(TestWebhookInfoBase): +class TestWebhookInfoWithoutRequest(WebhookInfoTestBase): def test_slot_behaviour(self, webhook_info): for attr in webhook_info.__slots__: assert getattr(webhook_info, attr, "err") != "err", f"got extra slot '{attr}'"