Пример #1
0
def create_user(user):
    sql = """INSERT INTO users (username, surname, name, phone, password, salt,  email, role) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"""
    created = backend._exec(sql, user.get('username'), user.get('surname'), user.get('name'), user.get('phone'), user.get('password'), user.get('salt'), user.get('email'), user.get('role'))
    if created:
        created = get_user(user.get('username'))
        print("CREATED USER: "******"Cannot create user")
    return created
Пример #2
0
    def test_015_test_receive_message_not_adding_new_sync_entry(self):
        backend._exec("""DROP TRIGGER IF EXISTS alarm_after_insert;""");
        backend._exec("""DROP TRIGGER IF EXISTS settings_after_update;""");
        config.LOCAL = False
        sync_entries = sync_queue_dao.get_all()
        self.assertEqual(3, len(sync_entries))
        new_alarms = NewAlarmsDao.get_all()
        self.assertEqual(0, len(new_alarms))
        new_settings = NewSettingsDao.get_all()
        self.assertEqual(0, len(new_settings))

        sql = """DELETE FROM alarms"""
        backend._exec(sql)
        SyncManager.onMessage(testData.ALARM_CREATE)
        SyncManager.onMessage(testData.SETTING_UPDATE)

        new_alarms = NewAlarmsDao.get_all()
        self.assertEqual(0, len(new_alarms))
        new_settings = NewSettingsDao.get_all()
        self.assertEqual(0, len(new_settings))
        sync_entries = sync_queue_dao.get_all()
        self.assertEqual(3, len(sync_entries))

        pass
Пример #3
0
def delete_controller(serial_number, controller_ip):
    sql = """DELETE FROM controllers WHERE installation = %s AND ip = %s"""
    return backend._exec(sql, serial_number, controller_ip)
Пример #4
0
def create_customer(customer):
    return backend._exec("""INSERT INTO customers(`name`) VALUES(%s)""",
                        customer.get('name'))
Пример #5
0
def create_controller(controller):
    return backend._exec(
        """INSERT INTO controllers(`installation`, `ip`, `name`) VALUES(%s, %s, %s)""",
        controller.get('installation'), controller.get('ip'),
        controller.get('name'))
Пример #6
0
def create_log_entry(entry, installation):
    return backend._exec("""INSERT INTO log(`name`, `value`, `time`, `address`, `type`, `installation`, `controller_ip`) VALUES(%s,%s,%s,%s,%s,%s,%s)""", entry['name'], entry['value'], entry['time'], entry['address'], entry['type'], installation, entry['controller_ip'])
Пример #7
0
def delete_assignee(username, customer_id):
    sql ="""DELETE FROM `assignees` WHERE `user` = %s AND customer = %s;"""
    return backend._exec(sql, username, customer_id)
Пример #8
0
def update_controller(controller):
    sql = """UPDATE controllers SET name = %s WHERE ip = %s AND installation = %s"""
    return backend._exec(sql, controller.get('name'), controller.get('ip'),
                         controller.get('installation'))
Пример #9
0
def insert(sync):
    return backend._exec("""INSERT INTO sync_queue(`installation`, `method`, `table`, `data`, `prev`) VALUES(?,?,?,?,?)""", sync['installation'], sync['method'], sync['table'], json.dumps(sync['data'], default=simple_encoder), json.dumps(sync['prev'], default=simple_encoder))
Пример #10
0
def update_cookie_id(cookie_id, expire, username):
    sql = """UPDATE users SET cookie_id = %s, cookie_expire = %s WHERE username = %s"""
    return backend._exec(sql, cookie_id, expire, username)
Пример #11
0
def delete(id, installation):
    return backend._exec("""DELETE FROM sync_queue WHERE id = ? AND installation = ?""", id, installation)
Пример #12
0
def delete_current(name, ip):
    return backend._exec("""DELETE FROM sync_queue WHERE data LIKE ? AND data LIKE ?""", '%' + name + '%', '%' + ip + '%')
Пример #13
0
def create_tag(tag):
    return backend._exec("""INSERT INTO tags(`installation`, `controller_ip`, `name`, `address`, `type`) VALUES(%s, %s, %s, %s, %s)""",
                         tag.get('installation'), tag.get('controller_ip'), tag.get('name'), tag.get('address'), tag.get('type'))
Пример #14
0
def delete_tag(serial_number, controller_ip, name):
    sql = """DELETE FROM tags WHERE `installation` = %s AND `controller_ip` = %s AND `name` = %s"""
    return backend._exec(sql, serial_number, controller_ip, name)
