def test_modify_group_name(app): if app.group.count == 0: app.group.change_field(Group(name=app.group.name_generator(), header="Header", footer="footer")) old_group = app.group.get_group_list() index = randrange(len(old_group)) group = Group(name="New funny group") group.id = old_group[index].id app.group.modify_group_by_index(index, group) assert len(old_group) == app.group.count() new_group = app.group.get_group_list() old_group[index] = group assert sorted(old_group, key=Group.id_or_max) == sorted(new_group, key=Group.id_or_max)
def test_modify_group_name(app): if app.group.count == 0: app.group.change_field( Group(name=app.group.name_generator(), header="Header", footer="footer")) old_group = app.group.get_group_list() index = randrange(len(old_group)) group = Group(name="New funny group") group.id = old_group[index].id app.group.modify_group_by_index(index, group) assert len(old_group) == app.group.count() new_group = app.group.get_group_list() old_group[index] = group assert sorted(old_group, key=Group.id_or_max) == sorted(new_group, key=Group.id_or_max)
def test_delete_contact_to_group(app2, db, orm): #проверка на пустой список групп if len(orm.get_group_list()) == 0: app2.group.create( Group(name="Created in_test_delete_contact_to_group", footer="Created footer_in_test_delete_contact_to_group", header="Created header_in_test_delete_contact_to_group")) # выбираем любую группу, переходим к ней app2.navigation.open_home_page() active_groups = orm.get_group_list() target_group = random.choice(active_groups) app2.group.select_some_group_to_view(target_group) # смотрим, сколько контактов в группе old_contacts = orm.get_contacts_in_group(target_group) # проверка на пустой список контактов if len(old_contacts) == 0: app2.contact.create( Contact( firstname2="firstname-created_in_test_delete_contact_to_group", middlename="middlename-created_in_test_delete_contact_to_group", lastname="lastname-created_in_test_delete_contact_to_group", nickname="nickname-created", title="title-created", company="company-created", address="address-created", home='home-created', mobile='mobile-created', work='work-created', fax='fax-created', email='*****@*****.**', email2='*****@*****.**', email3='*****@*****.**', address2='Another address-created', phone2='home_secondary-created', notes='Some text-created')) app2.contact.select_contact_by_index(0) app2.group.add_selected_contact_to_selected_group_by_id(target_group) app2.navigation.go_to_target_group_by_id(target_group.id) old_contacts = orm.get_contacts_in_group(target_group) # old_contacts.append(created_contact1) # return list(old_contacts) contact = random.choice(old_contacts) app2.contact.select_contact_by_id(contact.id) # удаляем выбранный контакт app2.contact.delete_selected_contact_in_group_page() app2.navigation.go_to_target_group_by_id( target_group.id) # просто чтобы контакт успел удалиться # app2.navigation.go_to_target_group_by_id_v2(target_group.id, text="Users removed.") # app2.navigation.wait(10) # собираем новый список контактов этой группы new_contacts = orm.get_contacts_in_group(target_group) old_contacts.remove(contact) # проверка, что список после удаления контакта совпадает с списком ??? каким assert sorted(new_contacts, key=Group.id_or_max) == sorted(old_contacts, key=Group.id_or_max)
def get_group_list(self): if self.group_cache is None: wd = self.app.wd self.open_group_page() self.group_cache = [] for element in wd.find_elements_by_css_selector('span.group'): text = element.text id = element.find_element_by_name('selected[]').get_attribute('value') self.group_cache.append(Group(name=text, id=id)) return list(self.group_cache)
def test_edit_group_name(app2, db, check_ui): # если число групп == 0, то делаем новую, чтобы ее можно было модифицировать if len(db.get_group_list()) == 0: app2.group.create(Group(name="Created name")) # собираем старый список групп из бд old_groups = db.get_group_list() group = random.choice(old_groups) new_group_data = Group(id=group.id, name="WOW03", footer=None, header=None) app2.group.edit_group_by_id(group.id, new_group_data) new_groups = db.get_group_list() assert len(old_groups) == app2.group.count() new_groups.remove(new_group_data) old_groups.remove(group) assert sorted(new_groups, key=Group.id_or_max) == sorted(old_groups, key=Group.id_or_max) if check_ui: newest_groups = db.get_group_list() assert sorted(newest_groups, key=Group.id_or_max) == sorted( app2.group.get_group_list(), key=Group.id_or_max)
def get_group_list(self): if self.group_cache is None: wd = self.app.wd self.app.navigation.open_groups_page() self.group_cache = [] wd.find_elements_by_css_selector("span.group") for element in wd.find_elements_by_css_selector("span.group"): text = element.text id = int( element.find_element_by_name("selected[]").get_attribute( "value")) self.group_cache.append(Group(name=text, id=id)) return list(self.group_cache)
def test_delete_some_group(app2, db, check_ui): if len(db.get_group_list()) == 0: app2.group.create(Group(name="Created name", footer="Created footer", header="Created header")) old_groups = db.get_group_list() group = random.choice(old_groups) app2.group.delete_group_by_id(group.id) new_groups = db.get_group_list() assert len(old_groups) - 1 == app2.group.count() old_groups.remove(group) assert old_groups == new_groups if check_ui: assert sorted(new_groups, key=Group.id_or_max) == sorted(app2.group.get_group_list(), key=Group.id_or_max) # assert new_groups == app2.group.get_group_list() #раскомментировать, чтобы проверить работоспособность check_ui: если тест упал - работает
def test_del_group(app): if app.group.count == 0: app.group.change_field( Group(name=app.group.name_generator(), header="Header", footer="footer")) old_group = app.group.get_group_list() index = randrange(len(old_group)) app.group.delete_by_index(index) assert len(old_group) - 1 == app.group.count() new_group = app.group.get_group_list() old_group[index:index + 1] = [] assert old_group == new_group
def get_group_list(self): list = [] cursor = self.connection.cursor() try: cursor.execute( "SELECT group_id, group_name, group_header, group_footer FROM group_list" ) for row in cursor: (id, name, header, footer) = row list.append( Group(id=id, name=name, header=header, footer=footer)) finally: cursor.close() return list
def test_add_contact_to_group(app2, db, orm): #проверка на пустой список контактов if len(db.get_contact_list()) == 0: app2.contact.create(Contact(firstname2="firstname-created_orm", middlename="middlename-created_orm", lastname="lastname-created_orm", nickname="nickname-created", title="title-created", company="company-created", address="address-created", home='home-created', mobile='mobile-created', work='work-created', fax='fax-created', email='*****@*****.**', email2='*****@*****.**', email3='*****@*****.**', address2='Another address-created', phone2='home_secondary-created', notes='Some text-created')) #проверка на пустой список групп if len(db.get_group_list()) == 0: app2.group.create(Group(name="Created name_orm", footer="Created footer_orm", header="Created header_orm")) app2.navigation.open_home_page() # выбор произвольной группы из дропдауна all_groups = orm.get_group_list() target_group = random.choice(all_groups) # выбрать любой контакт, который не входит в группы contacts_not_in_group = orm.get_contacts_not_in_group(target_group) # проверка на пустой список контактов if len(contacts_not_in_group) == 0: created_contact = app2.contact.create(Contact(firstname2="firstname-created_not_in_group", middlename="middlename-created_not_in_group", lastname="lastname-created_not_in_group", nickname="nickname-created", title="title-created", company="company-created", address="address-created", home='home-created', mobile='mobile-created', work='work-created', fax='fax-created', email='*****@*****.**', email2='*****@*****.**', email3='*****@*****.**', address2='Another address-created', phone2='home_secondary-created', notes='Some text-created')) contacts_not_in_group.append(created_contact) return list(contacts_not_in_group) contact = random.choice(contacts_not_in_group) app2.contact.select_contact_by_id(contact.id) # собрать старый список контактов в группах из orm old_cont_in_gr_orm = orm.get_contacts_in_group(target_group) # добавляем выбранный контакт в выбранную группу app2.group.add_selected_contact_to_selected_group_by_id(target_group) # собрать новый список контактов в группах из orm new_cont_in_gr_orm = orm.get_contacts_in_group(target_group) old_cont_in_gr_orm.append(contact) assert sorted(old_cont_in_gr_orm, key=Group.id_or_max) == sorted(new_cont_in_gr_orm, key=Group.id_or_max)
from fixture.orm import ORMFixture from model.model_group import Group from model.model_contact import Contact db = ORMFixture(host="127.0.0.1", database="addressbook", user="******", password="") try: l = db.get_contacts_not_in_group(Group(id='559')) for item in l: print(item) print(len(l)) finally: pass """ # извлекаем список групп из БД try: groups = db.get_group_list() for group in groups: print(group) print(len(groups)) finally: pass #db.destroy() - orm автоматически закрывает соединение с БД try: # извлекаем список контактов из БД contacts = db.get_contact_list() for contact in contacts:
def clean(group): return Group(id=group.id, name=group.name.strip())
def convert(group): return Group(id=group.id, name=group.name, header=group.header, footer=group.footer)
try: opts, args = getopt.getopt(sys.argv[1:], "n:f:", ["number of group", "file"]) except getopt.GetoptError as err: #getopt.usage() sys.exit(2) n = 5 f = "data/group.json" for o, a in opts: if o == "-n": n = int(a) elif o == "-f": f = a def random_string(prefix, maxlen): symbols = string.ascii_letters + string.digits + " " * 10 #string.punctuation + " "*10 return prefix + "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) test_data = [Group(name="Group name #2", header="Header", footer="footer")] + \ [Group(name=random_string("name", 10), header=random_string("header", 20), footer=random_string("footer", 20)) for i in range(n)] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f) with open(file, "w") as out: jsonpickle.set_encoder_options("json", indent=2) out.write(jsonpickle.encode(test_data))