Leibniz-HBI / tegracli

A Telegram/telethon research convenience wrapper for the terminal.
https://pypi.org/project/tegracli/
MIT License
5 stars 1 forks source link

[Problem] Unit tests for interface code to Telethon #16

Open pekasen opened 2 years ago

pekasen commented 2 years ago

Problem: Telethon requires the client to be registered and authenticated with Telegram with makes running tests quite difficult. As Telethon is an implementation of Telegram's MTProto-protocol which utilizes TCP with the low-level socket-package, mocking is not easily done with readily-available packages.

Solution 1: Mocking the Telethon.TelegramClient with prerecorded/mock data. Would require a sophisticated implementation and introduces quite some complexity. Additionally it will require some learning about asyncio's EventLoops and how to disable actual requests to socket.socket.

Solution 2: Marking the tests that require interactions with Telethon/Telegram optional and running them if valid crendentials are supplied by the user and pytest is told by the user to do so – this would mean that running tests in GH actions on push/pull request may be quite expensive as rate limit errors may cause the test to pause for ~24h.

Further alternatives and input is more than welcome.