def test_mod_group_name(app, db, check_ui): # Check if any group exist, and if not - create one, insert name if db.get_db_groups_list() == 0: app.group.create(GroupForm(group_name="AutocreatedGroup")) # Modify random group name old_groups_list = db.get_db_groups_list() group_selected = random.choice(old_groups_list) group = GroupForm(group_name="TestModGroupName") # Ensure the id of the modified item will remain group.group_id = group_selected.group_id app.group.mod_by_id(group.group_id, group) new_groups_list = db.get_db_groups_list() # First check if group was modified meaning len is the same assert len(old_groups_list) == len(new_groups_list) # # Change the item in old list with new item, sort lists ascending and check if they are still equal # for item in old_groups_list: # if item.group_id == group.group_id: # item.group_name = group.group_name # sorted_old_groups_list = sorted(old_groups_list, key=GroupForm.id_or_max) # sorted_new_groups_list = sorted(new_groups_list, key=GroupForm.id_or_max) # assert sorted_old_groups_list == sorted_new_groups_list # Check match of UI and DB lists if check_ui: sorted_db_new_groups_list = sorted([clear(x) for x in new_groups_list], key=GroupForm.id_or_max) sorted_ui_new_groups_list = sorted([clear(x) for x in app.group.get_groups_list()], key=GroupForm.id_or_max) assert sorted_db_new_groups_list == sorted_ui_new_groups_list
def test_add_contact_to_group(app, db): # Get groups and contacts list, make sure they are not empty db_groups_list = db.get_db_groups_list() db_contacts_list = db.get_db_contacts_list() if not db_groups_list: app.group.create(GroupForm(group_name="AutocreatedGroup")) db_groups_list = db.get_db_groups_list() if not db_contacts_list: app.contact.create(ContactForm(contact_name="AutocreatedContact")) db_contacts_list = db.get_db_contacts_list() # Choose random group and contact group = random.choice(db_groups_list) contact = random.choice(db_contacts_list) # Check if the contact is not in the group. Options: # 1. The contact is not in the group - add it to the group. # 2. The contact is in the group - ok, choose another one, which is not in the group. # 3. All other contacts are also in the group, list db_contacts_not_in_group is empty - create contact and # add it to the group. db_contacts_in_group = orm.get_db_contacts_in_group(GroupForm(group_id=group.group_id)) db_contacts_not_in_group = orm.get_db_contacts_not_in_group(GroupForm(group_id=group.group_id)) if contact not in db_contacts_in_group: app.contact.add_contact_to_group(contact.contact_id, group.group_id) else: if db_contacts_not_in_group: contact = random.choice(db_contacts_not_in_group) app.contact.add_contact_to_group(contact.contact_id, group.group_id) else: if not db_contacts_not_in_group: contact = ContactForm(contact_name="AutocreatedContact") app.contact.create(contact) contact = db.get_db_contacts_list()[-1] app.contact.add_contact_to_group(contact.contact_id, group.group_id) # db - check the contact was added in the group db_contacts_in_group = orm.get_db_contacts_in_group(GroupForm(group_id=group.group_id)) assert contact in db_contacts_in_group
def test_mod_group_footer(app, db, check_ui): # Check if any group exist, and if not - create one, insert footer if db.get_db_groups_list() == 0: app.group.create(GroupForm(group_footer="AutocreatedGroup")) # Modify random group footer old_groups_list = db.get_db_groups_list() group_selected = random.choice(old_groups_list) group = GroupForm(group_footer="TestModGroupFooter") # Ensure the id and name of the modified item will remain group.group_id = group_selected.group_id group.group_name = group_selected.group_name app.group.mod_by_id(group.group_id, group) new_groups_list = db.get_db_groups_list() # First check if group was modified meaning len is the same assert len(old_groups_list) == len(new_groups_list) # Check match of UI and DB lists if check_ui: sorted_db_new_groups_list = sorted([clear(x) for x in new_groups_list], key=GroupForm.id_or_max) sorted_ui_new_groups_list = sorted([clear(x) for x in app.group.get_groups_list()], key=GroupForm.id_or_max) assert sorted_db_new_groups_list == sorted_ui_new_groups_list
def test_remove_contact_from_group(app, db): # Make sure groups and contacts lists are not empty db_groups_list = db.get_db_groups_list() db_contacts_list = db.get_db_contacts_list() if not db_groups_list: app.group.create(GroupForm(group_name="AutocreatedGroup")) db_groups_list = db.get_db_groups_list() if not db_contacts_list: app.contact.create(ContactForm(contact_name="AutocreatedContact")) db_contacts_list = db.get_db_contacts_list() # Choose random group and contact group = random.choice(db_groups_list) contact = random.choice(db_contacts_list) # Make sure the contact is in the group db_contacts_in_group = orm.get_db_contacts_in_group( GroupForm(group_id=group.group_id)) if contact not in db_contacts_in_group: app.contact.add_contact_to_group(contact.contact_id, group.group_id) # Remove the contact from the group app.contact.remove_contact_from_group(contact.contact_id, group.group_id) assert contact not in db_contacts_in_group
def get_groups_list(self): # Cache handling if self.group_cache is None: wd = self.app.wd # Get list of groups on groups page (id, name) self.open_groups_page() self.group_cache = [] for element in wd.find_elements_by_css_selector("span.group"): id = element.find_element_by_name("selected[]").get_attribute( "value") text = element.text self.group_cache.append(GroupForm(group_id=id, group_name=text)) #return groups_list return list(self.group_cache)
def get_db_groups_list(self): db_groups_list = [] cursor = self.connection.cursor() try: cursor.execute( "select group_id, group_name, group_header, group_footer from group_list" ) # for row in cursor.fetchall(): # print(row) for row in cursor: (group_id, group_name, group_header, group_footer) = row db_groups_list.append( GroupForm(group_id=str(group_id), group_name=group_name, group_header=group_header, group_footer=group_footer)) finally: cursor.close() return db_groups_list
def test_del_group(app, db, check_ui): # Check if any group exist, and if not - create one with allure.step('Given a non-empty group list'): old_groups_list = db.get_db_groups_list() if not old_groups_list: app.group.create(GroupForm(group_name="AutocreatedGroup")) old_groups_list = db.get_db_groups_list() group = random.choice(old_groups_list) with allure.step('When I delete the group %s from the list' % group): app.group.del_by_id(group.group_id) with allure.step('Then the new group list is equal to the old group list without the deleted group'): new_groups_list = db.get_db_groups_list() # First check - if group was deleted at all assert len(old_groups_list) - 1 == len(new_groups_list) # Second check - if remained groups are equal old_groups_list.remove(group) assert old_groups_list == new_groups_list # Check match of UI and DB lists if check_ui: sorted_db_new_groups_list = sorted([clear(x) for x in new_groups_list], key=GroupForm.id_or_max) sorted_ui_new_groups_list = sorted([clear(x) for x in app.group.get_groups_list()], key=GroupForm.id_or_max) assert sorted_db_new_groups_list == sorted_ui_new_groups_list
# symbols = string.ascii_letters + string.digits + string.punctuation + " "*10 symbols = string.ascii_letters + string.digits + " " * 10 # Random choice of symbols, generated for cycle of random length, not higher than max length list_random_symbols = [random.choice(symbols) for i in range(random.randrange(maxlen))] random_string_from_symbols_list = prefix + "".join(list_random_symbols) return random_string_from_symbols_list # # Random options of test data # # Create 2 groups, 1 random and 1 empty # testdata = [ # GroupForm(group_name=random_string("group_name_", 10), # group_header=random_string("group_header_", 15), # group_footer=random_string("group_footer_", 20)), # GroupForm("", "", "")] # # Create 1 empty group and several random # testdata = \ # [GroupForm("", "", "")] + \ # [GroupForm(group_name=random_string("group_name_", 10), group_header=random_string("group_header_", 15), # group_footer=random_string("group_footer_", 20)) for i in range(5)] # # Create groups randomly, including empty # testdata = [ # GroupForm(group_name=group_name, group_header=group_header, group_footer=group_footer) # for group_name in ["", random_string("group_name", 10)] # for group_header in ["", random_string("group_header", 15)] # for group_footer in ["", random_string("group_footer", 20)] # ] # Create random groups testdata = [GroupForm(group_name=random_string("GN__", 5), group_header=random_string("GH__", 10), group_footer=random_string("GF__", 15)) for i in range(5)]
def clean(group): return GroupForm(group_id=group.group_id, group_name=group.group_name.strip())
def convert_group(group): return GroupForm(group_id=str(group.group_id), group_name=group.group_name, group_header=group.group_header, group_footer=group.group_footer)
from model.group_form import GroupForm testdata = [ GroupForm(group_name="GN_" + str(1), group_header="GH_" + str(1), group_footer="GF_" + str(1)), GroupForm(group_name="GN_" + str(2), group_header="GH_" + str(2), group_footer="GF_" + str(2)), GroupForm(group_name="GN_" + str(3), group_header="GH_" + str(3), group_footer="GF_" + str(3)) ]
db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") try: # Get groups groups = db.get_db_groups_list() # for group in groups: # print(group) # Get contacts contacts = db.get_db_contacts_list() # for contact in contacts: # print(contact) # Get contacts not in the group # Insert group id input_group = input("Enter group id \n") contacts_not_in_group = db.get_db_contacts_not_in_group( GroupForm(group_id=input_group)) contact_not_in_group_id = [] for item in contacts_not_in_group: contact_not_in_group_id.append(item.contact_id) # Get groups with its contacts contacts_in_group = db.get_db_contacts_in_group( GroupForm(group_id=input_group)) contact_in_group_id = [] for item in contacts_in_group: contact_in_group_id.append(item.contact_id) print("There are " + str(len(contacts_in_group)) + " contacts in group " + str(input_group) + " . ID: " + str(contact_in_group_id)) print("There are " + str(len(contacts_not_in_group)) + " contacts not in group " + str(input_group) + " . ID: " + str(contact_not_in_group_id)) print("There are overall " + str(len(groups)) + " groups and " +
def non_empty_group_list(db, app): if len(db.get_db_groups_list()) == 0: app.group.create(GroupForm(group_name="TestGroup")) result = db.get_db_groups_list() return result
def new_group(name, header, footer): return GroupForm(group_name=name, group_header=header, group_footer=footer)