def test_create_service(self): request = pretend.stub( registry=pretend.stub( settings={"docs.path": "/the/one/two/"}, ), ) storage = LocalDocsStorage.create_service(None, request) assert storage.base == "/the/one/two/"
def test_delete_by_prefix(self, tmpdir): storage_dir = str(tmpdir.join("storage")) os.makedirs(os.path.join(storage_dir, 'foo'), exist_ok=True) os.makedirs(os.path.join(storage_dir, 'bar'), exist_ok=True) filename0 = str(tmpdir.join("storage/foo/testfile0.txt")) with open(filename0, "wb") as fp: fp.write(b"Zeroth Test File!") filename1 = str(tmpdir.join("storage/foo/testfile1.txt")) with open(filename1, "wb") as fp: fp.write(b"First Test File!") filename2 = str(tmpdir.join("storage/bar/testfile2.txt")) with open(filename2, "wb") as fp: fp.write(b"Second Test File!") storage = LocalDocsStorage(storage_dir) storage.remove_by_prefix('foo') assert not os.path.exists(os.path.join(storage_dir, 'foo')) with open(os.path.join(storage_dir, "bar/testfile2.txt"), "rb") as fp: assert fp.read() == b"Second Test File!"
def test_delete_already_gone(self, tmpdir): storage_dir = str(tmpdir.join("storage")) storage = LocalDocsStorage(storage_dir) response = storage.remove_by_prefix('foo') assert response is None