Skip to content
Snippets Groups Projects
Verified Commit 5ddc285b authored by Timm Fitschen's avatar Timm Fitschen
Browse files

TST: fix

parent 8c90d14a
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ from random import randint ...@@ -33,6 +33,7 @@ from random import randint
from sys import maxsize as maxint from sys import maxsize as maxint
from lxml import etree from lxml import etree
from pytest import raises
from nose.tools import (assert_equal, assert_false, # @UnresolvedImport from nose.tools import (assert_equal, assert_false, # @UnresolvedImport
assert_is_not_none, assert_raises, assert_true, assert_is_not_none, assert_raises, assert_true,
nottest, with_setup) nottest, with_setup)
...@@ -231,8 +232,8 @@ def test_file6(): ...@@ -231,8 +232,8 @@ def test_file6():
file="test.dat") file="test.dat")
file_.insert() file_.insert()
assert_is_not_none(file_.id) assert file_.id is not None
assert_true(file_.is_valid()) assert file_.is_valid()
# pickup_folder # pickup_folder
# and try to store it to testfiles2/ # and try to store it to testfiles2/
...@@ -256,9 +257,12 @@ def test_file6(): ...@@ -256,9 +257,12 @@ def test_file6():
name="PickupTestfolder", name="PickupTestfolder",
description="Pickup test folder desc", description="Pickup test folder desc",
path="testfiles2/", path="testfiles2/",
pickup="path") pickup=path)
assert_raises(EntityError, folder_.insert) with raises(EntityError) as cm:
folder_.insert()
errors = cm.value.entity.get_errors()
assert errors[0].description == 'This target path does already exist.'
finally: finally:
try: try:
folder_.delete() folder_.delete()
...@@ -345,39 +349,35 @@ def test_consistency_file_was_modified(): ...@@ -345,39 +349,35 @@ def test_consistency_file_was_modified():
file="test.dat") file="test.dat")
file_.insert() file_.insert()
assert_is_not_none(file_.id) assert file_.id is not None
assert_true(file_.is_valid()) assert file_.is_valid()
# run consistency check (no consistency warning) # run consistency check (no consistency warning)
c = runCheck(None, None) c = runCheck(None, None)
assert_is_not_none(c.messages["Info", 0]) assert c.messages["Info", 0] is not None
assert_equal(c.messages["Info", 0][0], "File system is consistent.") assert c.messages["Info", 0][0] == "File system is consistent."
# run consistency check with modified warning) # when in debug mode, the server offers a special option
# TODO fix
# This smells badly. The argument is meant to transport the location
# that is checked. Understanding of the code is difficult.
# #
# TODO reactivate if meaningful # '-c FILE_WAS_MODIFIED'
# Why is it expeced that the file was modified? #
#c = runCheck(None, "-c FILE_WAS_MODIFIED") # which simulates a modified file.
# print(c.messages) c = runCheck(None, "-c FILE_WAS_MODIFIED")
#assert_is_not_none(c.messages["Error", 0])
# assert_equal( assert c.messages["Error", 0] is not None
#c.messages["Error", 0][0], assert c.messages["Error", 0][0] == 'debug/test_file_storage_consistency: File was modified.'
# 'debug/test_file_storage_consistency: File was modified.')
# download file again and check if it is still the same (just to be # download file again and check if it is still the same (just to be
# sure that the server only simulated the consistency breach # sure that the server only simulated the consistency breach
d = open(file_.download(target="test.dat.tmp"), "r") d = open(file_.download(target="test.dat.tmp"), "r")
r = d.read() r = d.read()
assert_equal(r, "hello world\n") assert r == "hello world\n"
# run a passing check again # run a passing check again
c = runCheck(None, None) c = runCheck(None, None)
assert_is_not_none(c.messages["Info", 0]) assert c.messages["Info", 0] is not None
assert_equal(c.messages["Info", 0][0], "File system is consistent.") assert c.messages["Info", 0][0] == "File system is consistent."
finally: finally:
# clean up file record # clean up file record
...@@ -411,34 +411,29 @@ def test_consistency_file_does_not_exist(): ...@@ -411,34 +411,29 @@ def test_consistency_file_does_not_exist():
file="test.dat") file="test.dat")
file_.insert() file_.insert()
assert_is_not_none(file_.id) assert file_.id is not None
assert_true(file_.is_valid()) assert file_.is_valid()
c = runCheck(None, "/debug/") c = runCheck(None, "/debug/")
assert_is_not_none(c.messages["Info", 0]) assert c.messages["Info", 0] is not None
assert_equal(c.messages["Info", 0][0], assert c.messages["Info", 0][0] == "File system below debug/ is consistent."
"File system below debug/ is consistent.")
# TODO fix # when in debug mode, the server offers a special option
# This smells badly. The argument is meant to transport the location #
# that is checked. Understanding of the code is difficult. # '-c FILE_DOES_NOT_EXIST'
# #
# TODO reactivate if meaningful # which simulates a accidentially removed file.
# Furthermore, I have no clue, why the file that was just successfully c = runCheck(None, "-c FILE_DOES_NOT_EXIST")
# inserted should lead to a FILE_DOES_NOT_EXIST error. assert c.messages["Error", 0] is not None
#c = runCheck(None, "-c FILE_DOES_NOT_EXIST") assert c.messages["Error", 0][0] == 'debug/test_file_storage_consistency: File does not exist.'
#assert_is_not_none(c.messages["Error", 0])
# assert_equal(
# c.messages["Error", 0][0],
# 'debug/test_file_storage_consistency: File does not exist.')
with open(file_.download(target="test.dat.tmp"), "r") as d: with open(file_.download(target="test.dat.tmp"), "r") as d:
r = d.read() r = d.read()
assert_equal(r, "hello world\n") assert r == "hello world\n"
c = runCheck(None, None) c = runCheck(None, None)
assert_is_not_none(c.messages["Info", 0]) assert c.messages["Info", 0] is not None
assert_equal(c.messages["Info", 0][0], "File system is consistent.") assert c.messages["Info", 0][0] == "File system is consistent."
finally: finally:
try: try:
...@@ -462,23 +457,21 @@ def test_consistency_file_does_not_exist(): ...@@ -462,23 +457,21 @@ def test_consistency_file_does_not_exist():
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_consistency_unknown_file(): def test_consistency_unknown_file():
c = runCheck(None, None) c = runCheck(None, None)
assert_is_not_none(c.messages["Info", 0]) assert c.messages["Info", 0] is not None
assert_equal(c.messages["Info", 0][0], "File system is consistent.") assert c.messages["Info", 0][0] == "File system is consistent."
# TODO fix # when in debug mode, the server offers a special option
# This smells badly. The argument is meant to transport the location #
# that is checked. Understanding of the code is difficult. # '-c UNKNOWN_FILE'
# #
# TODO reactivate if meaningful # which simulates an unknown file.
# It is unclear what this is supposed to test. How should a file be created c = runCheck(None, "-c UNKNOWN_FILE")
# under debug. Does not look meaningful. assert c.messages["Warning", 0] is not None
#c = runCheck(None, "-c UNKNOWN_FILE") assert c.messages["Warning", 0][0] == 'debug/: Unknown file.'
#assert_is_not_none(c.messages["Warning", 0])
#assert_equal(c.messages["Warning", 0][0], 'debug/: Unknown file.')
#c = runCheck(None, None) c = runCheck(None, None)
#assert_is_not_none(c.messages["Info", 0]) assert c.messages["Info", 0] is not None
#assert_equal(c.messages["Info", 0][0], "File system is consistent.") assert c.messages["Info", 0][0] == "File system is consistent."
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -693,48 +686,48 @@ def test_insert_files_in_dir(): ...@@ -693,48 +686,48 @@ def test_insert_files_in_dir():
except BaseException: except BaseException:
pass pass
# TODO reactivate
# No files are insered currently eventhough the other InserFilesInDir tests @with_setup(setup, teardown)
# work. What is the current behaviour of the regexp? def test_insert_files_in_dir_regex():
# @with_setup(setup, teardown) path = get_config().get("IntegrationTests",
# def test_insert_files_in_dir_regex(): "test_files.test_insert_files_in_dir.local") + "testfolder/"
# # TODO path_on_server = get_config().get("IntegrationTests",
# path = get_config().get("IntegrationTests", "test_files.test_insert_files_in_dir.server") + "testfolder/"
# "test_files.test_insert_files_in_dir.local") + "testfolder/" try:
# path_on_server = get_config().get("IntegrationTests", os.makedirs(path)
# "test_files.test_insert_files_in_dir.server") + "testfolder/" os.makedirs(path + "subfolder/")
# try: test_file1 = open(path + "subfolder/test_dont_insert.dat", "w")
# os.makedirs(path) test_file1.write("hello world\n")
# os.makedirs(path + "subfolder/") test_file1.close()
# test_file1 = open(path + "subfolder/test.dat", "w")
# test_file1.write("hello world\n") test_file2 = open(path + "subfolder/test_insert.dat", "w")
# test_file1.close() test_file2.write("hello world2\n")
# test_file2.close()
# test_file2 = open(path + "subfolder/test2.dat", "w")
# test_file2.write("hello world2\n") c = models.Container()
# test_file2.close() c.retrieve(
# unique=False,
# c = models.Container() raise_exception_on_error=False,
# c.retrieve( flags={
# unique=False, "InsertFilesInDir": "-e dont_insert " +
# raise_exception_on_error=False, path_on_server})
# flags={ assert c.messages["Warning", 2] is not None
# "InsertFilesInDir": "-e test " + assert c.messages["Warning", 2][0] == "Explicitly excluded file: {}".format(
# path_on_server}) path_on_server + "subfolder/test_dont_insert.dat")
# assert c.messages["Warning", 2] is not None
# assert c.messages["Warning", 2][0] == "Explicitly excluded directory or file: {}".format( # the other has been inserted
# path_on_server[:-1]) assert len(c) == 1
# assert len(c) == 0 assert c[0].name == "test_insert.dat"
#
# finally: finally:
# try: try:
# c.delete() c.delete()
# except BaseException: except BaseException:
# pass pass
# try: try:
# shutil.rmtree(path) shutil.rmtree(path)
# except BaseException: except BaseException:
# pass pass
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -752,8 +745,5 @@ def test_thumbnails(): ...@@ -752,8 +745,5 @@ def test_thumbnails():
reconnect=True).read() reconnect=True).read()
print(body) print(body)
xml = etree.fromstring(body) xml = etree.fromstring(body)
assert xml.xpath('/Response') assert xml.xpath('/Response/dir/file')[0].get(
assert xml.xpath('/Response/dir/file') "thumbnail")[-41:] == "/Thumbnails/testfiles/thumbnails_test.dat"
# TODO find a better way to check this
assert_equal(xml[1][0].get("thumbnail")[-41:],
"/Thumbnails/testfiles/thumbnails_test.dat")
...@@ -61,7 +61,7 @@ def test_file_system_returns_ids(): ...@@ -61,7 +61,7 @@ def test_file_system_returns_ids():
body = resp.read() body = resp.read()
print(body) print(body)
print(type(body)) print(type(body))
search = "<file id=\"" + str(file_.id) + "\" name=\"test.dat\"" search = "id=\"" + str(file_.id) + "\""
print(search) print(search)
assert_true(search in str(body)) assert_true(search in str(body))
......
[tox] [tox]
envlist= py37 envlist=py36 py37 py38
skip_missing_interpreters = true skip_missing_interpreters = true
[testenv] [testenv]
setenv = PASSWORD_STORE_DIR = {env:HOME}/.password-store setenv = PASSWORD_STORE_DIR = {env:HOME}/.password-store
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment