Spaces:
Running
Running
File size: 2,483 Bytes
de05efa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """Only the Share URL: the autorename bot asks for the link of a file in the Database Channel; nothing is published."""
from app.dbpublish import LinkNotice, parse_link_notice, parse_notice, parse_delete_notice
from .test_dbpublish import FILE_LINK, FakeReader, FakeUserbot, file_post, handle, make_app, notice, run
def ask(post=None, ref="l1"):
lines = ["Get the share URL"]
if post is not None:
lines.append(f"Post: {post}")
if ref:
lines.append(f"Ref: {ref}")
return "\n".join(lines)
def test_the_message_is_read_and_is_nothing_else():
assert parse_link_notice(ask(7)) == LinkNotice(post_id=7, ref="l1")
assert parse_link_notice("GET the Share URL\npost : x").post_id is None
assert parse_link_notice("please get the share url\nPost: 7") is None and parse_link_notice(None) is None
assert parse_notice(ask(7)) is None and parse_delete_notice(ask(7)) is None and parse_link_notice(notice(post=3)) is None
def test_the_link_is_returned_and_nothing_is_posted(tmp_path):
async def go():
app = await make_app(tmp_path)
post = file_post(app)
ev = await handle(app, ask(post.id))
assert ev.replies[0] == "๐ฅ Message received - looking for the Share URLโฆ\nRef: l1"
assert ev.replies[1] == f"๐ Share URL ready\nURL: {FILE_LINK}\nRef: l1"
assert not app.tg.sent and not app.tg.requests
await app.db.close()
run(go())
def test_the_userbot_reads_it_when_the_bot_cannot_see_the_button(tmp_path):
async def go():
app = await make_app(tmp_path)
hidden = file_post(app, buttons=False)
seen = file_post(app)
reader = FakeReader(app.clock, {hidden.id: seen})
app.ctx.userbot = FakeUserbot(reader)
ev = await handle(app, ask(hidden.id))
assert ev.replies[-1].startswith("๐ Share URL ready") and "read through the userbot" in ev.replies[-1]
await app.db.close()
run(go())
def test_failures_are_reported(tmp_path):
async def go():
app = await make_app(tmp_path)
none = await handle(app, ask(None), mid=2)
assert "no โPost:โ line" in none.replies[-1] and none.replies[-1].startswith("โ Share URL failed: ")
bare = file_post(app, buttons=False)
no_button = await handle(app, ask(bare.id), mid=3)
assert "No ๐ Share URL button" in no_button.replies[-1] and "Ref: l1" in no_button.replies[-1]
await app.db.close()
run(go())
|