Пример #15
0
def update_tag(tag):
    sql = """UPDATE tags SET `address` = %s, `type` = %s WHERE `name` = %s AND `installation` = %s AND `controller_ip` = %s"""
    return backend._exec(sql, tag.get('address'), tag.get('type'), tag.get('name'), tag.get('installation'), tag.get('controller_ip'))
Пример #16
0
def update_user_with_pw_and_salt(u):
    sql = """UPDATE users SET name = %s, surname = %s, phone = %s, email=%s, password = %s,  salt = %s, lang = %s, role = %s  WHERE username = %s"""
    updated = backend._exec(sql, u['name'], u['surname'], u['phone'], u['email'], u['password'], u['salt'], u['lang'], u['role'], u['username'])
    return u if updated else False
Пример #17
0
def set_attempt_time(id, installation):
    return backend._exec("UPDATE sync_queue SET last_sync_attempt = datetime('now') WHERE id = ? AND installation = ?", id, installation)
Пример #18
0
def update_user(u):
    sql = """UPDATE users SET name = %s, surname = %s, phone = %s, email=%s, lang = %s, role = %s WHERE username = %s"""
    updated = backend._exec(sql, u['name'], u['surname'], u['phone'], u['email'], u['lang'], u['role'], u['username'])
    return u if updated else False
Пример #19
0
def update(installation):
    sql = """UPDATE installations SET `name`= %s, `model` = %s, `customer` = %s WHERE `serial_number` = %s;"""
    return backend._exec(sql, installation.get('name'), installation.get('model'), installation.get('customer'), installation.get('serial_number'))
Пример #20
0
def delete_cookie(username):
    sql = "UPDATE users SET cookie_id = NULL, cookie_expire = NULL WHERE username = %s"
    return backend._exec(sql, username)
Пример #21
0
def register(installation):
     return backend._exec("""INSERT INTO installations(`serial_number`, `model`, `name`) VALUES(%s, %s, %s);""", installation['serial_number'], installation['model'], installation['name'])
Пример #22
0
def create_assignee(username, customer_id):
    return backend._exec("""INSERT INTO assignees(`user`, `customer`) VALUES(%s, %s);""",
                         username, customer_id)
Пример #23
0
 def setUpClass(self):
     backend._exec("DELETE FROM new_alarms")
     backend._exec("DELETE FROM new_settings")
Пример #24
0
def delete_controller(serial_number, controller_ip):
    sql = """DELETE FROM controllers WHERE installation = %s AND ip = %s"""
    return backend._exec(sql, serial_number, controller_ip)
Пример #25
0
def create_setting_with(setting_type, installation):
    return backend._exec("""INSERT INTO settings(`installation`, `setting_name`, `value`) VALUES(%s, %s, %s)""", installation['serial_number'], setting_type['setting_name'], setting_type['default_value'])
Пример #26
0
def create(installation):
     return backend._exec("""INSERT INTO installations(`serial_number`, `model`, `name`, `customer`) VALUES(%s, %s, %s, %s);""", installation['serial_number'], installation['model'], installation['name'], installation['customer'])
Пример #27
0
def update(customer):
    sql = """UPDATE customers SET `name` = %s WHERE `id` = %s;"""
    return backend._exec(sql, customer.get('name'), customer.get('id'))
Пример #28
0
def update_setting(setting, installation):
    sql = """UPDATE settings SET value = %s WHERE setting_name = %s AND installation = %s"""
    res = backend._exec(sql, setting.get('value'), setting.get('setting_name'), installation)
    return res
Пример #29
0
def delete(serial_number):
    return backend._exec("""DELETE FROM installations WHERE `serial_number` = %s;""", serial_number)
Пример #30
0
def update_controller(controller):
    sql = """UPDATE controllers SET name = %s WHERE ip = %s AND installation = %s"""
    return backend._exec(sql, controller.get('name'), controller.get('ip'), controller.get('installation'))
Пример #31
0
def delete_user(username):
    sql = """DELETE FROM users WHERE username = %s"""
    if not backend._exec(sql, username) == 1:
        raise ResourceNotFound("User not found")
Пример #32
0
def create_controller(controller):
    return backend._exec("""INSERT INTO controllers(`installation`, `ip`, `name`) VALUES(%s, %s, %s)""",
                         controller.get('installation'), controller.get('ip'), controller.get('name'))
Пример #33
0
def delete_customer(customer_id):
    sql ="""DELETE FROM customers WHERE `id` = %s"""
    return backend._exec(sql, customer_id)