Skip to content

Commit

Permalink
Merge integration (autocomplete support) into rel/1.0.X
Browse files Browse the repository at this point in the history
  • Loading branch information
RayPlante committed Dec 17, 2021
2 parents 24b78e3 + 68ae457 commit 263d831
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 27 deletions.
Empty file.
3 changes: 3 additions & 0 deletions python/nistoar/doi/resolving/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"http://github.com/usnistgov/oar-metadata/",
"[email protected]")

def setUpModule():
res._client_info = None

class TestFuncs(test.TestCase):

def tearDown(self):
Expand Down
5 changes: 4 additions & 1 deletion python/nistoar/doi/resolving/tests/test_resolving.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
cli = ("NIST Open Access for Research", "testing",
"http://github.com/usnistgov/oar-metadata/",
"[email protected]")
set_client_info(*cli)
def setUpModule():
set_client_info(*cli)
def tearDownModule():
set_client_info(None, None, None, None)

logger = logging.getLogger("test")

Expand Down
Empty file.
4 changes: 4 additions & 0 deletions python/nistoar/nerdm/convert/tests/test_pod_doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"email": "[email protected]"
}

def setUpModule():
import nistoar.doi.resolving.common as res
res._client_info = None

class TestConvertAuthors(unittest.TestCase):

def test_citeproc_author2nerdm_author(self):
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions python/nistoar/rmm/ingest/tests/postcomm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash
#
# Used by test_wsgi.py, this script prints arguments to a given output file
#
# USAGE: postcomm.sh OUTFILE [ARG ...]
#
set -e
[ -n "$1" ] || {
echo "${0}: Missing output filename"
exit 1
}
out=$1; shift

echo "$@" > $out
58 changes: 54 additions & 4 deletions python/nistoar/rmm/ingest/tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from nistoar.tests import *
from nistoar.rmm.ingest import wsgi

pydir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
testdir = os.path.dirname(os.path.abspath(__file__))
pydir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(testdir))))
basedir = os.path.dirname(pydir)
schemadir = os.path.join(basedir, "model")
exdir = os.path.join(schemadir, "examples")
janaffile = os.path.join(exdir, "janaf.json")
postcomm = os.path.join(testdir, "postcomm.sh")

dburl = None
if os.environ.get('MONGO_TESTDB_URL'):
Expand Down Expand Up @@ -53,15 +55,17 @@ def start(self, status, headers=None, extup=None):

def setUp(self):
self.archdir = tmpfiles.mkdir("ingest_archive")
self.commitfile = os.path.join(self.archdir, "postcommit.txt")
self.config = {
"db_url": dburl,
'nerdm_schema_dir': os.path.abspath(schemadir),
'archive_dir': self.archdir
'archive_dir': self.archdir,
'post_commit_exec': postcomm + ' ' + self.commitfile + " {db_url} {recid} {recfile}"
}

try:
self.svc = wsgi.app(self.config)
except Exception, e:
except Exception as e:
self.tearDown()
raise
self.resp = []
Expand Down Expand Up @@ -92,6 +96,7 @@ def test_get_types(self):
self.assertGreater(len(self.resp), 0)
self.assertIn("200", self.resp[0])
self.assertEqual(body[0].strip(), '["nerdm"]')
self.assertFalse(os.path.exists(self.commitfile), "Commit file created unexpectedly")

