def test_delete_contact_from_group(app): db = ORMFixture(host="localhost", name="addressbook", user="******", password="") if len(db.get_contact_list()) == 0: app.contact.create(Contact(firstname="Bro", lastname="Lu")) if len(db.get_group_list()) == 0: app.group.create( Group(name="Group1", header="header1", footer="footer1")) groups = db.get_group_list() group = random.choice(groups) contacts = db.get_contact_list() contact = random.choice(contacts) if len(db.get_contacts_in_group(group)) == 0: app.contact.add_contact_to_group(contact.id, group.id) contacts_in_group = db.get_contacts_in_group(group) contact_for_delete = random.choice(contacts_in_group) app.contact.delete_contact_from_group(contact_for_delete.id, group.id) contacts_not_in_group = db.get_contacts_not_in_group(group) assert contact_for_delete in contacts_not_in_group
def test_add_some_contact_in_group(app): db = ORMFixture(host='localhost', name='addressbook', user='******', password='') if len(db.get_group_list()) == 0: app.group.create(Group(name='Testname')) if len(db.get_contact_list()) == 0: app.contact.create( Contact(firstname="testname", lastname="testlastname", address="testaddress")) group_to_add = random.choice(db.get_group_list()) old_group_contacts = db.get_contacts_in_group(group_to_add) if len(db.get_contact_list()) == len( old_group_contacts ): # если все контакты входят в выбранную группу - создаем контакт app.contact.create( Contact(firstname="testname", lastname="testlastname", address="testaddress")) contact = random.choice(db.get_contacts_not_in_group(group_to_add)) app.contact.add_in_group_by_id(contact.id, group_to_add.id) old_group_contacts.append(contact) new_group_contacts = db.get_contacts_in_group(group_to_add) assert sorted(old_group_contacts, key=Contact.id_or_max) == sorted(new_group_contacts, key=Contact.id_or_max)
def test_delete_contact_from_group(app, db): db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") with allure.step('Check group and contact'): if len(db.get_group_list()) == 0: app.group.creation(Group(name="test")) if len(db.get_contact_list()) == 0: app.contact.creation(Contact(first_name="test")) with allure.step('Given a group list, contact list and random group'): old_groups = db.get_group_list() old_contacts = db.get_contact_list() group = random.choice(old_groups) group_id = group.id with allure.step('Check contact in group %s' % group): if len(db.get_contacts_in_group(Group(id=group_id))) == 0: contact = random.choice(old_contacts) contact_id = contact.id app.contact.add_contact_to_group(contact_id, group_id) with allure.step( 'Given a old contacts in group list and random contact to delete'): old_contacts_in_group = db.get_contacts_in_group(Group(id=group_id)) contact_to_delete = random.choice(old_contacts_in_group) contact_to_delete_id = contact_to_delete.id with allure.step('When I remove a contact %s from the group %s' % (contact_to_delete, group)): app.contact.delete_contact_from_group(contact_to_delete_id, group_id) with allure.step( 'Then the new contacts in group list is equal to the old contacts in group list withouth the deleted contact' ): new_contacts_in_group = db.get_contacts_in_group(Group(id=group_id)) old_contacts_in_group.remove(contact_to_delete) assert new_contacts_in_group == old_contacts_in_group
def test_add_contact_to_group(app): db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") contact_for_test = None group_for_test = None if len(db.get_group_list()) == 0: group_for_test = Group(name="test_group") app.group.create(group_for_test) if len(db.get_contact_list()) == 0: contact_for_test = Contact(firstname="test_contact") app.contact.create(contact_for_test) else: contact_for_test = random.choice(db.get_contact_list()) else: if len(db.get_contact_list()) == 0: contact_for_test = Contact(firstname="test_contact") app.contact.create(contact_for_test) group_for_test = random.choice(db.get_group_list()) else: groups = db.get_group_list() contacts = db.get_contact_list() for c in contacts: if len(db.get_contacts_groups(c)) == len(groups): continue else: groups_without_contact = [ g for g in groups if g not in db.get_contacts_groups(c) ] group_for_test = random.choice(groups_without_contact) contact_for_test = c break if contact_for_test is None: contact_for_test = Contact(firstname="test_contact") group_for_test = random.choice(db.get_group_list()) with allure.step('Given contacts in groups list'): old_contact_list_in_group = db.get_contacts_in_group(group_for_test) with allure.step('When I add a contact %s to the gtoup %s' % (group_for_test, contact_for_test)): app.contact.add_contact_to_group(contact_for_test, group_for_test) with allure.step('Then the the contact %s is in this group %s ' % (group_for_test, contact_for_test)): new_contact_list_in_group = db.get_contacts_in_group(group_for_test) assert len( new_contact_list_in_group) == len(old_contact_list_in_group) + 1 old_contact_list_in_group.append(contact_for_test) assert sorted(old_contact_list_in_group, key=Contact.id_or_max) == sorted( new_contact_list_in_group, key=Contact.id_or_max)
def test_all_contacts_homepage(app): db = ORMFixture(host='localhost', name='addressbook', user='******', password='') if len(db.get_contact_list()) == 0: app.contact.create(Contact(firstname="testname", lastname="testlastname", address="testaddress")) contacts_from_db = sorted(db.get_contact_list(), key=Contact.id_or_max) contacts_from_page = sorted(app.contact.get_contacts_list(), key=Contact.id_or_max) for contact in contacts_from_page: index = contacts_from_page.index(contact) contact_from_db = contacts_from_db[index] assert contact.firstname == contact_from_db.firstname assert contact.lastname == contact_from_db.lastname assert contact.address == contact_from_db.address assert contact.all_phones_from_page == merge_phones_like_on_home_page(contact_from_db) assert contact.all_mails_from_page == merge_mails_like_on_home_page(contact_from_db)
def test_add_contact_to_group(app): orm = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") # Check for available contacts and groups if len(orm.get_contact_list()) == 0: app.contact.create( Contact(firstname="Fname", middlename="Mname", lastname="Lname", nickname="Nick", title="TestTitle", company="TestCompany", address="TestAddress", homephone="1111111", mobilephone="2222222", workphone="3333333", fax="fax", email="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**", homepage="homepage", birth="1980", secondaryaddress="TestAddress2", secondaryphone="4444444")) if len(orm.get_group_list()) == 0: app.group.create( Group(name="test_name", header="test_header", footer="test_footer")) # Selection of random group and contact contact = random.choice(orm.get_contact_list()) group = random.choice(orm.get_group_list()) old_contacts_in_group = orm.get_contacts_in_group(group) # Adding of contact to group app.contact.add_contact_to_group(contact.id, group.name) new_contacts_in_group = orm.get_contacts_in_group(group) if len(old_contacts_in_group) == len(new_contacts_in_group): print( "\n", "Same group was chosen for the selected contact, please retry or create more groups" ) else: assert len(old_contacts_in_group) + 1 == len(new_contacts_in_group) for contact_in_group in new_contacts_in_group: assert (contact_in_group.id == contact.id) print("\n", "Contact", contact.firstname, "was successfully added to group", group.name)
def test_del_some_contact_from_group(app): db = ORMFixture(host='localhost', name='addressbook', user='******', password='') if len(db.get_group_list()) == 0: app.group.create(Group(name='Testname')) if len(db.get_contact_list()) == 0: app.contact.create( Contact(firstname="testname", lastname="testlastname", address="testaddress")) group_to_del = random.choice(db.get_group_list()) old_group_contacts = db.get_contacts_in_group(group_to_del) if len(old_group_contacts) == 0: contact_to_add = random.choice(db.get_contact_list) app.contact.add_in_group_by_id(contact_to_add.id, group_to_del.id) old_group_contacts.append(contact_to_add) contact = random.choice(old_group_contacts) app.contact.del_from_group_by_id(contact.id, group_to_del.id) old_group_contacts.remove(contact) new_group_contacts = db.get_contacts_in_group(group_to_del) assert sorted(old_group_contacts, key=Contact.id_or_max) == sorted(new_group_contacts, key=Contact.id_or_max)
def test_add_contact_in_group(app, db): db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") with allure.step('Check group and contact'): if len(db.get_group_list()) == 0: app.group.creation(Group(name="test")) if len(db.get_contact_list()) == 0: app.contact.creation(Contact(first_name="test")) with allure.step('Given a group list'): old_groups = db.get_group_list() with allure.step( 'Given a group, contact not in group and contact in group'): group = random.choice(old_groups) group_id = group.id contacts_without_group = db.get_contacts_not_in_group( Group(id=group_id)) contact = random.choice(contacts_without_group) contact_id = contact.id old_contacts_in_group = db.get_contacts_in_group(Group(id=group_id)) with allure.step('When I add a contact %s to the group %s' % (contact, group)): app.contact.add_contact_to_group(contact_id, group_id) with allure.step( 'Then the new contacts in group list is equal to the old contacts in group list with the added contact' ): new_contacts_in_group = db.get_contacts_in_group(Group(id=group_id)) old_contacts_in_group.append(contact) assert sorted(new_contacts_in_group, key=Contact.id_or_max) == sorted(old_contacts_in_group, key=Contact.id_or_max)
def test_add_contact_in_group(app, db): db = ORMFixture(host="127.0.0.1", name = "addressbook", user="******", password="") if len(db.get_contact_list()) == 0: app.contact.create(Contact(last="test")) if len(db.get_group_list()) == 0: app.group.create(Group(name="test")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) old_groups = db.get_group_list() group = random.choice(old_groups) app.contact.add_contact_to_group(contact.id, group) app.contact.show_contacts_in_group(group) list_contacts = app.contact.get_contact_list() def clean(contact): return Contact(id = contact.id, first = contact.first.strip(), last = contact.last.strip()) db_list = map(clean, db.get_contacts_in_group(group)) assert sorted(list_contacts, key = Contact.id_or_max) == sorted(db_list, key = Contact.id_or_max)
def test_del_from_group(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.add_new_contact( Contact(firstname="Gleb", middlename="Alex", lastname="Kazarkin", nickname="gkazarkin", title="AccTitle", company="TestCompany", address="Yakovleva 5", homephone="515232", mobilephone="89539235812", workphone="367412", fax="89539234611", email="*****@*****.**", email2="*****@*****.**", homepage="gkazarkin.com", bday="11", bmonth="April", byear="1987", aday="11", amonth="April", ayear="1987", address2="Yakovleva 5", secondaryphone="515232", notes="Test Note")) if len(db.get_group_list()) == 0: app.group.create(Group(name="test")) old_groups = db.get_group_list() old_contacts = db.get_contact_list() try: db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") l = db.get_contacts_in_group(Group(id="330")) for item in l: print(item) assert (len(l)) > 0 print(len(l)) finally: pass """Указывается ID группы""" # app.contact.del_from_group(group_id=random_group.id) app.contact.del_from_group(group_id=330) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) """Опциональный флаг проверки через UI Прописать запуск можно или в консоли или справа вверху Edit_Configuration - Additional arguments (Options) --check_ui""" if check_ui: assert sorted(new_contacts, key=Contact.id_or_max) == sorted( app.contact.get_contact_list(), key=Contact.id_or_max)
class ContactBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="chrome"): self.browser = browser config_name = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_name) as config_file: self.target = json.load(config_file) def init_fixtures(self): web_config = self.target["web"] self.fixture = Application(browser=self.browser, base_url=web_config["baseUrl"]) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target["db"] self.dbfixture = ORMFixture(host=db_config["host"], name=db_config["name"], user=db_config["user"], password=db_config["password"]) def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() def new_contact(self, firstname, lastname): return Contact(first_name=firstname, last_name=lastname) def create_contact(self, contact): self.fixture.contact.add_new(contact) def get_contact_list(self): return self.dbfixture.get_contact_list() def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def update_contact(self, contact_old, contact_new): self.fixture.contact.update_contact_by_id(contact_new, contact_old.id) def update_value_in_list(self, contact_list, contact_to_update, contact_with_new_data): # NOTE: this action is based on the shallow copying of the objects and greatly on immutability contact = contact_list[contact_list.index(contact_to_update)] contact.first_name = contact_with_new_data.first_name contact.last_name = contact_with_new_data.last_name
def test_eq_of_all_contacts_db_with_ui(app): ui = sorted(app.contact.get_contact_list(), key=Contact.id_or_max) db = ORMFixture(host='127.0.0.1', name='addressbook', user='******', password='') db_list = sorted(db.get_contact_list(), key=Contact.id_or_max) for i in range(len(ui)): assert ui[i].all_phones_from_homepage == merge_phones_like_on_homepage( db_list[i]) assert ui[i].firstname == db_list[i].firstname assert ui[i].lastname == db_list[i].lastname assert ui[i].address == db_list[i].address assert ui[i].allemails == merge_emails_like_on_homepage(db_list[i])
def test_check_all_contacts_data(app): if app.contact.count() == 0: app.contact.create( Contact(firstname="firstname", lastname="lastname", address="address", home_phone="123", work_phone="456", mobile_phone="789", secondary_phone="135", email1="*****@*****.**", email2="*****@*****.**", email3="*****@*****.**")) with allure.step('Given contact list from db and from homepage'): contacts_from_homepage = sorted(app.contact.get_contact_list(), key=Contact.id_or_max) db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") contacts_from_db = sorted(db.get_contact_list(), key=Contact.id_or_max) with allure.step( 'When I get contact email and phones from db and homepage'): for c in contacts_from_db: c.all_phones_from_home_page = merge_phones_like_on_home_page(c) c.all_emails_from_home_page = merge_emails_like_on_home_page(c) list_of_phones_from_db = [] list_of_emails_from_db = [] list_of_phones_from_home_page = [] list_of_emails_from_home_page = [] for i in range(0, len(contacts_from_db)): list_of_phones_from_db.append( contacts_from_db[i].all_phones_from_home_page) list_of_emails_from_db.append( contacts_from_db[i].all_emails_from_home_page) list_of_phones_from_home_page.append( contacts_from_homepage[i].all_phones_from_home_page) list_of_emails_from_home_page.append( contacts_from_homepage[i].all_emails_from_home_page) with allure.step( 'Then contact data from db should be equal to contact data from home page' ): assert contacts_from_db == contacts_from_homepage assert list_of_phones_from_db == list_of_phones_from_home_page assert list_of_emails_from_db == list_of_emails_from_home_page
def test_add_random_contact_to_random_group(app): orm = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") groups = orm.get_group_list() contacts = orm.get_contact_list() if len(contacts) == 0: app.contact.create((Contact(firstname="firstname", middlename="middlename", lastname="lastname", nickname="nickname", title="title", company="company", address="address", homephone="home", mobilephone="mobile", workphone="work", fax="fax", email="email", homepage="homepage", address2="address2", secondaryphone="phone2", notes="notes"))) if len(groups) == 0: app.group.create(Group(name="test")) app.contact.open_contact_list_page() # get random id contact and group contact = random.choice(contacts) contact_id = contact.id group = random.choice(groups) group_name = group.name group_id = group.id # add contact to random group old_contacts_in_groups = orm.get_contacts_in_group(Group(id=group_id)) app.contact.add_contact_to_group(contact_id, group_name) # verified contact in group new_contacts_in_groups = orm.get_contacts_in_group(Group(id=group_id)) if len(old_contacts_in_groups) == len(new_contacts_in_groups): print("Contact wasnt' added, randomly choosed same group") else: assert len(old_contacts_in_groups) + 1 == len(new_contacts_in_groups) for contact_in_group in new_contacts_in_groups: assert (contact_in_group.id == contact_id)
db = ORMFixture(host="127.0.0.1",name="addressbook",user="******",password="") connection = mysql.connector.connect(host="127.0.0.1",database="addressbook", user="******", password="") try: l = db.get_group_list() for item in l: print(item) finally: pass #db.destroy() ORM автоматически закрывает сессию с БД try: l = db.get_contact_list() for item in l: print(item) finally: pass #db.destroy() ORM автоматически закрывает сессию с БД try: l = db.get_contacts_in_group(Group(id="804")) for item in l: print(item) finally: pass #db.destroy() ORM автоматически закрывает сессию с БД try: l = db.get_contacts_not_in_group(Group(id="804"))
# __author__ = 'Alexey Buchkin' from fixture.orm import ORMFixture from model.group import Group db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") try: l = db.get_contact_list() for item in l: print(item) print(len(l)) finally: pass
__author__ = 'lemontree' from fixture.orm import ORMFixture from model.group import Group import random db = ORMFixture(host = "127.0.0.1", name = "addressbook", user = "******", password = "") try: l = db.get_contacts_not_in_group(Group(id="144")) print (random.choice(db.get_contact_list())) print("end of random") for item in l: print(item) print(len(l)) finally: pass # db.destroy()
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="chrome"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) db_config = self.target['db'] self.ormfixture = ORMFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.ormfixture.destroy() self.fixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.ormfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def new_contact(self, firstname, lastname, address): return Contact(firstname=firstname, lastname=lastname, address=address) def get_contact_list(self): return self.ormfixture.get_contact_list() def create_contact(self, contact): self.fixture.contact.create(contact) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def modify_contact(self, contact, new_contact): self.fixture.contact.edit_contact_by_id(contact.id, new_contact) def get_modified_contact(self, contact, new_contact): new_contact.id = contact.id return new_contact def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max)
# __author__ = 'Irina.Chegodaeva' import re from random import randrange from fixture.db import * import pytest from fixture.orm import ORMFixture db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") try: list_items = db.get_contact_list() for item in list_items: print(item) index = len(list_items) finally: pass @pytest.mark.parametrize("contact", list_items, ids=[repr(x) for x in list_items]) def test_contact_on_home_page_compare_with_db(app, db, contact): count_contact = len(db.get_contact_list()) contact_from_home_page = None contact_from_db = None if count_contact == 0: app.contact.add_contact(Contact(first_name="test" + app.libs.substring), delete_photo=False, dataset=(("1", "3"), ("2", "2"), ("3", "12"), ("4", "3"), ("5", "1"))) index = int(contact.id) for l1 in app.contact.get_contact_list(): if int(l1.id) == index:
def test_del_random_contact_from_group(app, db): orm = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") groups = orm.get_group_list() contacts = orm.get_contact_list() if len(contacts) == 0: app.contact.create((Contact(firstname="firstname", middlename="middlename", lastname="lastname", nickname="nickname", title="title", company="company", address="address", homephone="home", mobilephone="mobile", workphone="work", fax="fax", email="email", homepage="homepage", address2="address2", secondaryphone="phone2", notes="notes"))) if len(groups) == 0: app.group.create(Group(name="test")) app.contact.open_contact_list_page() # check contacts in group presence contacts_in_group = db.get_all_contacts_in_group() if len(contacts_in_group) == 0: # add contact in group contact = random.choice(contacts) contact_id = contact.id group = random.choice(groups) group_name = group.name group_id = group.id # add contact to random group old_contacts_in_groups = orm.get_contacts_in_group(Group(id=group_id)) app.contact.add_contact_to_group(contact_id, group_name) # verified contact in group new_contacts_in_groups = orm.get_contacts_in_group(Group(id=group_id)) if len(old_contacts_in_groups) == len(new_contacts_in_groups): print("Contact wasnt' added, randomly choosed same group") else: assert len(old_contacts_in_groups) + 1 == len( new_contacts_in_groups) for contact_in_group in new_contacts_in_groups: assert (contact_in_group.id == contact_id) # delete random contact from group contacts_in_group = db.get_all_contacts_in_group() contact_in_group = random.choice(contacts_in_group) contact_id = contact_in_group.id group_id = contact_in_group.group_id # get group name group_name = None for g in groups: if str(g.id) == str(group_id): group_name = g.name if group_name == None: raise ValueError("Can't find group_id") print("-------> " + str(group_name)) app.contact.delete_contact_from_group(contact_id, group_name) contacts_in_groups_after_deletion = db.get_all_contacts_in_group() assert len(contacts_in_group) - 1 == len(contacts_in_groups_after_deletion)
import mysql.connector from tests_contract.contact_lib import Contact from fixture.orm import ORMFixture db = ORMFixture(host='127.0.0.1', name='addressbook', user='******', password='') try: groups = db.get_contact_list() for group in groups: print group print len(groups) finally: pass #db.destroy() ''' try: cursor = connection.cursor() cursor.execute('select id, firstname, middlename, lastname, nickname, title, company, address, home, ' 'mobile, work, fax, email, email2, email3, homepage, address2, phone2, notes ' 'from addressbook') for row in cursor: print (row) (id, firstname, middlename, lastname, nickname, title, company, address, home, mobile, work, fax, email, email2, email3, homepage, address2, phone2, notes) = row list.append(Contact(first_name=firstname, last_name=lastname, middle_name=middlename, nickname=nickname,
from model.contact import Contact import random db = ORMFixture(host="localhost", name="addressbook", user="******", password="") # # try: # groups = random.choice(db.get_group_list()) # l = db.get_contacts_not_in_group(groups) # for item in l: # print(item) # print(len(l)) # finally: # pass #db.destroy() try: groups = random.choice(db.get_contact_list()) #print("TYPE GR", type(groups)) #groupid = random.choice(groups) print("TIPE ID", type(groups)) l = db.get_groups_not_in_contact((random.choice(db.get_contact_list()).id)) for item in l: print(item) print(len(l)) finally: pass #db.destroy() # try: # l = len(db.get_group_list()) # # print("результат", l) #
from fixture.orm import ORMFixture from model.group import Group from model.contact import Contact db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") try: group = Group(id="300") c = db.get_contact_list(search="name") for item in c: print(item) print(len(c)) finally: pass