def test_g_agrega_ip_a_red_existente(self): data = {"dns1": "5.5.5.5", "dns2": "5.5.5.5", "nombre": "test"} data2 = { "dns1": "10.10.10.10", "dns2": "10.10.10.10", "nombre": "test" } self.assertEqual(IPContainer.addIPtoNetwork("test_user1", "dns", data), True, "IP agregada 1 a la red existente correctamente") self.assertEqual( IPContainer.addIPtoNetwork("test_user1", "dns", data2), True, "IP agregada 2 a la red existente correctamente")
def addAPIUser(current_user): if current_user._admin: data = request.get_json() done = IPContainer.addAPIUser(data['username'], data['password']) return jsonify(success=done) return jsonify(message="You're not an admin.")
def login(): auth = request.authorization if not auth or not auth.username or not auth.password: return make_response( 'Could not verify.', 401, {'WWW-Authenticate': 'Basic realm="Login required."'}) return IPContainer.login(auth.username, auth.password)
def test_m_vaciar_tablas(self): IPContainer._dropUsers() self.assertEqual(IPContainer.getNumberOfUsers(), 0, "Tabla usuarios vaciada.") IPContainer._dropData() self.assertEqual(IPContainer.getNumberOfUsers(), 0, "Tabla datos vaciada.")
def test_b_agrega_usuarios(self): IPContainer.addUser("test_user1") self.assertEqual(IPContainer.existUser("test_user1"), True, "Usuario 1 agregado correctamente.") IPContainer.addUser("test_user2") self.assertEqual(IPContainer.existUser("test_user2"), True, "Usuario 2 agregado correctamente.")
def decorated(*args, **kwargs): token = None if 'x-access-token' in request.headers: token = request.headers['x-access-token'] if not token: return jsonify(message="Token is missing."), 401 current_user = IPContainer.tokenAccess(str(token)) if not current_user: return jsonify(message="Token is invalid."), 401 return f(current_user, *args, **kwargs)
def test_c_elimina_usuario(self): IPContainer.removeUser("test_user2") self.assertEqual(IPContainer.existUser("test_user2"), False, "Usuario eliminado correctamente.") self.assertEqual(IPContainer.getNumberOfUsers(), 1, "Usuario test_user2 borrado.")
def getAPIUser(current_user, public_id): return IPContainer.getAPIUser(public_id)
def test_l_comprobar_numero_redes(self): self.assertEqual(IPContainer.getNumberOfNetworks(), 1, "1 - Numero de redes correcto. (1)") IPContainer.createNetwork("test_user3", "wlan") self.assertEqual(IPContainer.getNumberOfNetworks(), 2, "2 - Numero de redes correcto. (2)")
def test_j_elimina_ip_de_red_no_existente(self): self.assertEqual( IPContainer.removeIPfromNetwork("test_user1", "pan", "5.5.5.5"), False, "IP borrada de la red no existente")
def test_h_comprueba_tamanio_red(self): self.assertEqual(IPContainer.getNetworkSize("test_user1", "dns"), 2, "Tamanio de red correcto.")
def test_f_crea_red_que_ya_existe(self): self.assertEqual(IPContainer.createNetwork("test_user1", "dns"), False, "Red existente no creada")
def existUser(current_user, user): return jsonify(exists=IPContainer.existUser(str(user)))
def getNumberOfUsers(current_user): return jsonify(users=IPContainer.getNumberOfUsers())
def removeUser(current_user, user): return jsonify(success=IPContainer.removeUser(str(user)))
def addUser(current_user, user): return jsonify(success=IPContainer.addUser(str(user)))
def status(): return IPContainer.getStatus()
def addAPIUser(current_user): data = request.get_json() done = IPContainer.addAPIUser(data['username'], data['password']) return jsonify(success=done)
def deleteAPIUser(current_user, public_id): return IPContainer.deleteAPIUser(public_id)
def test_d_elimina_usuario_que_no_existe(self): self.assertEqual(IPContainer.removeUser("test_user5"), False, "No elimina usuario que no existe.")
def test_e_crea_red(self): IPContainer.createNetwork("test_user1", "dns") self.assertEqual(IPContainer.existNetwork("test_user1", "dns"), True, "Nueva red creada correctamente")
def getNumberOfNetworks(current_user): return jsonify(networks=IPContainer.getNumberOfNetworks())
def _dropData(current_user): IPContainer._dropData() return jsonify(success=True)
def existNetwork(current_user, user, _type): return jsonify(exists=IPContainer.existNetwork(str(user), str(_type)))
def test_i_elimina_ip_de_red_existente(self): self.assertEqual( IPContainer.removeIPfromNetwork("test_user1", "dns", "5.5.5.5"), True, "IP borrada de la red existente")
def addIPtoNetwork(current_user, user, _type): js = request.get_json() return jsonify( success=IPContainer.addIPtoNetwork(str(user), str(_type), js['data']))
def test_k_comprobar_numero_usuarios(self): self.assertEqual(IPContainer.getNumberOfUsers(), 1, "Numero de usuarios correcto. (1)") IPContainer.addUser("test_user3") self.assertEqual(IPContainer.getNumberOfUsers(), 2, "Numero de usuarios correcto. (2)")
def removeIPfromNetwork(current_user, user, _type): js = request.get_json() return jsonify(success=IPContainer.removeIPfromNetwork( str(user), str(_type), js['ip']))
def removeNetwork(current_user, user, _type): return jsonify(success=IPContainer.removeNetwork(str(user), str(_type)))
def getAllAPIUsers(current_user): return IPContainer.getAllAPIUsers()