<commit_before>__author__ = 'NovikovII'

import re
import random
from model.contact import Contact

def random_contact(app):
    count = app.contact.count()
    return random.randint(0, count-1)

def test_phones_on_home_page(app, data_contacts):
    if app.contact.count() == 0:
        app.contact.add_contact(data_contacts)
    #получаем список контактов с web-страницы
    edit_contact = random_contact(app)
    contact_from_home_page = app.contact.get_contact_list()[edit_contact]
    contact_from_edit_page = app.contact.get_contact_list_info_from_edit_page(edit_contact)
    assert contact_from_home_page.paramentr['all_phone_from_home_page'] == merge_phone_like_on_home_page(contact_from_edit_page)
    assert contact_from_home_page.paramentr['all_emal_from_home_page'] == merge_email_like_on_home_page(contact_from_edit_page)
    assert contact_from_home_page.paramentr['lastname'] == contact_from_edit_page.paramentr['lastname']
    assert contact_from_home_page.paramentr['firstname'] == contact_from_edit_page.paramentr['firstname']
    assert contact_from_home_page.paramentr['address'] == contact_from_edit_page.paramentr['address']


def test_phones_on_contact_view_page(app, data_contacts):
    if app.contact.count() == 0:
        app.contact.add_contact(data_contacts)
    #получаем список контактов с web-страницы
    contact_from_view_page = app.contact.get_contact_from_view_page(0)
    contact_from_edit_page = app.contact.get_contact_list_info_from_edit_page(0)
    assert contact_from_view_page.paramentr['mobile'] == contact_from_edit_page.paramentr['mobile']

def clear(s):
    return re.sub("[() -]", "", s)

def merge_phone_like_on_home_page(contact):
    return "\n".join(filter(lambda x: x != "",
                            map(lambda x: clear(x),
                                filter(lambda x: x is not None,
                                       [contact.paramentr['home'], contact.paramentr['mobile'], contact.paramentr['work'], contact.paramentr['phone2']]))))

def merge_email_like_on_home_page(contact):
    return "\n".join(filter(lambda x: x != "",
                            filter(lambda x: x is not None,
                                  [contact.paramentr['email'], contact.paramentr['email2'], contact.paramentr['email3']])))<commit_msg>Задание №21: Переделать тесты для проверки информации о контактах на главной странице Переделать тесты для проверки информации о контактах на главной странице -- на этот раз нужно реализовать сравнение для всех записей, а не для одной случайно выбранной. А сравнивать -- с информацией, загруженной из базы данных.<commit_after>__author__ = 'NovikovII'

import re
import random
from model.contact import Contact

def random_contact(app):
    count = app.contact.count()
    return random.randint(0, count-1)

def test_phones_on_home_page(app, data_contacts):
    if app.contact.count() == 0:
        app.contact.add_contact(data_contacts)
    #получаем список контактов с web-страницы
    edit_contact = random_contact(app)
    contact_from_home_page = app.contact.get_contact_list()[edit_contact]
    contact_from_edit_page = app.contact.get_contact_list_info_from_edit_page(edit_contact)
    assert contact_from_home_page.paramentr['all_phone_from_home_page'] == merge_phone_like_on_home_page(contact_from_edit_page)
    assert contact_from_home_page.paramentr['all_emal_from_home_page'] == merge_email_like_on_home_page(contact_from_edit_page)
    assert contact_from_home_page.paramentr['lastname'] == contact_from_edit_page.paramentr['lastname']
    assert contact_from_home_page.paramentr['firstname'] == contact_from_edit_page.paramentr['firstname']
    assert contact_from_home_page.paramentr['address'] == contact_from_edit_page.paramentr['address']


def test_phones_on_db(app, db, data_contacts):
    if app.contact.count() == 0:
        app.contact.add_contact(data_contacts)
    #получаем список контактов с web-страницы
    contact_from_home_page = app.contact.get_contact_list()
    contact_from_db = db.get_contact_list()
    contact_from_home_page.sort(key=Contact.id_or_max)
    contact_from_db.sort(key=Contact.id_or_max)
    assert len(contact_from_home_page) == len(contact_from_db)
    for i in range(len(contact_from_home_page)):
        assert contact_from_home_page[i].paramentr['all_phone_from_home_page'] == merge_phone_like_on_home_page(contact_from_db[i])
        assert contact_from_home_page[i].paramentr['all_emal_from_home_page'] == merge_email_like_on_home_page(contact_from_db[i])
        assert contact_from_home_page[i].paramentr['lastname'] == contact_from_db[i].paramentr['lastname']
        assert contact_from_home_page[i].paramentr['firstname'] == contact_from_db[i].paramentr['firstname']
        assert contact_from_home_page[i].paramentr['address'] == contact_from_db[i].paramentr['address']


def test_phones_on_contact_view_page(app, data_contacts):
    if app.contact.count() == 0:
        app.contact.add_contact(data_contacts)
    #получаем список контактов с web-страницы
    contact_from_view_page = app.contact.get_contact_from_view_page(0)
    contact_from_edit_page = app.contact.get_contact_list_info_from_edit_page(0)
    assert contact_from_view_page.paramentr['mobile'] == contact_from_edit_page.paramentr['mobile']


def clear(s):
    return re.sub("[() -]", "", s)


def merge_phone_like_on_home_page(contact):
    return "\n".join(filter(lambda x: x != "",
                            map(lambda x: clear(x),
                                filter(lambda x: x is not None,
                                       [contact.paramentr['home'], contact.paramentr['mobile'], contact.paramentr['work'], contact.paramentr['phone2']]))))


def merge_email_like_on_home_page(contact):
    return "\n".join(filter(lambda x: x != "",
                            filter(lambda x: x is not None,
                                  [contact.paramentr['email'], contact.paramentr['email2'], contact.paramentr['email3']])))
{'fraction_non_alphanumeric': 0.10754495042849942, 'fraction_numerical': 0.003528818685935137, 'mean_word_length': 4.480662983425415, '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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3582562', 'n_tokens_mistral': 1972, 'n_tokens_neox': 2032, 'n_words': 300}