diff --git a/tests/data/test.graphml b/tests/data/test.graphml deleted file mode 100644 index afa0b0d..0000000 --- a/tests/data/test.graphml +++ /dev/null @@ -1,209 +0,0 @@ - - - - - - - - - Erdos renyi (gnp) graph - gnp - false - 0.4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/test_convert_image_export.py b/tests/test_convert_image_export.py new file mode 100644 index 0000000..90dcdb0 --- /dev/null +++ b/tests/test_convert_image_export.py @@ -0,0 +1,52 @@ +import unittest +import test_settings +import ndio.remote.neurodata as neurodata +import ndio.ramon +import ndio.convert.png as ndpng +import ndio.convert.tiff as ndtiff +import numpy as np +import os + + +class TestDownload(unittest.TestCase): + + def setUp(self): + self.hostname = test_settings.HOSTNAME + self.token_user = test_settings.NEURODATA + self.nd = neurodata(user_token=self.token_user, hostname=self.hostname) + self.image_data = np.zeros((512,512), dtype=np.uint8) + + # self.image_data = (255.0 / data.max() * (data - data.min())).astype(np.uint8) + + def test_export_load_png(self): + + # if returns string, successful export + self.assertEqual( + ndpng.save("download.png", self.image_data), + "download.png") + + # now confirm import works too + self.assertEqual(ndpng.load("download.png")[0][0], + self.image_data[0][0]) + self.assertEqual(ndpng.load("download.png")[10][10], + self.image_data[10][10]) + os.system("rm ./download.png") + + def test_export_load_tiff(self): + # if returns string, successful export + self.assertEqual( + ndtiff.save("download-1.tiff", + self.image_data), + "download-1.tiff") + + # now confirm import works too + self.assertEqual( + ndtiff.load("download-1.tiff")[0][0], + self.image_data[0][0]) + self.assertEqual( + ndtiff.load("download-1.tiff")[10][10], + self.image_data[10][10]) + os.system("rm ./download-1.tiff") + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_convert_image_export.py.old b/tests/test_convert_image_export.py.old deleted file mode 100644 index 672d023..0000000 --- a/tests/test_convert_image_export.py.old +++ /dev/null @@ -1,56 +0,0 @@ -import unittest -import ndio.remote.neurodata as neurodata -import ndio.ramon -import ndio.convert.png as ndpng -import ndio.convert.tiff as ndtiff -import numpy - - -class TestDownload(unittest.TestCase): - - def setUp(self): - self.oo = neurodata() - - def test_export_load(self): - # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/ - image_download = self.oo.get_image('kasthuri11', 'image', - 1000, 1100, - 1000, 1100, - 1000, - resolution=3) - - # if returns string, successful export - self.assertEqual( - ndpng.export_png("tests/trash/download.png", image_download), - "tests/trash/download.png") - - # now confirm import works too - self.assertEqual(ndpng.load("tests/trash/download.png")[0][0], - image_download[0][0]) - self.assertEqual(ndpng.load("tests/trash/download.png")[10][10], - image_download[10][10]) - - def test_export_load(self): - # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/ - image_download = self.oo.get_image('kasthuri11', 'image', - 1000, 1100, - 1000, 1100, - 1000, - resolution=3) - - # if returns string, successful export - self.assertEqual( - ndtiff.save("tests/trash/download-1.tiff", - image_download), - "tests/trash/download-1.tiff") - - # now confirm import works too - self.assertEqual( - ndtiff.load("tests/trash/download-1.tiff")[0][0], - image_download[0][0]) - self.assertEqual( - ndtiff.load("tests/trash/download-1.tiff")[10][10], - image_download[10][10]) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_data.py b/tests/test_data.py new file mode 100644 index 0000000..d693ab2 --- /dev/null +++ b/tests/test_data.py @@ -0,0 +1,50 @@ +import unittest +import ndio.remote.neurodata as neurodata +import ndio.remote.errors +import numpy +import h5py +import os +import test_settings + +HOSTNAME = test_settings.HOSTNAME +NEURODATA = test_settings.NEURODATA +TEST = test_settings.TEST + +class TestData(unittest.TestCase): + + def setUp(self): + self.token_user = NEURODATA + hostname = HOSTNAME + self.nd = neurodata(self.token_user, + hostname=hostname, + check_tokens=True) + self.ramon_id = 1 + dataset_name = 'demo1' + project_name = 'ndio_demos' + self.t = 'test_token' + self.c = 'test_channel' + self.nd.create_dataset(dataset_name, 100, 100, 100, 1.0, + 1.0, + 1.0) + self.nd.create_project(project_name, dataset_name, + 'localhost', + 1, 1, 'localhost', 'Redis') + self.nd.create_token(self.t, project_name, dataset_name, 1) + try: + self.nd.create_channel(self.c, project_name, + dataset_name, 'timeseries', + 'uint8', 0, 500, propagate=1) + except: + pass + + #random 3-d array + self.data = numpy.arange(30).reshape(2,3,5) + + def test_post_cutout(self): + self.nd.post_cutout(self.t, self.c, 0, 0, 0, 0, self.data) + + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/test_getURL.py b/tests/test_getURL.py new file mode 100644 index 0000000..4d46573 --- /dev/null +++ b/tests/test_getURL.py @@ -0,0 +1,117 @@ +import ndio.remote.neurodata as neurodata +import test_settings +import unittest + +HOSTNAME = test_settings.HOSTNAME +NEURODATA = test_settings.NEURODATA +TEST = test_settings.TEST + +class TestgetURL(unittest.TestCase): + + def setUp(self): + self.neurodata = neurodata(user_token=NEURODATA, hostname=HOSTNAME) + self.public = neurodata(hostname=HOSTNAME) + self.test = neurodata(user_token=TEST, hostname=HOSTNAME) + self.private_project = "https://{}/nd/sd/private_neuro/info/".format(HOSTNAME) + self.public_project = "https://{}/nd/sd/public_neuro/info/".format(HOSTNAME) + self.private_test_project = "https://{}/nd/sd/private_test_neuro/info/".format(HOSTNAME) + + #Create the projects/tokens that are required for this + self.neurodata.create_dataset('private_neuro', 10, 10, 10, 1, 1, 1) + self.neurodata.create_project('private_neuro', 'private_neuro', 'localhost', 0) + self.neurodata.create_token('private_neuro', 'private_neuro', 'private_neuro', 0) + + self.neurodata.create_dataset('public_neuro', 10, 10, 10, 1, 1, 1) + self.neurodata.create_project('public_neuro', 'public_neuro', 'localhost', 1) + self.neurodata.create_token('public_neuro', 'public_neuro', 'public_neuro', 1) + + self.test.create_dataset('private_test_neuro', 10, 10, 10, 1, 1, 1) + self.test.create_project('private_test_neuro', 'private_test_neuro', 'localhost', 0) + self.test.create_token('private_test_neuro', 'private_test_neuro', 'private_test_neuro', 0) + + def tearDown(self): + self.neurodata.delete_token('private_neuro', 'private_neuro', 'private_neuro') + self.neurodata.delete_project('private_neuro', 'private_neuro') + self.neurodata.delete_dataset('private_neuro') + + self.neurodata.delete_token('public_neuro', 'public_neuro', 'public_neuro') + self.neurodata.delete_project('public_neuro', 'public_neuro') + self.neurodata.delete_dataset('public_neuro') + + self.neurodata.delete_token('private_test_neuro', 'private_test_neuro', 'private_test_neuro') + self.neurodata.delete_project('private_test_neuro', 'private_test_neuro') + self.neurodata.delete_dataset('private_test_neuro') + + def test_masterToken(self): + try: + req = self.neurodata.getURL(self.private_project) + print(req.status_code) + self.assertEqual(req.status_code, 200) + except ValueError as e: + print(req.content) + try: + req2 = self.neurodata.getURL(self.public_project) + self.assertEqual(req2.status_code, 200) + except ValueError as e: + print(e) + + try: + req3 = self.neurodata.getURL(self.private_test_project) + self.assertEqual(req3.status_code, 200) + except ValueError as e: + print(e) + + def test_testToken(self): + try: + req = self.test.getURL(self.private_project) + self.assertEqual(req.status_code, 403) + except ValueError as e: + print(e) + try: + req2 = self.test.getURL(self.public_project) + self.assertEqual(req2.status_code, 200) + except ValueError as e: + print(e) + try: + req3 = self.test.getURL(self.private_test_project) + self.assertEqual(req3.status_code, 200) + except ValueError as e: + print(e) + + + def test_publicToken(self): + try: + req = self.public.getURL(self.private_project) + self.assertEqual(req.status_code, 401) + except ValueError as e: + print(req.content) + try: + req2 = self.public.getURL(self.public_project) + self.assertEqual(req2.status_code, 200) + except ValueError as e: + print(e) + + def test_newToken(self): + test = neurodata(user_token=TEST, hostname='localhost') + test.create_dataset('test', 1, 1, 1, 1.0, 1.0, 1.0, 0) + test.create_project('testp', 'test', 'localhost', 1, 1, 'localhost', 'Redis') + test.create_token('testt', 'testp', 'test', 1) + new_token = neurodata(user_token='testt', hostname=HOSTNAME) + new_token_project = "https://{}/sd/testp/info/".format(HOSTNAME) + # try: + # req = new_token.getURL(new_token_project) + # self.assertEqual(req.status_code, 200) + # except ValueError as e: + # print(e) + # try: + # req2 = new_token.getURL(self.private_project) + # self.assertEqual(req2.status_code, 401) + # except ValueError as e: + # print(e) + + test.delete_token('testt', 'testp', 'test') + test.delete_project('testp', 'test') + test.delete_dataset('test') + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_propagate.py b/tests/test_propagate.py index 05db3e1..860a23f 100644 --- a/tests/test_propagate.py +++ b/tests/test_propagate.py @@ -48,6 +48,25 @@ def test_propagate_status_fails_on_bad_token(self): with self.assertRaises(ValueError): self.nd.get_propagate_status(token, self.c) + + #Channel is by default not allowed to be propagated. But pass the test + def test_propagated(self): + self.nd.create_dataset('test', 1, 1, 1, 1.0, 1.0, 1.0, 0) + self.nd.create_project( + 'testp', 'test', 'localhost', 1, 1, 'localhost', 'Redis') + self.nd.create_channel( + 'testc', 'testp', 'test', 'image', 'uint8', 0, 500, 0) + self.nd.create_token('testt', 'testp', 'test', 1) + + self.assertEqual(self.nd.propagate('testt', 'testc'), True) + #Is it supposed to be 1? + self.assertEqual(self.nd.get_propagate_status('testt', 'testc'), '1') + + self.nd.delete_token('testt', 'testp', 'test') + self.nd.delete_channel('testc', 'testp', 'test') + self.nd.delete_project('testp', 'test') + self.nd.delete_dataset('test') + def test_kasthuri11_is_propagated(self): # token = 'kasthuri11' self.assertEqual(self.nd.get_propagate_status(self.t, self.c), '1') diff --git a/tests/test_propagate.py.old b/tests/test_propagate.py.old deleted file mode 100644 index 15cab7f..0000000 --- a/tests/test_propagate.py.old +++ /dev/null @@ -1,25 +0,0 @@ -import unittest -import ndio.remote.neurodata as neurodata -import ndio.remote.errors -import numpy -import h5py -import os - - -class TestPropagate(unittest.TestCase): - - def setUp(self): - self.nd = neurodata(check_tokens=True) - - def test_propagate_status_fails_on_bad_token(self): - token = 'this is not a token' - with self.assertRaises(ndio.remote.errors.RemoteDataNotFoundError): - self.nd.get_propagate_status(token, 'channel') - - def test_kasthuri11_is_propagated(self): - token = 'kasthuri11' - self.assertEqual(self.nd.get_propagate_status(token, 'image'), '2') - - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_ramon_import_export.py b/tests/test_ramon_import_export.py new file mode 100644 index 0000000..73cbc03 --- /dev/null +++ b/tests/test_ramon_import_export.py @@ -0,0 +1,57 @@ +import unittest +import ndio.remote.neurodata as neurodata +import ndio.ramon as ramon +import test_settings +import numpy as np +import h5py +import os +import random +import json + + +class TestRAMON(unittest.TestCase): + + def setUp(self): + self.user = test_settings.NEURODATA + self.hostname = test_settings.HOSTNAME + self.nd = neurodata(user_token=self.user, hostname=self.hostname) + + def test_json_export(self): + ##################Dynamically create ramon object + anno_type = 1 + r = ramon.AnnotationType.get_class(anno_type)() + # print json.loads(ramon.to_json(r)) + self.nd.create_dataset('test', 1, 1, 1, 1.0, 1.0, 1.0, 0) + self.nd.create_project( + 'testp', 'test', 'localhost', 1, 1, 'localhost', 'MySQL') + self.nd.delete_channel('testc', 'testp', 'test') + self.nd.create_channel('testc', 'testp', 'test', + 'annotation', 'uint32', 0, 500, 0) + self.nd.create_token('testt', 'testp', 'test', 1) + # import pdb; pdb.set_trace() + post_id = self.nd.post_ramon('testt', 'testc', r) + return_r = self.nd.get_ramon('testt', 'testc', post_id) + # import pdb; pdb.set_trace() + assertEqual(post_id, ramon.to_json(return_r)["0"]["id"]) + + self.nd.delete_ramon('testt', 'testc', r) + + self.nd.delete_token('testt', 'testp', 'test') + self.nd.delete_channel('testc', 'testp', 'test') + self.nd.delete_project('testp', 'test') + self.nd.delete_dataset('test') + + # print self.nd.get_ramon_ids('public_neuro', 'public_channel') + + + + # # #self.assertEqual( + # # # str(self.ramon_id), + # # # json.loads(ramon.to_json(r))['2']['id'] + # # #) + + + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_ramon_import_export.py.old b/tests/test_ramon_import_export.py.old index 765f553..246b5cd 100644 --- a/tests/test_ramon_import_export.py.old +++ b/tests/test_ramon_import_export.py.old @@ -1,6 +1,7 @@ import unittest import ndio.remote.neurodata as neurodata import ndio.ramon as ramon +import test_settings import numpy import h5py import os @@ -11,18 +12,32 @@ import json class TestRAMON(unittest.TestCase): def setUp(self): - self.nd = neurodata() - self.t = 'kasthuri2015_ramon_v4' - self.c = 'neurons' + self.user = test_settings.NEURODATA + self.hostname = test_settings.HOSTNAME + self.nd = neurodata(user_token=self.user, hostname=self.hostname) self.ramon_id = 1 def test_json_export(self): - r = self.nd.get_ramon(self.t, self.c, self.ramon_id) + self.nd.create_dataset('test', 1, 1, 1, 1.0, 1.0, 1.0, 0) + self.nd.create_project( + 'testp', 'test', 'localhost', 1, 1, 'localhost', 'Redis') + self.nd.delete_channel('testc', 'testp', 'test') + self.nd.create_channel( + 'testc', 'testp', 'test', 'image', 'uint8', 0, 500, 0) + self.nd.create_token('testt', 'testp', 'test', 1) + + r = self.nd.get_ramon('testt', 'testc', self.ramon_id) + self.assertEqual( str(self.ramon_id), json.loads(ramon.to_json(r))['1']['id'] ) + self.nd.delete_token('testt', 'testp', 'test') + self.nd.delete_channel('testc', 'testp', 'test') + self.nd.delete_project('testp', 'test') + self.nd.delete_dataset('test') + if __name__ == '__main__': unittest.main() diff --git a/tests/trash/.ignore_me b/tests/trash/.ignore_me deleted file mode 100644 index d6b7ef3..0000000 --- a/tests/trash/.ignore_me +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore