Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xgaia committed May 28, 2020
1 parent 6cf747d commit f4ab45f
Show file tree
Hide file tree
Showing 15 changed files with 2,162 additions and 932 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TESTPYTHON:=$(shell $(PYTHON) --version 2>/dev/null)
PIPENVOPTS=
FLASKOPTS=
PYTESTOPTS=
TESTFILE?=
TESTFILE?=tests
NTASKS?=1

HOST?=0.0.0.0
Expand Down
129 changes: 69 additions & 60 deletions askomics/libaskomics/LocalAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,23 +403,31 @@ def authenticate_user(self, login, password):
# If user is local, check the password
else:
password_match = self.check_password(user["username"], password, user["password"], user["salt"])
# Don't return password and salt
user.pop("password")
user.pop("salt")
else:
# No user in database, try to get it from ldap
ldap_user = ldap_auth.get_user(login)
# If user in ldap and not in db, create it in db
if ldap_user:
password_match = ldap_auth.check_password(ldap_user["dn"], password)
if password_match:
inputs = {
"username": ldap_user["username"]
}
# Create user in db
user = self.persist_user(inputs, ldap_login=True)
user["fname"] = ldap_user["fname"]
user["lname"] = ldap_user["lname"]
user["email"] = ldap_user["email"]
# Create user directories
self.create_user_directories(user["id"], user["username"])
if ldap_auth.ldap:
ldap_user = ldap_auth.get_user(login)
# If user in ldap and not in db, create it in db
if ldap_user:
password_match = ldap_auth.check_password(ldap_user["dn"], password)
if password_match:
inputs = {
"username": ldap_user["username"]
}
# Create user in db
user = self.persist_user(inputs, ldap_login=True)
user["fname"] = ldap_user["fname"]
user["lname"] = ldap_user["lname"]
user["email"] = ldap_user["email"]
# Create user directories
self.create_user_directories(user["id"], user["username"])

# Don't return password and salt
user.pop("password")
user.pop("salt")

if not password_match or not user:
error_messages.append("Bad login or password")
Expand Down Expand Up @@ -638,8 +646,7 @@ def update_password(self, inputs, user):
if not inputs["newPassword"] == '':
if password_identical:
# Try to authenticate the user with his old password
credentials = {'login': user['username'], 'password': inputs['oldPassword']}
authentication = self.authenticate_user(credentials)
authentication = self.authenticate_user(user['username'], inputs['oldPassword'])
if not authentication['error']:
self.update_pw_db(user['username'], inputs['newPassword'])
else:
Expand Down Expand Up @@ -787,17 +794,18 @@ def get_user(self, username):
User
"""
user = self.get_user_from_db(username)
user.pop("password")
user.pop("salt")
ldap_auth = LdapAuth(self.app, self.session)
if user:
user.pop("password")
user.pop("salt")
ldap_auth = LdapAuth(self.app, self.session)

if user["ldap"] == 1 and ldap_auth.ldap:
ldap_user = ldap_auth.get_user(username)
if ldap_user:
user["username"] = ldap_user["username"]
user["fname"] = ldap_user["fname"]
user["lname"] = ldap_user["lname"]
user["email"] = ldap_user["email"]
if user["ldap"] == 1 and ldap_auth.ldap:
ldap_user = ldap_auth.get_user(username)
if ldap_user:
user["username"] = ldap_user["username"]
user["fname"] = ldap_user["fname"]
user["lname"] = ldap_user["lname"]
user["email"] = ldap_user["email"]

return user

Expand Down Expand Up @@ -1039,51 +1047,52 @@ def send_reset_link(self, login):
login_type = self.get_login_type(login)

user = self.get_user(login)
if user["ldap"] == 1:
return
if user:
if user["ldap"] == 1:
return

if login_type == 'username':
valid_user = self.is_username_in_db(login)
username = login
email = self.get_email_with_username(login) if valid_user else None
else:
valid_user = self.is_email_in_db(login)
username = self.get_username_with_email(login) if valid_user else None
email = login
if login_type == 'username':
valid_user = self.is_username_in_db(login)
username = login
email = self.get_email_with_username(login) if valid_user else None
else:
valid_user = self.is_email_in_db(login)
username = self.get_username_with_email(login) if valid_user else None
email = login

if valid_user:
token = self.create_reset_token(login)
if valid_user:
token = self.create_reset_token(login)

mailer = Mailer(self.app, self.session)
if mailer.check_mailer():
body = textwrap.dedent("""
Dear {user},
mailer = Mailer(self.app, self.session)
if mailer.check_mailer():
body = textwrap.dedent("""
Dear {user},
We heard that you lost your AskOmics password. Sorry about that!
We heard that you lost your AskOmics password. Sorry about that!
But don’t worry! You can use the following link to reset your password:
But don’t worry! You can use the following link to reset your password:
{url}/password_reset?token={token}
{url}/password_reset?token={token}
If you don’t use this link within 3 hours, it will expire. To get a new password reset link, visit {url}/password_reset
If you don’t use this link within 3 hours, it will expire. To get a new password reset link, visit {url}/password_reset
Thanks,
The AskOmics Team
Thanks,
The AskOmics Team
""".format(
user=username,
url=self.settings.get('askomics', 'instance_url'),
token=token
))
""".format(
user=username,
url=self.settings.get('askomics', 'instance_url'),
token=token
))

asko_subtitle = ""
try:
asko_subtitle = " | {}".format(self.settings.get("askomics", "subtitle"))
except Exception:
pass
asko_subtitle = ""
try:
asko_subtitle = " | {}".format(self.settings.get("askomics", "subtitle"))
except Exception:
pass

mailer.send_mail(email, "[AskOmics{}] Password reset".format(asko_subtitle), body)
mailer.send_mail(email, "[AskOmics{}] Password reset".format(asko_subtitle), body)

def check_token(self, token):
"""Get username corresponding to the token
Expand Down
2 changes: 1 addition & 1 deletion askomics/libaskomics/SparqlQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ def build_query_from_json(self, preview=False, for_editor=False):
predicate = "faldo:location/faldo:{}/faldo:position".format("begin" if attribute["faldo"].endswith("faldoStart") else "end")
else:
predicate = "<{}>".format(attribute["uri"])
obj = self.format_sparql_variable("{}{}_{}".format(attribute["entityLabel"], attribute["humanNodeId"], attribute["label"]))
obj = self.format_sparql_variable("{}{}_{}".format(attribute["entityLabel"], attribute["nodeId"], attribute["label"]))
self.store_triple({
"subject": subject,
"predicate": predicate,
Expand Down
4 changes: 2 additions & 2 deletions askomics/libaskomics/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def camel_case(string):
return ''.join(x for x in string.title() if not x.isspace())

@staticmethod
def unique(l):
def unique(dup_list):
"""return the list with duplicate elements removed and keep order"""
return [i for n, i in enumerate(l) if i not in l[n + 1:]]
return [i for n, i in enumerate(dup_list) if i not in dup_list[n + 1:]]

@staticmethod
def intersect(a, b):
Expand Down
5 changes: 3 additions & 2 deletions askomics/react/src/routes/query/query.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ export default class Query extends Component {
if (link.source.id == node1.id && link.target.id == node2.id) {
newLink = {
uri: link.uri,
type: "link",
type: ["included_in", "overlap_with"].includes(link.uri) ? "posLink" : "link",
sameStrand: this.nodeHaveStrand(node1.uri) && this.nodeHaveStrand(node2.uri),
sameRef: this.nodeHaveRef(node1.uri) && this.nodeHaveRef(node2.uri),
strict: true,
Expand All @@ -609,7 +609,7 @@ export default class Query extends Component {
if (link.source.id == node2.id && link.target.id == node1.id) {
newLink = {
uri: link.uri,
type: "link",
type: ["included_in", "overlap_with"].includes(link.uri) ? "posLink" : "link",
sameStrand: this.nodeHaveStrand(node1.uri) && this.nodeHaveStrand(node2.uri),
sameRef: this.nodeHaveRef(node1.uri) && this.nodeHaveRef(node2.uri),
strict: true,
Expand Down Expand Up @@ -823,6 +823,7 @@ export default class Query extends Component {
saveIcon: "play",
waiting: waiting
})
console.log(this.graphState)
}

initGraph () {
Expand Down
18 changes: 9 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from askomics.libaskomics.SparqlQueryLauncher import SparqlQueryLauncher
from askomics.libaskomics.Start import Start
from askomics.libaskomics.Result import Result
from askomics.libaskomics.SparqlQueryBuilder import SparqlQueryBuilder
from askomics.libaskomics.SparqlQuery import SparqlQuery
from askomics.libaskomics.Utils import Utils

import pytest
Expand Down Expand Up @@ -423,24 +423,24 @@ def create_result(self):
dict
Result info
"""
# Query: transcript concerned by DE and included in QTL

with open("tests/data/graphState_simple_query.json", "r") as file:
file_content = file.read()

json_query = json.loads(file_content)

# Get query and endpoints and graphs of the query
query_builder = SparqlQueryBuilder(self.app, self.session)
query = SparqlQuery(self.app, self.session, json_query)
query_launcher = SparqlQueryLauncher(self.app, self.session)
query = query_builder.build_query_from_json(json_query, preview=False, for_editor=False)
endpoints = query_builder.endpoints
graphs = query_builder.graphs
query.build_query_from_json(preview=False, for_editor=False)

info = {
"graph_state": json_query,
"query": query,
"query": query.sparql,
"celery_id": '00000000-0000-0000-0000-000000000000',
"graphs": graphs,
"endpoints": endpoints
"graphs": query.graphs,
"endpoints": query.endpoints
}

# Save job in database database
Expand All @@ -449,7 +449,7 @@ def create_result(self):
result.save_in_db()

# Execute query and write result to file
headers, results = query_launcher.process_query(query)
headers, results = query_launcher.process_query(query.sparql)
file_size = result.save_result_in_file(headers, results)

# Update database status
Expand Down
Loading

0 comments on commit f4ab45f

Please sign in to comment.