Ejemplo n.º 1
0
def test_mod_group(app):
    if app.group.count() == 0:
        app.group.add(Group("Group 02", "Group 02 footer"))
    old_groups = app.group.get_group_list()
    index = randrange(len(old_groups))
    group = Group(group_name="Modified")
    group.id = old_groups[index].id
    app.group.modify_group_by_index(group, index)
    new_groups = app.group.get_group_list()
    old_groups[index] = group
    assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
Ejemplo n.º 2
0
def test_remove_contact_from_group(app, orm):
    group_list = orm.get_group_list()
    # Предусловие
    if len(group_list) == 0:
        app.group.create(
            Group(name='GroupToRmContqct', footer='Frooter', header='Header'))
        group_list = app.orm.get_group_list()
    # Ищем группу в которой есть контакты, либо делаем такую
    for i in range(len(group_list)):
        contacts_in_group = orm.get_contacts_in_group(group_list[i])
        if len(contacts_in_group) > 0:
            target_group = group_list[i]
            break
        else:
            # Нужно добавить в группу контакт
            contact_list_raw = orm.get_contact_list()
            contact_list = orm.convert_contacts_to_model(contact_list_raw)
            # Проверяем что есть контакт для добавления иначе создаем
            if len(contact_list) == 0:
                app.contact.create_random_contact()
                contact_list = orm.get_contact_list()
            # Добавляем случайный контакт в случайную группу
            random_contact_index = random.randint(0, len(contact_list))
            random_group = group_list[random.randint(0, group_list)]
            app.contact.add_to_group(random_contact_index, random_group)
    random_group = random.choice(group_list)
    removed_contact = app.contact.remove_contact_from_group(random_group)
    assert removed_contact in orm.get_contacts_not_in_group(random_group)
Ejemplo n.º 3
0
 def get_group_list(self):
     lst = []
     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
             lst.append(Group(id=str(id), name=name, header=header, footer=footer))
     finally:
         cursor.close()
     return lst
Ejemplo n.º 4
0
 def get_group_list(self):
     if self.group_cache is None:
         wd = self.app.wd
         self.open_group_page()
         self.group_cache = []
         for g in wd.find_elements_by_css_selector('.group'):
             name = g.text
             group_id = g.find_element_by_tag_name('input').get_attribute(
                 'value')
             self.group_cache.append(Group(name=name, id=group_id))
     return list(self.group_cache)
def test_edit_group_data(app):
    before = app.group.get_group_list()
    random_group = random.randint(0, len(before) - 1)
    app.group.edit_data_by_index(
        random_group,
        Group(name='Test' + str(random.randint(1, 100)),
              header='New',
              footer='FooterNew'))
    assert len(before) == app.group.count()
    after = app.group.get_group_list()
    assert before != after, 'Список групп не изменился после редактирования данных группы'
Ejemplo n.º 6
0
def test_delete_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name='Test', header='Header', footer='Footer'))
    before = db.get_group_list()
    group = random.choice(before)
    app.group.delete_by_id(group.id)
    assert (len(before) - 1) == app.group.count()
    after = db.get_group_list()
    assert sorted(before, key=Group.id_or_max) != sorted(after,
                                                         key=Group.id_or_max)
    if check_ui:
        assert sorted(after, key=Group.id_or_max) == sorted(
            app.group.get_group_list(), key=Group.id_or_max)
Ejemplo n.º 7
0
 def get_group_list(self):
     list = []
     self.connection.commit()
     cursor = self.connection.cursor()
     try:
         cursor.execute(
             "select group_id, group_name, group_footer from group_list")
         for row in cursor:
             (id, name, footer) = row
             list.append(
                 Group(id=str(id), group_name=name, group_footer=footer))
     finally:
         cursor.close()
     return list
def test_add_contact_to_group(app, orm):
    # Получаем первичную информацию
    group_list = app.orm.get_group_list()
    contact_list = app.orm.get_contact_list()
    # Предусловия
    if len(group_list) == 0:
        app.group.create(
            Group(name='GroupToAddContqct', footer='Frooter', header='Header'))
        group_list = app.orm.get_group_list()
    if len(contact_list) == 0:
        app.contact.create_random_contact()
        contact_list = app.orm.get_contact_list()
    # Добавляем случайный контакт в случайную группу
    random_contact_index = random.randint(0, len(contact_list))
    random_group = group_list[random.randint(0, group_list)]
    app.contact.add_to_group(random_contact_index, random_group)
    # Проверяем наличие контакта в группе куда мы его добавляли
    contacts_in_group = orm.get_contacts_in_group(random_group)
    assert contact_list[random_contact_index] in contacts_in_group
Ejemplo n.º 9
0
def get_group_in_deeper(session, graph, args=None):
    dargs = dict(args)
    groups = request_in_deeper(graph, 'search', dargs)

    for key, entity in groups.items():
        if not dedup.add(entity['id']):
            continue
        if not re.search(u'[\u4e00-\u9fff]', entity['name']):
            logging.info("skip due to no chinese word: %s", entity['name'])
            continue
        members = request_in_deeper(graph, '{}/members'.format(entity['id']), {'limit': 1000})
        entity['members'] = len(members)

        dataIn = Group()
        dataIn.id = entity['id']
        dataIn.name = entity['name']
        dataIn.privacy = entity['privacy']
        dataIn.members = entity['members']

        if not session.query(Group).filter_by(id=entity['id']).scalar():
            session.add(dataIn)
            session.commit()
Ejemplo n.º 10
0
 def convert_group(group):
     return Group(id=str(group.id), name=group.name, header=group.header, footer=group.footer)
def clean(group):
    return Group(id=group.id,
                 group_name=group.group_name.strip(),
                 group_footer=group.group_footer.strip())
Ejemplo n.º 12
0
import string
import random
from model.data import Group


testdata = [
    Group(name='groupname1', header='groupheader1', footer='groupfooter1'),
    Group(name='groupname2', header='groupheader2', footer='groupfooter2')
]


# def random_string(prefix, max_len):
#     symbols = string.ascii_letters + string.digits + " " * 10
#     return prefix + ''.join([random.choice(symbols) for i in range(random.randrange(max_len))])
#
#
# testdata = [Group('', '', '')] + [
#     Group(name=random_string('name', 10), header=random_string('header', 10), footer=random_string('footer', 10))
#     for i in range(5)
# ]
 def clean_group(group):
     return Group(id=group.id, name=group.name.strip())
Ejemplo n.º 14
0
from model.data import Group

testdata = [
    Group(group_name="name1", group_footer="footer1"),
    Group(group_name="name2", group_footer="footer2")
]
Ejemplo n.º 15
0
    getopt.usage()
    sys.exit(2)

n = 5
f_name = 'data/groups.json'

for opt, val in opts:
    if opt == '-n':
        n = int(val)
    elif opt == '-f':
        f = val


def random_string(prefix, max_len):
    symbols = string.ascii_letters + string.digits + " " * 10
    return prefix + ''.join(
        [random.choice(symbols) for i in range(random.randrange(max_len))])


testdata = [Group('', '', '')] + [
    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_name)

with open(file, 'w') as f:
    jsonpickle.set_encoder_options('json', indent=2)
    f.write(jsonpickle.encode(testdata))
Ejemplo n.º 16
0
except:
    getopt.usage()
    sys.exit(2)

n = 1
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(group_name="", group_footer="")] + [
    Group(group_name=random_string("name", 10), group_footer=random_string("footer", 15))
    for i in range(n)
]

testdata1 = [Group(group_name=random_string("name", 10), group_footer=random_string("footer", 15)) 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(testdata1))