"""
This only covers the component registration side of the XEP-0077 plugin
"""
import unittest
from slixmpp import ComponentXMPP, Iq
from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.test import SlixTest
from slixmpp.plugins.xep_0077 import Register
class TestRegistration(SlixTest):
def setUp(self):
self.stream_start(
mode="component", plugins=["xep_0077"], jid="shakespeare.lit", server="lit"
)
def testRegistrationForm(self):
self.stream_start(
mode="component", plugins=["xep_0077"], jid="shakespeare.lit", server="lit"
)
self.recv(
"""
""",
)
self.send(
f"""
{self.xmpp["xep_0077"].form_instructions}
""",
use_values=False # Fails inconsistently without this
)
def testRegistrationSuccessAndModif(self):
self.recv(
"""
bill
Calliope
"""
)
self.send("")
user_store = self.xmpp["xep_0077"]._user_store
self.assertEqual(user_store["bill@server"]["username"], "bill")
self.assertEqual(user_store["bill@server"]["password"], "Calliope")
self.recv(
"""
""",
)
self.send(
f"""
{self.xmpp["xep_0077"].form_instructions}
bill
Calliope
""",
use_values=False # Fails inconsistently without this
)
def testRegistrationAndRemove(self):
self.recv(
"""
bill
Calliope
"""
)
self.send("")
pseudo_iq = self.xmpp.Iq()
pseudo_iq["from"] = "bill@shakespeare.lit/globe"
user = self.xmpp["xep_0077"].api["user_get"](None, None, None, pseudo_iq)
self.assertEqual(user["username"], "bill")
self.assertEqual(user["password"], "Calliope")
self.recv(
"""
"""
)
self.send("")
user_store = self.xmpp["xep_0077"]._user_store
self.assertIs(user_store.get("bill@shakespeare.lit"), None)
suite = unittest.TestLoader().loadTestsFromTestCase(TestRegistration)