def test_modify_group_name(app, db, check_ui): with allure.step('Check group'): if len(db.get_group_list()) == 0: app.group.creation(Group(name="test")) with allure.step('Given a group list and group to modify'): old_groups = db.get_group_list() index = randrange(len(old_groups)) group = Group(name="New group") group.id = old_groups[index].id with allure.step('When I change a group info to %s' % group): app.group.modify_group_by_id(group, group.id) with allure.step( 'Then the new group list is equal to the old list with new group info' ): new_groups = db.get_group_list() assert len(old_groups) == len(new_groups) old_groups[index] = group assert old_groups == new_groups if check_ui: assert sorted(new_groups, key=Group.id_or_max) == sorted( app.group.get_group_list(), key=Group.id_or_max) # def test_modify_group_header(app): # if app.group.count() == 0: # app.group.creation(Group(header="test")) # old_groups = app.group.get_group_list() # app.group.modify_first_group(Group(header="New group")) # new_groups = app.group.get_group_list() # assert len(old_groups) == len(new_groups)
def test_edit_name_group_by_index(app, db, check_ui): if len(db.get_group_list()) == 0: app.group.create(Group(name="NSKjcndk", header="dfde", footer="dddfe")) old_groups = db.get_group_list() group_by_edit = random.choice(old_groups) group = Group(name="new") group.id = group_by_edit.id app.group.edit_by_id(group_by_edit.id, group) new_groups = db.get_group_list() assert len(old_groups) == len(new_groups) for element in old_groups: if element == group_by_edit: element.name = group.name assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max) if check_ui: assert sorted(old_groups, key=Group.id_or_max) == sorted( app.group.get_group_list(), key=Group.id_or_max)
def main(): logger.info("Test") # f = open("quotes.json", "r") # quotes = f.read() # quotes = json.loads(quotes) # for quote in quotes.values(): # logger.info(quote) # dao.insert_quote(quote) # f = open("bakchods.json", "r") # quotes = f.read() # quotes = json.loads(quotes) # for quote in quotes: # logger.info(quote) # bakchod = Bakchod(quote["id"], None, None) # bakchod.username = quote.get("username") # bakchod.first_name = quote.get("first_name") # bakchod.lastseen = quote.get("lastseen") # bakchod.rokda = quote.get("rokda") # bakchod.censored = quote.get("censored") # bakchod.history = quote.get("history") # dao.insert_bakchod(bakchod) f = open("groups.json", "r") quotes = f.read() quotes = json.loads(quotes) for quote in quotes: logger.info(quote) group = Group(None, None) group.id = quote.get("id") group.title = quote.get("title") group.members = quote.get("members") dao.insert_group(group)
def test_edit_random_group(app, db, check_ui): with pytest.allure.step('Given a non-empty group list'): if len(db.get_group_list()) == 0: app.group.create( Group(name="Name_for_editing", header="Header_for_editing", footer="Footer_for_editing")) old_groups = db.get_group_list() with pytest.allure.step('Given a group data'): data_for_edit = Group(name="Edited name", header="Edited header", footer="Edited footer") with pytest.allure.step('Given a random group from the list'): group_for_edit = random.choice(old_groups) data_for_edit.id = group_for_edit.id with pytest.allure.step('When I replace the data in selected group'): app.group.edit_group_by_id(data_for_edit) with pytest.allure.step( ' Then the new group list is equal to the old group list with selected group replaced by a new group' ): new_groups = db.get_group_list() old_groups.remove(group_for_edit) old_groups.append(data_for_edit) assert sorted(old_groups, key=Group.group_id_or_max) == sorted( new_groups, key=Group.group_id_or_max) if check_ui: assert sorted(new_groups, key=Group.group_id_or_max) == \ sorted(app.group.get_group_list(), key=Group.group_id_or_max)
def test_modify_some_group(app): # Get list og existing groups old_groups_list = app.group_page.get_list() group_to_modify = Group(name="! test") # Check if there is any group exist in list if len(old_groups_list) == 0: app.group_page.create(Group(name="! test")) # Generate index to modify index = randrange(len(old_groups_list)) # Find certain group in list group_to_modify.id = old_groups_list[index].id # Determinate fields to modify # group_modified = Group(name="Modified Group", footer="Modified footer", header="Modified header") group_modified = Group(name="Modified Group", _id=group_to_modify.id) # at least name # Modify group in WEB app.group_page.modify_by_index(index, group_modified) # Assert result assert len(old_groups_list) == app.group_page.count() # additional assert for list length in case of exception # Get updated group list new_groups_list = app.group_page.get_list() # Change modified group in old list old_groups_list[index] = group_modified assert sorted(old_groups_list, key=Group.id_or_max) == sorted(new_groups_list, key=Group.id_or_max)
def test_method_modify_group_name(app, db, check_ui): if len(db.get_group_list()) == 0: app.group.create(Group(name="test")) old_groups = db.get_group_list() index = random.randrange(len(old_groups)) group = Group(name="New name") group.id = old_groups[index].id app.group.modify_group_by_id(group.id, group) new_groups = db.get_group_list() assert len(old_groups) == len(new_groups) old_groups[index] = group if check_ui: assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
def test_del_group(app): # Get list og existing groups groups_list = app.group_page.get_list() group_to_delete = Group(name="Modified Group") # Check if certain group exist in list if group_to_delete not in groups_list: app.group_page.create(group_to_delete) # if not then we create new group groups_list = app.group_page.get_list() # Find certain group in list group_to_delete_index = groups_list.index(group_to_delete) group_to_delete.id = groups_list[group_to_delete_index].id # Delete certain group from list app.group_page.delete(group_to_delete) # Assert result assert len(groups_list) - 1 == app.group_page.count() # additional assert for list length in case of exception # Get updated group list groups_list = app.group_page.get_list() assert group_to_delete not in groups_list # check for deleted element existed
def test_modify_group(app): # Get list of existing groups old_groups_list = app.group_page.get_list() group_to_modify = Group(name="test group") # Check if certain group exist in list if group_to_modify not in old_groups_list: app.group_page.create(group_to_modify) # if not then we create new group old_groups_list = app.group_page.get_list() # Find certain group in list modified_group_index = old_groups_list.index(group_to_modify) group_to_modify.id = old_groups_list[modified_group_index].id # Determinate fields to modify # group_modified = Group(name="Modified Group", footer="Modified footer", header="Modified header") group_modified = Group(name="Modified Group", _id=group_to_modify.id) # at least name # Modify group in WEB app.group_page.edit(group_to_modify, group_modified) # Assert result assert len(old_groups_list) == app.group_page.count() # additional assert for list length in case of exception # Get updated group list new_groups_list = app.group_page.get_list() # Change modified group in old list old_groups_list[modified_group_index] = group_modified assert sorted(old_groups_list, key=Group.id_or_max) == sorted(new_groups_list, key=Group.id_or_max)