<commit_before># -*- coding: utf-8 -*-
__author__ = 'vden'
from model.contact import Contact
import pytest
import random
import string


def random_string(prefix, maxlen):
    symbols = string.ascii_letters+string.digits+" "*10
    return prefix+"".join([random.choice(symbols) for i in range(random.randrange(maxlen))])


testdata = [Contact(firstname="", middlename="", lastname="", nickname="", title="", company="",
                    address="", homephone="", mobilephone="", workphone="", fax="", address2="",
                    seconderyphone="", notes="")]+ [Contact(firstname=random_string('firstname', 10),
                                                    middlename=random_string('middlename', 10),
                                                    lastname=random_string('lastname', 10),
                                                    nickname=random_string('nickname', 10),
                                                    title=random_string('title', 10),
                                                    company=random_string('company', 10),
                                                    address=random_string('address', 10),
                                                    homephone=random_string('home', 10),
                                                    mobilephone=random_string('mobile', 10),
                                                    workphone=random_string('work', 10),
                                                    fax=random_string('fax', 10),
                                                    address2=random_string('address2', 10),
                                                    seconderyphone=random_string('phone2', 10),
                                                    notes=random_string('notes', 10)) for i in range(5)
]


@pytest.mark.parametrize("contact", testdata, ids=[repr(x) for x in testdata])
def test_add_contact(app, contact):
    old_contacts = app.contact.get_contact_list()
    app.contact.create(contact)
    assert len(old_contacts)+1 == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts.append(contact)
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)



<commit_msg>Задание №19: Реализована загрузка тестовых данных из файлов<commit_after># -*- coding: utf-8 -*-
__author__ = 'vden'
from model.contact import Contact


def test_add_contact(app, json_contacts):
    contact = json_contacts
    old_contacts = app.contact.get_contact_list()
    app.contact.create(contact)
    assert len(old_contacts)+1 == app.contact.count()
    new_contacts = app.contact.get_contact_list()
    old_contacts.append(contact)
    assert sorted(old_contacts, key=Contact.id_or_max) == sorted(new_contacts, key=Contact.id_or_max)




{'fraction_non_alphanumeric': 0.11557610241820768, 'fraction_numerical': 0.014580369843527738, 'mean_word_length': 1.861648016276704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 27, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1747211', 'n_tokens_mistral': 751, 'n_tokens_neox': 712, 'n_words': 133}