diff --git a/tests/test_file.py b/tests/test_file.py index 013a470d21dd62b278ed84d8aa4047e31f84c79d..bb17d8da6a522cd1e3cb3853d436e0adb3577975 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -5,6 +5,8 @@ # # Copyright (C) 2018 Research Group Biomedical Physics, # Max-Planck-Institute for Dynamics and Self-Organization Göttingen +# Copyright (C) 2019 IndiScale GmbH (info@indiscale.com) +# Copyright (C) 2019 Daniel Hornung (d.hornung@indiscale.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -35,7 +37,7 @@ from nose.tools import (assert_equal, assert_false, # @UnresolvedImport assert_is_not_none, assert_raises, assert_true, nottest, with_setup) -from caosdb import execute_query, get_config, get_connection +from caosdb import execute_query, get_config, get_connection, Info from caosdb.common import models from caosdb.exceptions import EntityError from caosdb.utils.checkFileSystemConsistency import runCheck @@ -50,13 +52,10 @@ def setup(): upload_file.write("hello world\n") upload_file.close() os.mkdir("testfolder") - os.mkdir("testfolder/subfolder") - upload_file = open("testfolder/test1.dat", "w") - upload_file.write("hello world\n") - upload_file.close() - upload_file = open("testfolder/subfolder/test2.dat", "w") - upload_file.write("hello world\n") - upload_file.close() + with open("testfolder/test1.dat", "w") as upload_file: + upload_file.write("hello world\n") + with open("testfolder/subfolder/test2.dat", "w") as upload_file: + upload_file.write("hello world\n") def teardown(): @@ -79,7 +78,7 @@ def teardown(): @with_setup(setup, teardown) -def test_file_with_empty_space(): +def test_file_with_space(): file_ = models.File(name="TestFile", description="Testfile Desc", path="testfiles/test file with spaces.dat", @@ -696,3 +695,10 @@ def test_thumbnails(): # TODO find a better way to check this assert_equal(xml[1][0].get("thumbnail")[-41:], "/Thumbnails/testfiles/thumbnails_test.dat") + + +@with_setup(setup, teardown) +def test_empty_folder(): + """The file system has has problems with empty subfolders.""" + os.mkdir("testfolder/subfolder") + Info() diff --git a/tests/test_webinterface.py b/tests/test_webinterface.py index c4f622cdf2e5b4f75f800980b91775bee265c52e..b9ba13f083731f3b83a19c3c19fcbb79da84d4bc 100644 --- a/tests/test_webinterface.py +++ b/tests/test_webinterface.py @@ -5,6 +5,7 @@ # # Copyright (C) 2019 Timm Fitschen (t.fitschen@indiscale.com) # Copyright (C) 2019 IndiScale GmbH +# Copyright (C) 2019 Daniel Hornung (d.hornung@indiscale.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -25,35 +26,33 @@ @author: Timm Fitschen (t.fitschen@indiscale.com) """ -import caosdb as c from urllib import request from urllib.error import HTTPError import ssl import re +import caosdb as c import pytest + def test_webinterface_version_build(): + """Tests if a correct build number is created and returned.""" url = c.get_config().get("Connection", "url") context = ssl.SSLContext() context.verify_mode = ssl.CERT_NONE - buildNumber = request.urlopen(url + "webinterface/version/build", - context=context).read().decode("utf8") - assert re.match(r"\d+", buildNumber) + build_number = request.urlopen(url + "webinterface/version/build", + context=context).read().decode("utf8") + assert re.match(r"\d+", build_number) + def test_webinterface(): + """Tests if a 404 error is correctly returned.""" url = c.get_config().get("Connection", "url") context = ssl.SSLContext() context.verify_mode = ssl.CERT_NONE - buildNumber = request.urlopen(url + "webinterface/version/build", - context=context).read().decode("utf8") - with pytest.raises(HTTPError) as e404: request.urlopen(url + "webinterface/..", context=context) assert e404.value.code == 404 - - -