def test_modify_some_group_name(app, db): if len(db.get_group_list()) == 0: app.group.create(Group(name="test")) old_groups = db.get_group_list() # выбираем случайную группу, которую будем редактировать group = random.choice(old_groups) # подготавливаем новые данные с id группы, которую будем редактировать new_data = Group(id=group.id, name="new name") # перезаписываем группу с использованием старого id app.group.modify_group_by_id(group.id, new_data) new_groups = db.get_group_list() assert len(old_groups) == len(new_groups) old_groups.remove(group) old_groups.append(new_data) 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 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 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 # делаем приведение типов для id, т.к. в БД id это int, а из web читаем как str list.append( Group(id=str(id), name=name, header=header, footer=footer)) finally: cursor.close() return list
def test_add_contact_to_group(app, db): if len(db.get_group_list()) == 0: app.group.create(Group(name="test")) group_list = db.get_group_list() rand_group = random.choice(group_list) def generate_new_contact_id(): id_list = db.get_all_contact_id_list() new_id = max(id_list) + 1 return str(new_id) new_contact = Contact(id=generate_new_contact_id(), lastname="lll8", firstname="fff") app.open_home_page() app.contact.create_contact(new_contact, add_to_group=rand_group) orm = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") contacts_in_group = orm.get_contacts_in_group(rand_group) assert new_contact in contacts_in_group
getopt.usage() sys.exit(2) n = 5 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 return prefix + "".join( [random.choice(symbols) for i in range(random.randrange(maxlen))]) testdata = [Group(name="", header="", footer="")] + [ Group(name=random_string("name", 10), header=random_string("header", 10), footer=random_string("footer", 10)) for i in range(n) ] file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f) with open(file, "w") as f: jsonpickle.set_encoder_options("json", indent=2) f.write(jsonpickle.encode(testdata))
from python_lessons.model.group import Group testdata = [ Group(name="name1", header="header1", footer="footer1"), Group(name="name2", header="header2", footer="footer2") ]
def convert(group): return Group(id=str(group.id), name=group.name, header=group.header, footer=group.footer)
from python_lessons.fixture.orm import ORMFixture from python_lessons.model.group import Group db = ORMFixture(host="127.0.0.1", name="addressbook", user="******", password="") try: l = db.get_contacts_not_in_group(Group(id='337')) for item in l: print(item) print(len(l)) finally: pass # db.destroy()
def clean(group): return Group(id=group.id, name=group.name.strip())