Skip to content

Commit

Permalink
more verbose message for missing configs on update-queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Simaris committed Apr 24, 2019
1 parent 99a28b1 commit 80d1db2
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
17 changes: 17 additions & 0 deletions quit/web/modules/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ def sparql(branch_or_ref):
else:
response.headers["X-CurrentCommit"] = commitid
return response
except KeyError as e:
logger.exception(e)
print(e.args)
if "config value 'user.name' was not found" in e.args:
message = ("Unable to process query: "
"git config value 'user.name' was not found.\n"
"Please use the following command in your data repo:"
"\n\n git config user.name <your name>")
return make_response(message, 400)
if "config value 'user.email' was not found" in e.args:
message = ("Unable to process query: "
"git config value 'user.email' was not found.\n"
"Please use the following command in your data repo:"
"\n\n git config user.email <your email>")
return make_response(message, 400)
# KeyError has many sources -> it could be caused by other problems
return make_response('Error after executing the update query.', 400)
except Exception as e:
# query ok, but unsupported query type or other problem during commit
logger.exception(e)
Expand Down
16 changes: 15 additions & 1 deletion quit/web/modules/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,21 @@ def merge(refspec):
return response
else:
return "<pre>Unsupported Mimetype: {}</pre>".format(mimetype), 406

except KeyError as e:
message = "\n"
if "config value 'user.name' was not found" in e.args:
message += ("Unable to process query: "
"git config value 'user.name' was not found.\n"
"Please use the following command in your data repo:"
"\n\n git config user.name <your name>")
if "config value 'user.email' was not found" in e.args:
message += ("Unable to process query: "
"git config value 'user.email' was not found.\n"
"Please use the following command in your data repo:"
"\n\n git config user.email <your email>")
logger.error(e)
logger.error(traceback.format_exc())
return "<pre>" + traceback.format_exc() + message + "</pre>", 400
except Exception as e:
logger.error(e)
logger.error(traceback.format_exc())
Expand Down
51 changes: 51 additions & 0 deletions tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import quit.application as quitApp
from quit.web.app import create_app
from tempfile import TemporaryDirectory
from pygit2 import config as gitconfig
import json

class EndpointTests(unittest.TestCase):
Expand All @@ -28,6 +29,7 @@ def testInsertDataNoSnapshotIsolation(self):
config = objects['config']
app = create_app(config).test_client()


# execute INSERT DATA query
update = """INSERT DATA {
GRAPH <http://example.org/> {
Expand Down Expand Up @@ -412,6 +414,55 @@ def testInsertDataOverlappingWithMerge(self):
"p": {'type': 'uri', 'value': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'},
"o": {'type': 'uri', 'value': 'http://ex.org/Todo'}})

def testInsertDataWithNoGitConfigUser(self):
with TemporaryDirectory() as repo:

# Start Quit
args = quitApp.parseArgs(['-t', repo])
objects = quitApp.initialize(args)
config = objects['config']
app = create_app(config).test_client()
gitGlobalConfig = gitconfig.Config.get_global_config()
username = gitGlobalConfig.__getitem__("user.name")
email = gitGlobalConfig.__getitem__("user.email")
try:
gitconfig.Config.get_global_config().__delitem__("user.name")
# execute INSERT DATA query
update = """INSERT DATA {
GRAPH <http://example.org/> {
<http://ex.org/garbage> a <http://ex.org/Todo> ;
<http://ex.org/task> "Take out the organic waste" .
}}
"""
response = app.post('/sparql', data=dict(update=update))
message = response.get_data().decode("utf-8")
self.assertEqual(
message,
("Unable to process query: git config value 'user.name' "
"was not found.\nPlease use the following command in your"
" data repo:\n\n git config user.name <your name>"))
# Uncommenting the second line below and commenting the first
# causes the test to fail with an KeyError.
# "username" and username are both str s
# Even more, the same code line still correctly reset user.name
# and user.email
gitGlobalConfig.__setitem__("user.name", "username")
# gitGlob alConfig.__setitem__("user.name", username)
gitGlobalConfig = gitconfig.Config.get_global_config()
gitGlobalConfig.__delitem__("user.email")
response = app.post('/sparql', data=dict(update=update))
gitGlobalConfig.__setitem__("user.name", username)
gitGlobalConfig.__setitem__("user.email", email)
message = response.get_data().decode("utf-8")
self.assertEqual(
message,
("Unable to process query: git config value 'user.email' "
"was not found.\nPlease use the following command in your"
" data repo:\n\n git config user.email <your email>"))
except Exception as e:
gitGlobalConfig.__setitem__("user.name", username)
gitGlobalConfig.__setitem__("user.email", email)
raise e

if __name__ == '__main__':
unittest.main()

0 comments on commit 80d1db2

Please sign in to comment.