import datetime
import unittest
from slixmpp import Iq
from slixmpp.test import SlixTest
from slixmpp.plugins.xep_0292 import stanza
REF = """
Full Name
FullName
some nick
1984-05-21
https://nicoco.fr
About me
xmpp:test@localhost
test@gmail.com
work
tel:+555
Nice
France
"""
class TestVcard(SlixTest):
def test_basic_interfaces(self):
iq = Iq()
x = iq["vcard"]
x["fn"]["text"] = "Full Name"
x["nickname"]["text"] = "some nick"
x["n"]["given"] = "Full"
x["n"]["surname"] = "Name"
x["bday"]["date"] = datetime.date(1984, 5, 21)
x["note"]["text"] = "About me"
x["url"]["uri"] = "https://nicoco.fr"
x["impp"]["uri"] = "xmpp:test@localhost"
x["email"]["text"] = "test@gmail.com"
x["tel"]["uri"] = "tel:+555"
x["tel"]["parameters"]["type_"]["text"] = "work"
x["adr"]["locality"] = "Nice"
x["adr"]["country"] = "France"
self.check(iq, REF, use_values=False)
def test_easy_interface(self):
iq = Iq()
x: stanza.VCard4 = iq["vcard"]
x["full_name"] = "Full Name"
x["given"] = "Full"
x["surname"] = "Name"
x["birthday"] = datetime.date(1984, 5, 21)
x.add_nickname("some nick")
x.add_note("About me")
x.add_url("https://nicoco.fr")
x.add_impp("xmpp:test@localhost")
x.add_email("test@gmail.com")
x.add_tel("+555", "work")
x.add_address("France", "Nice")
self.check(iq, REF, use_values=False)
def test_2_phones(self):
vcard = stanza.VCard4()
tel1 = stanza.Tel()
tel1["parameters"]["type_"]["text"] = "work"
tel1["uri"] = "tel:+555"
tel2 = stanza.Tel()
tel2["parameters"]["type_"]["text"] = "devil"
tel2["uri"] = "tel:+666"
vcard.append(tel1)
vcard.append(tel2)
self.check(
vcard,
"""
work
tel:+555
devil
tel:+666
""",
use_values=False
)
suite = unittest.TestLoader().loadTestsFromTestCase(TestVcard)