mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 20:11:30 +00:00
test(services): utilities for checking and alterning testfiles
This commit is contained in:
parent
fc58d6a5ca
commit
2ad518499e
|
@ -177,17 +177,25 @@ def get_testfile_bodies(service: DummyService):
|
||||||
testfiles: List[str] = []
|
testfiles: List[str] = []
|
||||||
for folder in service.get_folders():
|
for folder in service.get_folders():
|
||||||
files = listdir(folder)
|
files = listdir(folder)
|
||||||
|
files = [path.join(folder, file) for file in files]
|
||||||
testfiles.extend(files)
|
testfiles.extend(files)
|
||||||
bodies = []
|
bodies = {}
|
||||||
for f in testfiles:
|
for f in testfiles:
|
||||||
pass
|
with open(f, "r") as file:
|
||||||
|
bodies[f] = file.read()
|
||||||
with open("/usr/tsr.txt") as file:
|
|
||||||
content = file.read()
|
|
||||||
bodies.append(content)
|
|
||||||
return bodies
|
return bodies
|
||||||
|
|
||||||
|
|
||||||
|
def is_original_files(service: DummyService):
|
||||||
|
# For use in restoration tests mostly
|
||||||
|
|
||||||
|
paths = testfile_paths(service.get_folders())
|
||||||
|
return get_testfile_bodies(service) == {
|
||||||
|
paths[0]: TESTFILE_BODY,
|
||||||
|
paths[1]: TESTFILE2_BODY,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def raw_dummy_service(tmpdir) -> DummyService:
|
def raw_dummy_service(tmpdir) -> DummyService:
|
||||||
dirnames = ["test_service", "also_test_service"]
|
dirnames = ["test_service", "also_test_service"]
|
||||||
|
@ -197,20 +205,22 @@ def raw_dummy_service(tmpdir) -> DummyService:
|
||||||
makedirs(service_dir)
|
makedirs(service_dir)
|
||||||
service_dirs.append(service_dir)
|
service_dirs.append(service_dir)
|
||||||
|
|
||||||
|
paths = testfile_paths(service_dirs)
|
||||||
bodies = [TESTFILE_BODY, TESTFILE2_BODY]
|
bodies = [TESTFILE_BODY, TESTFILE2_BODY]
|
||||||
|
|
||||||
for fullpath, body in zip(testfile_paths(service_dirs), bodies):
|
# Just touching first, filling is separate
|
||||||
|
for fullpath in paths:
|
||||||
with open(fullpath, "w") as file:
|
with open(fullpath, "w") as file:
|
||||||
file.write(TESTFILE2_BODY)
|
file.write("")
|
||||||
|
|
||||||
paths = testfile_paths
|
|
||||||
|
|
||||||
# we need this to not change get_folders() much
|
|
||||||
class TestDummyService(DummyService, folders=service_dirs):
|
class TestDummyService(DummyService, folders=service_dirs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
service = TestDummyService()
|
service = TestDummyService()
|
||||||
# assert pickle.dumps(service) is not None
|
write_testfile_bodies(service, bodies)
|
||||||
|
|
||||||
|
assert is_original_files(service)
|
||||||
|
|
||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue