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
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
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)
def create_customer(customer): return backend._exec("""INSERT INTO customers(`name`) VALUES(%s)""", customer.get('name'))
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'))
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'])
def delete_assignee(username, customer_id): sql ="""DELETE FROM `assignees` WHERE `user` = %s AND customer = %s;""" return backend._exec(sql, username, customer_id)
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'))
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))
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)
def delete(id, installation): return backend._exec("""DELETE FROM sync_queue WHERE id = ? AND installation = ?""", id, installation)
def delete_current(name, ip): return backend._exec("""DELETE FROM sync_queue WHERE data LIKE ? AND data LIKE ?""", '%' + name + '%', '%' + ip + '%')
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'))
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)
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'))
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
def set_attempt_time(id, installation): return backend._exec("UPDATE sync_queue SET last_sync_attempt = datetime('now') WHERE id = ? AND installation = ?", id, installation)
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
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'))
def delete_cookie(username): sql = "UPDATE users SET cookie_id = NULL, cookie_expire = NULL WHERE username = %s" return backend._exec(sql, username)
def register(installation): return backend._exec("""INSERT INTO installations(`serial_number`, `model`, `name`) VALUES(%s, %s, %s);""", installation['serial_number'], installation['model'], installation['name'])
def create_assignee(username, customer_id): return backend._exec("""INSERT INTO assignees(`user`, `customer`) VALUES(%s, %s);""", username, customer_id)
def setUpClass(self): backend._exec("DELETE FROM new_alarms") backend._exec("DELETE FROM new_settings")
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'])
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'])
def update(customer): sql = """UPDATE customers SET `name` = %s WHERE `id` = %s;""" return backend._exec(sql, customer.get('name'), customer.get('id'))
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
def delete(serial_number): return backend._exec("""DELETE FROM installations WHERE `serial_number` = %s;""", serial_number)
def delete_user(username): sql = """DELETE FROM users WHERE username = %s""" if not backend._exec(sql, username) == 1: raise ResourceNotFound("User not found")
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'))
def delete_customer(customer_id): sql ="""DELETE FROM customers WHERE `id` = %s""" return backend._exec(sql, customer_id)