def seedGroup(self): group = Group.query.first() if not group: group = Group(name="Nigeria Division") stat = group.save() # current_app.logger.info(f'seeding Group {group.name}') # attach user to Nigeria division group user = User.query.filter_by(name='Angela Prisca').first() user_group = UserGroup(group_id=group.id, user_id= user.id) user_group.save() # current_app.logger.info(f'seeding UserGroup:: \ # group id: {user_group.id}:user id: {user_group.user_id}') # attach user to Nigeria division group user = User.query.filter_by(name='Jack Robison').first() user_group = UserGroup(group_id=group.id, user_id= user.id) user_group.save() # current_app.logger.info(f'seeding UserGroup:: \ # group id: {user_group.id}:user id: {user_group.user_id}') group = Group(name="London Division") stat = group.save() # current_app.logger.info(f'seeding Group {group.name}') group = Group(name="Rider Group") stat = group.save() # current_app.logger.info(f'seeding Group {group.name}') # attach user to Rider group user = User.query.filter_by(name='John Richard').first() user_group = UserGroup(group_id=group.id, user_id= user.id) user_group.save() # current_app.logger.info(f'seeding UserGroup:: \ # group id: {user_group.id}:user id: {user_group.user_id}')
def fill_groups(): shelf = get_db() floor6 = Group(101, 'Mediapark - 6th floor (25)') partners = Group(102, 'Mediapark HCK (101)') if str(floor6.id) in shelf: return shelf[str(floor6.id)] = floor6 shelf[str(partners.id)] = partners teardown_db("Unexpected error occured")
def test_delete_random_contact_from_random_group(app, db, check_ui, orm): if len(db.get_group_list()) == 0: app.group.open_groups_page() app.group.creation(Group(name="group1", header="skip", footer="skip")) app.open_homepage() if len(db.get_contact_list()) == 0: app.contact.open_contact_page() app.contact.filling_contact_form( Contact(firstname='qwer', middlename='qwer', lastname='wert', nickname='asd', title='fsdf', company='fsd', address='dfsdf', homephone='45345', mobilephone='2312', workphone='2342', fax='23213', email='*****@*****.**', email2='*****@*****.**', email3='*****@*****.**', homepage='sfsdfs.sdf', byear='1900', ayear='2000', address2='sdfsdfsd', secondaryphone='233534', notes='dfsdf')) group = random.choice(db.get_group_list()) app.contact.select_group(group) app.contact.submit_contact_creation() app.open_homepage() if len(db.get_contacts_in_groups()) == 0: contact1 = random.choice(db.get_contact_list()) group1 = random.choice(db.get_group_list()) app.contact.select_by_id(contact1) app.contact.move_to_group_by_group_id(group1) app.open_homepage() group2 = Group(id=random.choice(db.get_contacts_in_groups()).group) old_contacts = orm.get_contacts_in_group(group2) contact2 = random.choice(old_contacts) app.contact.delete_by_id(contact2.id) app.open_homepage() #assert len(old_contacts) - 1 == app.contact.count() new_contacts = orm.get_contacts_in_group(group2) old_contacts.remove(contact2) assert old_contacts == new_contacts if check_ui: assert sorted(new_contacts, key=Contact.id_or_max) == sorted( app.contact.get_contact_list(), key=Contact.id_or_max)
def test_edit_group_name(app, db, check_ui): app.group.open_groups_page() if len(db.get_group_list()) == 0: app.group.creation(Group(name="group1", header="skip", footer="skip")) app.group.return_to_groups_page() old_groups = db.get_group_list() group = random.choice(old_groups) group.name = "qqwerty1234" index = old_groups.index(group) app.group.edit_group_by_id(group.id, group) app.group.return_to_groups_page() #assert len(old_groups) == app.group.count() new_groups = db.get_group_list() old_groups[index] = group assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max) if check_ui: assert sorted(new_groups, key=Group.id_or_max) == sorted(app.group.get_group_list(), key=Group.id_or_max) app.open_homepage() #def test_edit_group_header(app): # app.group.open_groups_page() # if app.group.count() == 0: # app.group.creation(Group(name="group1", header="skip", footer="skip")) # app.group.return_to_groups_page() #old_groups = app.group.get_group_list() #app.group.edit_first_group(Group(header ="New header")) #app.group.return_to_groups_page() #new_groups = app.group.get_group_list() #assert len(old_groups) == len(new_groups) #app.open_homepage()
def get_groups(self): group_result = querry_database('SELECT * FROM Groupings') groups = [] for grp in group_result: group = Group(grp) groups.append(group) return groups
def get_group_list(self): if self.group_cache is None: wd = self.app.wd 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 init_group(row): group = Group() group.id = row['id'] group.uid = row['uid'] group.group_name = row['group_name'] group.update_date = row['update_date'] group.is_deleted = row['is_deleted'] return group
def main(): group = Group() while True: print( '\n\nselect action:\n' + \ '[0] - insert person\n' + \ '[1] - view group collection\n' + \ '[2] - view min & max age of person from category\n' + \ '[3] - add subordinate to the person\n' + \ '[4] - view subordinates of the person\n' + \ '[5] - save current group collection to the file\n' + \ '[6] - exit\n' ) choise = make_choise(7) if choise == 0: input_person(group) elif choise == 1: group.get_all() elif choise == 2: view_age(group) elif choise == 3: add_subordinate(group) elif choise == 4: view_subordinates(group) elif choise == 5: serializer = Serializer() serializer.serialize(group.collection) print('collection saved successfully\n') else: break
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=str(id), name=name, header=header, footer=footer)) finally: cursor.close() return list
def test_delete_random_group(app, db, check_ui): app.group.open_groups_page() if len(db.get_group_list()) == 0: app.group.creation(Group(name="group1", header="skip", footer="skip")) app.group.return_to_groups_page() old_groups = db.get_group_list() group = random.choice(old_groups) app.group.delete_group_by_id(group.id) app.group.return_to_groups_page() #assert len(old_groups) - 1 == app.group.count() new_groups = db.get_group_list() 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) app.open_homepage()
def create_group(self): """ validate data and creates a new Group """ name = self.window.ed_group_name.text() order = self.window.ed_group_order.text() errors = validate_data(name=name, order=order) if errors: self.show_errors(errors) else: # there are no errors, then the group is create try: group = Group(name=name, order=order, competence_id=self.competence.id) db.session.add(group) db.session.commit() self.clear_fields() self.clear_errors() self.load_groups_competence() except Exception as e: print(f'Error creating group') print(e)
def create_group(): if not load_user(current_user.get_id()): return abort(401, description="Unauthorised to view this page") profile = Profile.query.filter_by( profile_id=request.args["profile_id"]).first() form = CreateGroup() if form.validate_on_submit(): new_group = Group( name=form.name.data, description=form.description.data, ) GroupMembers(groups=new_group, profile_id=profile.profile_id, admin=True) db.session.add(new_group) db.session.commit() return redirect( url_for("web_groups.show_groups", profile_id=profile.profile_id)) return render_template("create_group.html", form=form, profile=profile)
def parse_get_group_name_list_mask2(self, result): gmarklist = result["gmarklist"] gmasklist = result["gmasklist"] gnamelist = result["gnamelist"] ret_groups = {} # parse gmarklist 似乎没有没使用 # parse gmasklist [群屏蔽] 暂时没写,我的qq获取没数据 # parse gnamelist for i in range(0, len(gnamelist)): group_obj = Group() group_obj.flag = gnamelist[i]["flag"] group_obj.name = gnamelist[i]["name"] group_obj.gid = gnamelist[i]["gid"] group_obj.code = gnamelist[i]["code"] ret_groups[group_obj.gid] = group_obj return ret_groups
except getopt.GetoptError as err: # print help information and exit: print(str(err)) # will print something like "option -a not recognized" 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 + string.punctuation + " "*10 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 out: jsonpickle.set_encoder_options('json', indent=2) out.write(jsonpickle.encode(testdata))
def addGroupsPagePost(): group = Group(request.form["name"]) db.session.add(group) db.session.commit() groups = Group.query.all() return render_template("groups.html", type="add", groups=groups)
from core.Database import Database from models.Group import Group import json, time db = Database() group = Group() class Groups(): def __init__(self): pass def get_group(self, id, req_url): result = db.get_group_db(id, req_url) return result def get_all_groups(self, req_url, start_index, count): result = db.get_all_groups_db(req_url, start_index, count) return result def get_filtered_groups(self, attribute_name, attribute_value, req_url, start_index, count): result = db.get_filtered_groups_db(attribute_name, attribute_value, req_url, start_index, count) return result def create_group(self, group_data_json, req_url):
def seed_db(): from models.Profile import Profile from models.User import User from models.Group import Group from models.Content import Content from models.Group_members import GroupMembers from models.Admin import Admin from main import bcrypt import random from faker import Faker faker = Faker() users = [] contents = [] profile_ids = list(range(1, 11)) random.shuffle(profile_ids) admins = [] for i in range(1, 6): user = User() user.email = f"test{i}@test.com" user.password = bcrypt.generate_password_hash("123456").decode("utf-8") user.subscription_status = random.choice([0, 1]) db.session.add(user) users.append(user) db.session.commit() print("User table seeded") for i in range(30): content = Content() content.title = faker.sentence() content.genre = faker.word() content.year = faker.year() db.session.add(content) contents.append(content) db.session.commit() print("Content table seeded") for i in range(10): content = random.sample(contents, k=2) restrictions = ("G", "PG", "M", "MA15+", "R18+") profile = Profile() profile.name = faker.first_name_nonbinary() profile.restrictions = random.choice(restrictions) profile.user_id = random.choice(users).user_id profile.unrecommend.extend(content) db.session.add(profile) db.session.commit() print("Profile table seeded") for i in range(10): content = random.sample(contents, k=3) group = Group() group.name = faker.word() group.description = faker.text() group.content.extend(content) admin = GroupMembers() admin.groups = group admin.profile_id = profile_ids.pop(0) admin.admin = True member_ids = [i for i in range(1, 11) if i != admin.profile_id] random.shuffle(member_ids) for i in range(2): member = GroupMembers() member.groups = group member.profile_id = member_ids.pop() member.admin = False db.session.add(group) db.session.commit() print("Group table seeded") for i in range(1, 3): admin = Admin() admin.username = f"Admin{i}" admin.password = bcrypt.generate_password_hash("654321").decode( "utf-8") db.session.add(admin) admins.append(admin) db.session.commit() print("Admin table seeded")
from models.Group import Group testdata = [ Group(name="name1", header="header1", footer="footer1"), Group(name="name2", header="header2", footer="footer2") ]
def clean(group): return Group(id=group.id, name=group.name.strip())
from fixtures.orm import ORMFixture from models.Group import Group db = ORMFixture(host='127.0.0.1', port=8889, name='addressbook', user='******', password='******') try: l = db.get_contacts_in_group(Group(id='357')) for item in l: print(item) print(len(l)) finally: pass #db.destroy()
def new_group(name, header, footer): return Group(name=name, header=header, footer=footer)
def convert(group): return Group(id=str(group.id), name=group.name, header=group.header, footer=group.footer)
def non_empty_group_list(db, app): if len(db.get_group_list()) == 0: app.group.open_groups_page() app.group.creation(Group(name="group1", header="skip", footer="skip")) app.group.return_to_groups_page() return db.get_group_list()
def add_group(self, **kwargs): group = Group(name=kwargs["name"]) self.db.session.add(group) self.db.session.commit()