diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2019-05-30 17:56:06 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-05-31 11:35:42 +0200 |
commit | 58ac5495f765df7da902d875af5fe8796b44dce0 (patch) | |
tree | a69ba9e5af2c0c0b99227cb40b7c4bd1cb014c49 /admin | |
parent | b3467f7ddb96c3bf274894585b9a398172f8781b (diff) |
#915 add unit test infrastructure for REST API
This python script creates a database and starts ogAdmServer to run the
tests. This requires root to be launched:
# ./run-tests.py
From the 'tests' folder.
Diffstat (limited to 'admin')
-rw-r--r-- | admin/Sources/Services/ogAdmServer/tests/config/ogAdmServer.cfg | 7 | ||||
-rwxr-xr-x | admin/Sources/Services/ogAdmServer/tests/run-tests.py | 42 |
2 files changed, 49 insertions, 0 deletions
diff --git a/admin/Sources/Services/ogAdmServer/tests/config/ogAdmServer.cfg b/admin/Sources/Services/ogAdmServer/tests/config/ogAdmServer.cfg new file mode 100644 index 00000000..aa201130 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/config/ogAdmServer.cfg @@ -0,0 +1,7 @@ +ServidorAdm=localhost +PUERTO=2008 +USUARIO=test-db +PASSWORD=test-db +datasource=localhost +CATALOG=test-db +INTERFACE=eth1 diff --git a/admin/Sources/Services/ogAdmServer/tests/run-tests.py b/admin/Sources/Services/ogAdmServer/tests/run-tests.py new file mode 100755 index 00000000..0491ccb2 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/run-tests.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import subprocess, glob, os + +sql_data = "INSERT INTO aulas (nombreaula, idcentro, urlfoto, grupoid, ubicacion, puestos, modomul, ipmul, pormul, velmul, router, netmask, ntp, dns, proxy, modp2p, timep2p) VALUES ('Aula virtual', 1, 'aula.jpg', 0, 'Despliegue virtual con Vagrant.', 5, 2, '239.194.2.11', 9000, 70, '192.168.56.1', '255.255.255.0', '', '', '', 'peer', 30); INSERT INTO ordenadores (nombreordenador, ip, mac, idaula, idrepositorio, idperfilhard, idmenu, idproautoexec, grupoid, router, mascara, arranque, netiface, netdriver, fotoord) VALUES ('pc2', '192.168.2.1', '0800270E6501', 1, 1, 0, 0, 0, 0, '192.168.56.1', '255.255.255.0', '00unknown', 'eth0', 'generic', 'fotoordenador.gif'), ('pc2', '192.168.2.2', '0800270E6502', 1, 1, 0, 0, 0, 0, '192.168.56.1', '255.255.255.0', '00unknown', 'eth0', 'generic', 'fotoordenador.gif');" + +sql_create_user = "CREATE USER 'test-db'@'hostname'; GRANT ALL PRIVILEGES ON *.* To 'test-db'@'hostname' IDENTIFIED BY 'test-db';" + +sql_delete_user = "DROP USER 'test-db'@'hostname';" + +def start_mysql(): + + subprocess.run(['mysqladmin', 'drop', '-f', 'test-db'], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocess.run(['mysqladmin', 'create', 'test-db']) + subprocess.run('mysql --default-character-set=utf8 test-db < ../../../../Database/ogAdmBD.sql', shell=True) + subprocess.run(['mysql', '-D', 'test-db', '-e', sql_data]) + subprocess.run(['mysql', '-D', 'test-db', '-e', sql_create_user]) + + return + +def stop_mysql(): + + subprocess.run(['mysql', '-D', 'test-db', '-e', sql_delete_user]) + subprocess.run(['mysqladmin', 'drop', '-f', 'test-db']) + + return + +if os.getuid() is not 0: + print('You need to be root to run these tests :-)') + exit() + +start_mysql(); + +subprocess.Popen(['../ogAdmServer', '-f', 'config/ogAdmServer.cfg']) + +for filename in glob.iglob('units/**'): + subprocess.run(['python3', filename, '-v']) + +stop_mysql(); + +subprocess.run(['pkill', 'ogAdmServer']) |