コード例 #1
0
 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)
コード例 #2
0
def test_delete_some_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    app.group.delete_group_by_id(group.id)
    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)
コード例 #3
0
 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
コード例 #4
0
 def get_groups_with_contacts(self):
     list = []
     cursor = self.connection.cursor()
     try:
         cursor.execute(
             "select group_id, group_name, group_header, group_footer from group_list "
             "where group_id in (select group_id from address_in_groups)")
         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
コード例 #5
0
def test_del_contact_in_group(app, db):
    if len(db.get_contact_list()) == 0:
        app.contact.create(Contact(firstname="Vlad", lastname="hater"))
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test"))
    groups = db.get_groups_with_contacts()
    group = random.choice(groups)
    group_id = group.id
    contacts = db.get_contacts_in_group()
    contact = random.choice(contacts)
    contact_id = contact.id
    if len(db.get_contacts_in_group()) == 0:
        app.contact.add_contact_to_group(contact_id, group_id)
    old_contacts = db.get_contacts_in_group()
    app.contact.del_contact_in_group(contact_id, group_id)
    new_contacts = db.get_contacts_in_group()
    assert len(old_contacts) - 1 == len(new_contacts)
コード例 #6
0
def test_add_contact_in_group(app, db, check_ui):
    if len(db.get_contact_list()) == 0:
        app.contact.create(Contact(firstname="Vlad", lastname="hater"))
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test"))
    if len(db.get_contacts_not_in_group()) == 0:
        app.contact.create(Contact(firstname="Vlad", lastname="hater"))
    group = app.group.get_group_list()
    groups = random.choice(group)
    group_id = groups.id
    contacts = db.get_contacts_not_in_group()
    contact = random.choice(contacts)
    contact_id = contact.id
    print(db.get_contacts_in_group())
    old_contact = db.get_contacts_in_group()
    app.contact.add_contact_to_group(contact_id, group_id)
    new_contacts = db.get_contacts_in_group()
    assert len(old_contact) + 1 == len(new_contacts)
    contact_ui = db.get_contacts_in_group()
    if check_ui:
        assert sorted(contact_ui, key=Contact.id_or_max) == sorted(
            app.group.get_group_list(), key=Contact.id_or_max)
コード例 #7
0
ファイル: run.py プロジェクト: schopr9/flask-ubuntu
def group_new():
    """create group"""
    raw_dict = request.get_json(force=True)
    try:
        group_schema.validate(raw_dict)
        group_dict = raw_dict['data']['attributes']
        group = Group(group_dict['name'])
        group.add(group)
        query = Group.query.filter_by(name=group_dict['name']).first()
        results = group_schema.dump(query).data
        print results
        return jsonify({"id": query.id})

    except ValidationError as err:

        resp = jsonify({"error": err.messages})
        resp.status_code = 403
        return resp

    except SQLAlchemyError as e:
        db.session.rollback()
        resp = jsonify({"error": str(e)})
        resp.status_code = 403
        return resp
コード例 #8
0
 def convert(group):
     return Group(id=str(group.id),
                  name=group.name,
                  header=group.header,
                  footer=group.footer)
コード例 #9
0
 def clean(group):
     return Group(id=group.id, name=group.name.strip())
コード例 #10
0
from model.models import Group

testdata = [
    Group(name="name1", header="header1", footer="footer1"),
    Group(name="name2", header="header2", footer="footer2")
]
コード例 #11
0
    opts, args = getopt.getopt(sys.argv[1:], "n:f:", ["Number_of_groups", "file"])
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 + string.punctuation + " "*10
    return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))])


testdata = [
    Group(name=random_string("name", 10), header=random_string("header", 20), footer=random_string("footer", 20))
    for i in range(6)
]

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))
コード例 #12
0
def non_empty_group_list(db, app):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="new name"))
    return db.get_group_list()
コード例 #13
0
def new_group(name, header, footer):
    return Group(name=name, header=header, footer=footer)