Skip to content

Commit

Permalink
Update tests for workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
thedemons committed Jan 20, 2022
1 parent 3ba16c9 commit 4c64010
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions tests/tdata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,56 @@
from src.td import TDesktop
from src.tl.telethon import TelegramClient
from src.api import API, CreateNewSession, UseCurrentSession
from telethon.errors.rpcerrorlist import FreshResetAuthorisationForbiddenError

import asyncio
import pytest
import pytest_asyncio
from _pytest._io import TerminalWriter

@pytest.mark.asyncio
async def test_entry_point(event_loop):
event_loop._close = event_loop.close
event_loop.close = lambda: None
await tdata_to_telethon()


async def tdata_to_telethon():


api_desktop = API.TelegramDesktop.Generate("windows", "!thedemons#opentele")
api_ios = API.TelegramIOS.Generate("!thedemons#opentele")


tdesk = TDesktop("tests/tdata_test_profile", api_desktop, "!thedemons#opentele", "opentele#thedemons!")
assert tdesk.isLoaded()


oldClient = await tdesk.ToTelethon(flag=UseCurrentSession, api=api_desktop)

await oldClient.connect()
assert await oldClient.is_user_authorized()

await oldClient.PrintSessions()


newClient = await tdesk.ToTelethon(flag=CreateNewSession, api=api_ios, password="!thedemons#opentele")

await newClient.connect()
assert await newClient.is_user_authorized()

await newClient.PrintSessions()

await oldClient.TerminateAllSessions()

tdesk = await oldClient.ToTDesktop(UseCurrentSession, api=api_desktop)
tdesk.SaveTData("tests/tdata_test_profile", "!thedemons#opentele", "opentele#thedemons!")

try:
await oldClient.TerminateAllSessions()
except FreshResetAuthorisationForbiddenError as e:
pass


# Fix for "RuntimeError: Event loop is closed"
# Thanks to https://github.com/pytest-dev/pytest-asyncio/issues/30

@pytest_asyncio.fixture
def event_loop():
writer = TerminalWriter(sys.stdout)
writer.hasmarkup = True
writer.write("\n\n")
writer.sep("=", "Begin testing for opentele package", yellow=True)

policy = asyncio.get_event_loop_policy()
res = policy.new_event_loop()
res._close = res.close
res.close = lambda: None
res.run_until_complete(tdata_to_telethon())

yield res

@pytest.mark.asyncio
async def test_entry_point(event_loop):
pass
tdesk = await oldClient.ToTDesktop(UseCurrentSession, api=api_desktop)
tdesk.SaveTData("tests/tdata_test_profile", "!thedemons#opentele", "opentele#thedemons!")


await oldClient.disconnect()
await newClient.disconnect()
await oldClient.disconnected
await newClient.disconnected

Binary file modified tests/tdata_test_profile/FAC6C2D89AFB5816/configs
Binary file not shown.
Binary file modified tests/tdata_test_profile/FAC6C2D89AFB5816/maps
Binary file not shown.
Binary file modified tests/tdata_test_profile/FAC6C2D89AFB5816s
Binary file not shown.
Binary file modified tests/tdata_test_profile/key_opentele#thedemons!s
Binary file not shown.

0 comments on commit 4c64010

Please sign in to comment.