Exemple #1
0
    def test_upload_files_called_with_single_file(self):
        datastore = MagicMock()
        path = "foo/bar"
        assert not os.path.isdir(path)
        task = DatastoreUpload(datastore=datastore, path=path)

        task.run()

        assert datastore.upload_files.call_args[1]["files"] == [path]
Exemple #2
0
    def test_upload_files_called_with_multiple_files(self):
        datastore = MagicMock()
        path = ["foo/bar", "my/path"]

        assert not any([os.path.isdir(path_item) for path_item in path])
        task = DatastoreUpload(datastore=datastore, path=path)

        task.run()

        assert datastore.upload_files.call_args[1]["files"] == path
Exemple #3
0
    def test_upload_called_with_directory(self, monkeypatch):
        mocked_isdir = MagicMock()
        mocked_isdir.return_value = True
        monkeypatch.setattr("os.path.isdir", mocked_isdir)

        datastore = MagicMock()
        path = "foo/bar"

        task = DatastoreUpload(datastore=datastore, path=path)

        task.run()

        assert datastore.upload.call_args[1]["src_dir"] == path
Exemple #4
0
    def test_missing_datastore_raises_error(self):
        datastore = MagicMock()
        task = DatastoreUpload(datastore=datastore)

        with pytest.raises(ValueError, match="A path must be provided."):
            task.run()
Exemple #5
0
    def test_missing_datastore_raises_error(self):
        path = ""
        task = DatastoreUpload(path=path)

        with pytest.raises(ValueError, match="A datastore must be provided."):
            task.run()
Exemple #6
0
    def test_initialization(self):
        relative_root = "/foo/bar"
        task = DatastoreUpload(relative_root=relative_root)

        assert task.relative_root == relative_root