Moved tests in a seperate folder

This commit is contained in:
Navan Chauhan 2020-07-07 11:41:42 +05:30
parent 0f0791037f
commit b296e4d277
7 changed files with 3092 additions and 8 deletions

View File

@ -20,8 +20,7 @@ jobs:
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install mysql-connector mysql pip install mysql-connector mysql
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Fetch Latest Curie-CLI - name: Fetch Latest Curie-CLI
run: docker pull navanchauhan/curie-cli:latest run: docker pull navanchauhan/curie-cli:latest
- name: Run Database-Filler script - name: Run Backend Test
run: cd app && python backend_test.py run: cd tests && python backednTest.py

View File

@ -20,12 +20,10 @@ jobs:
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install flake8 mysql-connector mysql pip install flake8 mysql-connector mysql
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint script with flake8 - name: Lint script with flake8
run: | run: |
# stop the build if there are Python syntax errors or undefined names flake8 ./tests/dbTestFiller.py --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 ./app/dbTestFiller.py --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 ./app/dbTestFiller.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics flake8 ./tests/dbTestFiller.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run Database-Filler script - name: Run Database-Filler script
run: cd app && python dbTestFiller.py run: cd tests && python dbTestFiller.py

100
tests/backendTest.py Normal file
View File

@ -0,0 +1,100 @@
import mysql.connector as con
mycon = con.connect(host="navanspi.duckdns.org",user="curieweb",password="curie-web-russian-54",port=3306,database="curie")
mycursor = mycon.cursor()
# If we are running the CI on an actual server, try using the 6LU7 Mpro and Geraniin Job ID because Eucalyptol fails
sql_select_Query = 'select * from curieweb where id="l9xo2isr98oepcia" LIMIT 1'
mycursor.execute(sql_select_Query)
records = mycursor.fetchall()
def email(zi):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
fromaddr = "navanchauhan@gmail.com"
toaddr = toEmail
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Curie Web Results for Job ID " + str(jobID)
body = "Attached Zip contains the docked files, PLIP report and PyMOL Visualisations. If the ZIP file does not contain these files, please report this issue by replying to this email. Job was submitted on {} with the description {}".format(date, description)
msg.attach(MIMEText(body, 'plain'))
filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip"
attachment = open((str(zi) + ".zip"), "rb")
p = MIMEBase('application', 'octet-stream')
p.set_payload((attachment).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p)
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(fromaddr, 'ircd mday avbc tice')
text = msg.as_string()
s.sendmail(fromaddr, toaddr, text)
s.quit()
receptor_name = "protein.pdbqt"
ligand_name = "ligand.pdbqt"
description = "GitHub Action Test"
#print(records[0])
r = records[0]
jobID = r[0]
toEmail = r[1]
targetB = r[2]
if r[3] != None:
receptor_name = str(r[3])
if r[6] != None:
ligand_name = str(r[6])
ligandB = r[4]
configB = r[7]
date = r[8]
if r[9] != None:
description = r[9]
import os
cd = os.getcwd()
f = os.path.join(cd,"static/uploads")
#t = os.path.join(f,"receptor",target)
#r = os.path.join(f,"ligands",ligand)
#c = os.path.join(f,"configs",config)
print(f)
import tempfile
from shutil import copy
from shutil import make_archive
with tempfile.TemporaryDirectory() as directory:
print('The created temporary directory is %s' % directory)
os.chdir(directory)
# copy(t,os.getcwd())
# copy(r,os.getcwd())
# copy(c, os.getcwd())
file = open(receptor_name,"wb")
file.write(targetB)
file.close()
file = open(ligand_name,"wb")
file.write(ligandB)
file.close()
file = open("config.txt","wb")
file.write(configB)
file.close()
os.system("docker run --rm -v ${PWD}:/results -w /results -u $(id -u ${USER}):$(id -g ${USER}) navanchauhan/curie-cli -r %s -l %s -c config.txt -dpi" % (receptor_name,ligand_name))
#copy("report.pdf",f)
z = "Curie_Web_Result_"+str(jobID)
zi = os.path.join(f,z)
make_archive(zi, 'zip', directory)
#copy(("Curie_Web_Result_"+str(jobID)),f)
email(zi)
#print((str(zi) + ".zip"))
mycursor.execute('UPDATE curieweb set done=1 where id="%s"' % (jobID))
mycon.commit()

69
tests/dbTestFiller.py Normal file
View File

@ -0,0 +1,69 @@
import mysql.connector as con
debug = False
host = "navanspi.duckdns.org"
done = 1
if debug != False:
host = "192.168.1.6"
done = 0
mycon = con.connect(host=host,user="curieweb",password="curie-web-russian-54",port=3306,database="curie")
mycursor = mycon.cursor()
try:
mycursor.execute("create table curieweb ( id varchar(16) primary key, email nvarchar(255) NOT NULL, protein LONGBLOB NOT NULL, protein_name VARCHAR(255), ligand_pdbqt LONGBLOB, ligand_smile VARCHAR(255), ligand_name VARCHAR(255), config LONGBLOB NOT NULL, date DATE, description VARCHAR(255), done TINYINT DEFAULT 0)")
except con.ProgrammingError:
print("Table Already Exists!")
#try:
# mycursor.execute("insert into curieweb values (1,'navanchauhan@gmail.com','lu.pdbqt','test.pdbqt','owo.txt',CURDATE(),'CURIE WEB TASK',0)")
#except con.IntegrityError:
# print("Duplicate Entry For Primary Key!")
from random import choice, shuffle
from string import digits, ascii_lowercase
def gen_word(N, min_N_dig, min_N_low):
choose_from = [digits]*min_N_dig + [ascii_lowercase]*min_N_low
choose_from.extend([digits + ascii_lowercase] * (N-min_N_low-min_N_dig))
chars = [choice(bet) for bet in choose_from]
shuffle(chars)
return ''.join(chars)
def convertToBinaryData(filename):
with open(filename, 'rb') as file:
binaryData = file.read()
return binaryData
from os.path import basename
ligand = convertToBinaryData("./files/Eucalyptol.pdbqt")
receptor = convertToBinaryData("./files/6LU7.pdbqt")
config = convertToBinaryData("./files/6LU7.txt")
ligandName = "Eucalyptol"
receptorName = "6LU7"
sqlQuery = "insert into curieweb (id, email, protein, protein_name, ligand_pdbqt, ligand_name,date, config,done) values (%s,%s,%s,%s,%s,%s,CURDATE(),%s,%s) "
jobID = gen_word(16, 1, 1)
print("Succesfuly submitted Job ID:",jobID)
insert_tuple = (jobID,"navanchauhan@gmail.com",receptor,receptorName,ligand,ligandName,config,done)
try:
mycursor.execute(sqlQuery,insert_tuple)
except con.IntegrityError:
print("Oops, Collision occured. Generating new Job ID and trying again.")
jobID = gen_word(16, 1, 1)
insert_tuple = (jobID,"navanchauhan@gmail.com",receptor,receptorName,ligand,ligandName,config,done)
mycursor.execute(sqlQuery,insert_tuple)
print("Removing Test Query")
q = 'delete from curieweb where id="%s"' % (jobID)
mycursor.execute(q)
mycon.commit()
print("Database working perfectly")

2889
tests/files/6LU7.pdbqt Normal file

File diff suppressed because it is too large Load Diff

7
tests/files/6LU7.txt Normal file
View File

@ -0,0 +1,7 @@
receptor=./targets/6LU7.pdbqt
center_x=-9.7
center_y=11.4
center_z=68.9
size_x=19.3
size_y=29.9
size_z=21.3

View File

@ -0,0 +1,22 @@
REMARK Name =
REMARK 3 active torsions:
REMARK status: ('A' for Active; 'I' for Inactive)
REMARK 1 A between atoms: C_1 and C_2
REMARK 2 A between atoms: C_2 and C_11
REMARK 3 A between atoms: C_6 and C_10
REMARK x y z vdW Elec q Type
REMARK _______ _______ _______ _____ _____ ______ ____
ROOT
ATOM 1 C UNL 1 0.937 -0.135 -0.034 0.00 0.00 +0.000 C
ATOM 2 C UNL 1 2.469 -0.028 0.003 0.00 0.00 +0.000 C
ATOM 3 C UNL 1 2.954 1.145 0.903 0.00 0.00 +0.000 C
ATOM 4 C UNL 1 2.482 0.909 2.351 0.00 0.00 +0.000 C
ATOM 5 C UNL 1 2.921 -0.490 2.797 0.00 0.00 +0.000 C
ATOM 6 C UNL 1 3.781 -1.141 1.697 0.00 0.00 +0.000 C
ATOM 7 O UNL 1 2.972 -1.282 0.511 0.00 0.00 +0.000 OA
ATOM 8 C UNL 1 4.986 -0.243 1.358 0.00 0.00 +0.000 C
ATOM 9 C UNL 1 4.494 1.151 0.952 0.00 0.00 +0.000 C
ATOM 10 C UNL 1 4.237 -2.536 2.112 0.00 0.00 +0.000 C
ATOM 11 C UNL 1 2.966 0.109 -1.444 0.00 0.00 +0.000 C
ENDROOT
TORSDOF 0