from scenarios import *
scenario = (
# Disable the throttling, otherwise it’s way too long
send_stanza(""),
expect_stanza("/iq[@type='result']",
after = save_value("sessionid", extract_attribute("/iq[@type='result']/commands:command[@node='configure']", "sessionid"))),
send_stanza(""
""
""
"6667"
"66976670"
"9999"
""),
expect_stanza("/iq[@type='result']/commands:command[@node='configure'][@status='completed']/commands:note[@type='info'][text()='Configuration successfully applied.']"),
send_stanza(""),
sequences.connection("irc.localhost", '{jid_one}/{resource_one}'),
expect_stanza("/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
expect_stanza("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']",
"/presence/muc_user:x/muc_user:status[@code='110']"),
expect_stanza("/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]",
after = save_value("counter", lambda x: 0)),
(
send_stanza("{counter}"),
expect_stanza("/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='{counter}']",
after = save_value("counter", lambda stanza: str(1 + int(extract_text("/message/body", stanza))))),
) * 150,
# Retrieve the archive, without any restriction
send_stanza(""),
expect_stanza("/message/mam:result[@queryid='qid1']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid1']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='0']"),
# followed by 98 more messages
(
expect_stanza("/message/mam:result[@queryid='qid1']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid1']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body"),
) * 98,
# and finally the message "99"
expect_stanza("/message/mam:result[@queryid='qid1']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid1']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='99']",
after = save_value("last_uuid", extract_attribute("/message/mam:result", "id"))),
# And it should not be marked as complete
expect_stanza("/iq[@type='result'][@id='id1'][@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}']",
"/iq/mam:fin/rsm:set/rsm:last[text()='{last_uuid}']",
"!/iq//mam:fin[@complete='true']",
"/iq//mam:fin"),
# Retrieve the next page, using the “after” thingy
send_stanza("{last_uuid}"),
expect_stanza("/message/mam:result[@queryid='qid2']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid2']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='100']"),
(
expect_stanza("/message/mam:result[@queryid='qid2']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid2']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body"),
) * 48,
expect_stanza("/message/mam:result[@queryid='qid2']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid2']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='149']",
after = save_value("last_uuid", extract_attribute("/message/mam:result", "id"))),
expect_stanza("/iq[@type='result'][@id='id2'][@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}']",
"/iq/mam:fin/rsm:set/rsm:last[text()='{last_uuid}']",
"/iq//mam:fin[@complete='true']",
"/iq//mam:fin"),
# Send a request with a non-existing ID set as the “after” value.
send_stanza("DUMMY_ID"),
expect_stanza("/iq[@id='id3'][@type='error']/error[@type='cancel']/stanza:item-not-found"),
# Request the last page just BEFORE the last message in the archive
send_stanza(""),
expect_stanza("/message/mam:result[@queryid='qid3']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid3']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='50']"),
(
expect_stanza("/message/mam:result[@queryid='qid3']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid3']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body"),
) * 98,
expect_stanza("/message/mam:result[@queryid='qid3']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid3']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='149']",
after = save_value("last_uuid", extract_attribute("/message/mam:result", "id"))),
expect_stanza("/iq[@type='result'][@id='id3'][@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}']",
"/iq/mam:fin/rsm:set/rsm:last[text()='{last_uuid}']",
"!/iq//mam:fin[@complete='true']",
"/iq//mam:fin"),
# Do the same thing, but with a limit value.
send_stanza("{last_uuid}2"),
expect_stanza("/message/mam:result[@queryid='qid4']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid4']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='147']"),
expect_stanza("/message/mam:result[@queryid='qid4']/forward:forwarded/delay:delay",
"/message/mam:result[@queryid='qid4']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='148']",
after = save_value("last_uuid", extract_attribute("/message/mam:result", "id"))),
expect_stanza("/iq[@type='result'][@id='id4'][@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}']",
"/iq/mam:fin/rsm:set/rsm:last[text()='{last_uuid}']",
"!/iq/mam:fin[@complete='true']"),
# Test if everything is fine even with weird max value: 0
send_stanza("0"),
expect_stanza("/iq[@type='result'][@id='id5'][@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}']",
"!/iq/mam:fin[@complete='true']"),
)