def test_edit_group_name(app, db, check_ui): if app.group.count_groups() == 0: app.group.create(Group(_name="for_edit_test", _header="", _footer="")) # получаем список групп с БД old_groups = db.get_group_list() # выбираем из списка случайную группу group = random.choice(old_groups) # задаем новые данные для группы new_group_data = Group(_name="name_group_edit_test", _header="header_group_edit_test", _footer="footer_group_edit_test") # модифицируем группу app.group.edit_group_by_id(group.group_id, new_group_data) # получаем новый список групп new_groups = db.get_group_list() # ищем отредактированную группу по id new_group = next(x for x in new_groups if x.group_id == group.group_id) # в старом списке удаляем старую группу old_groups.remove(group) # на его место добавляем новую отредактированную old_groups.append(new_group) # сравниваем длины старого и нового списков assert len(old_groups) == len(new_groups) if check_ui: assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
def get_group_list(self): if self.group_cache is None: wd = self.app.wd self.open_groups_page() self.group_cache = [] for element in wd.find_elements_by_css_selector("span.group"): text = element.text group_id = element.find_element_by_name( "selected[]").get_attribute("value") self.group_cache.append(Group(_name=text, _id=group_id)) return list(self.group_cache)
def test_delete_some_group(app, db, check_ui): if len(db.get_group_list()) == 0: app.group.create(Group(_name="for_delete_test", _header="for_delete_test", _footer="for_delete_test")) old_groups = db.get_group_list() group = random.choice(old_groups) app.group.delete_group_by_id(group.group_id) new_groups = db.get_group_list() assert len(old_groups) - 1 == len(new_groups) old_groups.remove(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 get_group_list(self): group_list = [] cursor = self.connection.cursor() try: cursor.execute( "select group_id, group_name, group_header, group_footer from group_list" ) for row in cursor: (group_id, name, header, footer) = row group_list.append( Group(_id=str(group_id), _name=name, _header=header, _footer=footer)) finally: cursor.close() return group_list
import random import string from Models.group_class import Group test_data = [ Group(_name="name_constant", _header="header_constant", _footer="footer_constant"), Group(_name="name_constant_2", _header="header_constant_2", _footer="footer_constant_2") ] # def random_string(prefix, maxlen): # symbols = string.ascii_letters + string.digits + " " * 10 # + string.punctuation # return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))]) # # # test_data_for_group = [Group(_name="", _header="", _footer="")] + \ # [Group(_name=random_string("group_name", 10), # _header=random_string("group_name", 20), # _footer=random_string("group_name", 20)) for i in range(1)] # test_data_for_group = [Group(_name=name, _header=header, _footer=footer) # for name in ["", random_string("group_name", 10)] # for header in ["", random_string("group_name", 20)] # for footer in ["", random_string("group_name", 20)]]
except getopt.GetoptError as err: getopt.usage() sys.exit(2) n = 2 f = "data/groups.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 return prefix + "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) test_data_for_group = [Group(_name="", _header="", _footer="")] + \ [Group(_name=random_string("group_name", 10), _header=random_string("group_name", 20), _footer=random_string("group_name", 20)) for i in range(n)] group_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f) with open(group_file, "w") as out_file: jsonpickle.set_encoder_options("json", indent=2) out_file.write(jsonpickle.encode(test_data_for_group))
def convert(group): return Group(_id=str(group.group_id), _name=group.name, _header=group.header, _footer=group.footer)
import pymysql.cursors #from Fixtures.db import DbFixture from Fixtures.orm import ORMFixture from Models.group_class import Group db = ORMFixture(host_value="127.0.0.1", name_value="addressbook", user_value="root", password_value="") try: contact_list = db.get_contacts_in_group(Group(_id="233")) for item in contact_list: print(item) print(len(contact_list)) finally: pass # try: # contact_list = db.get_contact_list() # for item in contact_list: # print(item) # print(len(contact_list)) # # finally: # pass # try: # group_list = db.get_group_list() # for item in group_list:
def clean(group): return Group(_id=group.group_id, _name=group.name.strip())