def test_person(): c1 = models.Contact("email", "*****@*****.**") c2 = models.Contact("email", "*****@*****.**") p = models.Person("Alice", "Alma", "Hüntzi 3", "Bern", "3007") p.contact.append(c1) p.contact.append(c2) assert p.primary_email == "*****@*****.**"
def test_contact_list_serializer(): c1 = models.Contact("emergency", "0774568293") c2 = models.Contact("mobile", "0791234567") c3 = models.Contact("email", "*****@*****.**") d = serializers.contact_list_serializer([c1, c2, c3]) assert tuple(d.keys()) == ("mobile", "email", "emergency") assert isinstance(d["mobile"], list)
def test_dump_person_list(): c1 = models.Contact("emergency", "0774568293") c2 = models.Contact("mobile", "0791234567") c3 = models.Contact("email", "*****@*****.**") p1 = models.Person("Aline", "Alma", contact=[c1, c2, c3]) p2 = models.Person("David", "Düber") f = io.StringIO() dumpers.person_list_yaml_dumper(f, [p1, p2]) f.seek(0) lst = parsers.person_list_parser(f) assert len(lst) == 2
def test_person_list_serializer(): c1 = models.Contact("emergency", "0774568293") c2 = models.Contact("mobile", "0791234567") c3 = models.Contact("email", "*****@*****.**") p1 = models.Person("Aline", "Alma", contact=[c1, c2, c3]) p2 = models.Person("David", "Düber") d = serializers.person_list_serializer([p2, p1]) d_vals = list(d.values()) assert list(d.keys()) == ["Aline_Alma", "David_Düber"] assert d_vals[0]["first_name"] == "Aline" assert isinstance(d_vals[0]["contact"]["mobile"], list)
def test_dump_course_text(): c1 = models.Contact("emergency", "0774568293") c2 = models.Contact("mobile", "0791234567") c3 = models.Contact("email", "*****@*****.**") p1 = models.Person("Aline", "Alma", contact=[c1, c2, c3]) p2 = models.Person("David", "Düber") course = models.Course(title="Laber", participants=[p1, p2]) f = io.StringIO() dumpers.course_text_dumper(f, course) f.seek(0) lines = list(f) assert len(lines) == 7 + 2
def test_person_age(): c = models.Contact("mobile", "0791234567") p = models.Person("Alice", "Alma", "Hüntzi 3", "Bern", "3007") p.contact.append(c) p.birthdate = datetime.date(2010, 1, 5) print("ID:", p.identifier) assert p.age(datetime.date(2020, 1, 5)) == 10
def contacts_to_list(contacts): lst = list() for channel, adresses in contacts.items(): if not isinstance(adresses, (list, tuple)): adresses = [adresses] for i, a in enumerate(adresses): lst.append(models.Contact(channel=channel, address=a, order=i)) return lst
def test_contact_phone(kind): c = models.Contact(kind, "0791234567") assert c.address == "+41 79 123 45 67"