Example #1
0
    def test_gets_file(self, tmpdir):
        with open(str(tmpdir.join("file.txt")), "wb") as fp:
            fp.write(b"my test file contents")

        storage = LocalFileStorage(str(tmpdir))
        file_object = storage.get("file.txt")
        assert file_object.read() == b"my test file contents"
Example #2
0
 def test_stores_two_files(self, tmpdir):
     storage = LocalFileStorage(str(tmpdir))
     storage.store("foo/first.txt", io.BytesIO(b"First Test File!"))
     storage.store("foo/second.txt", io.BytesIO(b"Second Test File!"))
     with open(os.path.join(str(tmpdir), "foo/first.txt"), "rb") as fp:
         assert fp.read() == b"First Test File!"
     with open(os.path.join(str(tmpdir), "foo/second.txt"), "rb") as fp:
         assert fp.read() == b"Second Test File!"
Example #3
0
    def test_stores_file(self, tmpdir):
        filename = str(tmpdir.join("testfile.txt"))
        with open(filename, "wb") as fp:
            fp.write(b"Test File!")

        storage_dir = str(tmpdir.join("storage"))
        storage = LocalFileStorage(storage_dir)
        storage.store("foo/bar.txt", filename)

        with open(os.path.join(storage_dir, "foo/bar.txt"), "rb") as fp:
            assert fp.read() == b"Test File!"
Example #4
0
 def test_create_service(self):
     request = pretend.stub(
         registry=pretend.stub(
             settings={"files.path": "/the/one/two/"},
         ),
     )
     storage = LocalFileStorage.create_service(None, request)
     assert storage.base == "/the/one/two/"
Example #5
0
    def test_stores_two_files(self, tmpdir):
        filename1 = str(tmpdir.join("testfile1.txt"))
        with open(filename1, "wb") as fp:
            fp.write(b"First Test File!")

        filename2 = str(tmpdir.join("testfile2.txt"))
        with open(filename2, "wb") as fp:
            fp.write(b"Second Test File!")

        storage_dir = str(tmpdir.join("storage"))
        storage = LocalFileStorage(storage_dir)
        storage.store("foo/first.txt", filename1)
        storage.store("foo/second.txt", filename2)

        with open(os.path.join(storage_dir, "foo/first.txt"), "rb") as fp:
            assert fp.read() == b"First Test File!"

        with open(os.path.join(storage_dir, "foo/second.txt"), "rb") as fp:
            assert fp.read() == b"Second Test File!"
Example #6
0
 def test_raises_when_file_non_existant(self, tmpdir):
     storage = LocalFileStorage(str(tmpdir))
     with pytest.raises(FileNotFoundError):
         storage.get("file.txt")
Example #7
0
 def test_basic_init(self):
     storage = LocalFileStorage("/foo/bar/")
     assert storage.base == "/foo/bar/"
Example #8
0
 def test_stores_file(self, tmpdir):
     storage = LocalFileStorage(str(tmpdir))
     storage.store("foo/bar.txt", io.BytesIO(b"Test File!"))
     with open(os.path.join(str(tmpdir), "foo/bar.txt"), "rb") as fp:
         assert fp.read() == b"Test File!"