def test_is_ready(self):
req = {
Expand All @@ -103,6 +108,7 @@ def test_is_ready(self):
self.assertGreater(len(self.resp), 0)
self.assertIn("200", self.resp[0])
self.assertEqual(body[0], 'Service ready\n')
self.assertFalse(os.path.exists(self.commitfile), "Commit file created unexpectedly")

def test_auth(self):
# test rejection when auth key provided but wsgi is not configured to
Expand Down Expand Up @@ -201,6 +207,7 @@ def test_is_not_found(self):
body = self.svc(req, self.start)
self.assertGreater(len(self.resp), 0)
self.assertIn("404", self.resp[0])
self.assertFalse(os.path.exists(self.commitfile), "Commit file created unexpectedly")

def test_bad_post_resource(self):
with open(janaffile) as doc:
Expand All @@ -213,6 +220,7 @@ def test_bad_post_resource(self):
body = self.svc(req, self.start)

self.assertIn("404", self.resp[0])
self.assertFalse(os.path.exists(self.commitfile), "Commit file created unexpectedly")

def test_no_content_length(self):
with open(janaffile) as doc:
Expand All @@ -226,6 +234,7 @@ def test_no_content_length(self):

self.assertIn("411", self.resp[0])
self.assertIn("Content-Length", self.resp[0])
self.assertFalse(os.path.exists(self.commitfile), "Commit file created unexpectedly")

def test_bad_content_length(self):
with open(janaffile) as doc:
Expand All @@ -239,7 +248,7 @@ def test_bad_content_length(self):
body = self.svc(req, self.start)

self.assertIn("400", self.resp[0])

self.assertFalse(os.path.exists(self.commitfile), "Commit file created unexpectedly")

def test_bad_post_input(self):
doc = StringIO('title <a href="http://bad.url">hello world</a>')
Expand All @@ -252,6 +261,7 @@ def test_bad_post_input(self):

body = self.svc(req, self.start)
self.assertIn("400", self.resp[0])
self.assertFalse(os.path.exists(self.commitfile), "Commit file created unexpectedly")

def test_good_post(self):
client = MongoClient(dburl)
Expand All @@ -266,6 +276,7 @@ def test_good_post(self):
finally:
client.close()

# self.svc = wsgi.app(self.config)
with open(janaffile) as doc:
clen = len(doc.read())
with open(janaffile) as doc:
Expand All @@ -282,6 +293,11 @@ def test_good_post(self):
self.assertTrue(os.path.isfile(archfile))

self.assertIn("200", self.resp[0])
self.assertTrue(os.path.isfile(self.commitfile), "Failed to create commit file")
with open(self.commitfile) as fd:
content = fd.read()
self.assertIn("sdp0fjspek351", content)
self.assertIn("mongodb:", content)

client = MongoClient(dburl)
try:
Expand All @@ -305,6 +321,40 @@ def setUp(self):

def tearDown(self):
tmpfiles.clean()

def test_mkpostcomm(self):
commexec = "echo {recfile} goober {recid} {file}"
commexec = wsgi._mkpostcomm(commexec, file="/tmp/gurn.txt")
self.assertTrue(isinstance(commexec, list), "Output is not a list")
self.assertEqual(len(commexec), 5)
self.assertEqual(commexec[4], "/tmp/gurn.txt")
self.assertEqual(commexec[0], "echo")
self.assertEqual(commexec[1], "{recfile}")
self.assertEqual(commexec[2], "goober")
self.assertEqual(commexec[3], "{recid}")

commexec = wsgi._mkpostcomm(commexec, "mds2-5555", file="/tmp/gary.txt")
self.assertEqual(commexec[4], "/tmp/gurn.txt")
self.assertEqual(commexec[0], "echo")
self.assertEqual(commexec[1], "{recfile}")
self.assertEqual(commexec[2], "goober")
self.assertEqual(commexec[3], "mds2-5555")

commexec = wsgi._mkpostcomm(commexec, "mds2-5556", "/tmp", file="/tmp/gary.txt")
self.assertEqual(commexec[4], "/tmp/gurn.txt")
self.assertEqual(commexec[0], "echo")
self.assertEqual(commexec[1], "/tmp/mds2-5556.json")
self.assertEqual(commexec[2], "goober")
self.assertEqual(commexec[3], "mds2-5555")

commexec = "echo {recfile} goober {recid} {file}"
commexec = wsgi._mkpostcomm(commexec, "mds2-5555", "/tmp", file="/tmp/gary.txt")
self.assertEqual(commexec[4], "/tmp/gary.txt")
self.assertEqual(commexec[0], "echo")
self.assertEqual(commexec[1], "/tmp/mds2-5555.json")
self.assertEqual(commexec[2], "goober")
self.assertEqual(commexec[3], "mds2-5555")


def test_nerdm_archive_cache(self):
with open(janaffile) as fd:
Expand Down
Loading

0 comments on commit 263d831

Please sign in to comment.