示例#1
0
    async def test_get_objects(self, mocker: MockerFixture):
        with Path(__file__).resolve().parent.joinpath(
                "../data/s3_list_objects.json").open("r") as file:
            response = json.load(file)

        patched_s3 = mocker.patch.object(S3, "_list_objects")
        patched_s3.return_value = response

        s3 = S3()
        s3._bucket_name = "bucket1"
        assert await s3._get_objects() == [
            File(name="dir1/",
                 type=FileType.dir,
                 info="",
                 hidden=False,
                 index=0,
                 raw=ANY),
            File(
                name="dir2/",
                type=FileType.dir,
                info="",
                hidden=False,
                index=1,
                raw=None,
            ),
            File(
                name="dir3/",
                type=FileType.dir,
                info="",
                hidden=False,
                index=2,
                raw=None,
            ),
            File(
                name=".file1",
                type=FileType.file,
                info="6.0 K",
                hidden=True,
                index=3,
                raw=ANY,
            ),
            File(
                name="file2",
                type=FileType.file,
                info="151.9 K",
                hidden=False,
                index=4,
                raw=ANY,
            ),
            File(
                name="file3",
                type=FileType.file,
                info="3.5 K",
                hidden=False,
                index=5,
                raw=ANY,
            ),
        ]
示例#2
0
    def test_s3_uri(self):
        s3 = S3()
        assert s3.uri == "s3://"

        s3.path = Path("hello.com")
        assert s3.uri == "s3://hello.com"

        s3.path = Path("hello.com/yes/no")
        assert s3.uri == "s3://hello.com/yes/no"
示例#3
0
    def test_bucket_path(self):
        s3 = S3()
        assert s3.bucket_path == ""

        s3.path = Path("hello.com")
        assert s3.bucket_path == ""

        s3.path = Path("hello.com/yes")
        assert s3.bucket_path == "yes"
示例#4
0
    def test_bucket_name(self):
        s3 = S3()
        assert s3.bucket_name == ""

        s3.path = Path("hello.com")
        assert s3.bucket_name == "hello.com"

        s3.path = Path("hello.com/adsafsd")
        assert s3.bucket_name == "hello.com"
示例#5
0
    async def test_get_paths(self, mocker: MockerFixture):
        patched_s3_object = mocker.patch.object(S3, "_get_objects")
        patched_s3_bucket = mocker.patch.object(S3, "_get_buckets")

        s3 = S3()
        await s3.get_paths()
        patched_s3_object.assert_not_called()
        patched_s3_bucket.assert_called_once()

        patched_s3_object.reset_mock()
        patched_s3_bucket.reset_mock()
        s3._path = Path("hello")
        await s3.get_paths()
        patched_s3_object.assert_called_once()
        patched_s3_bucket.assert_not_called()
示例#6
0
    async def test_cd(self, mocker: MockerFixture):
        patched_s3 = mocker.patch.object(S3, "get_paths")

        s3 = S3()
        s3._path = Path("1/2")

        await s3.cd()
        assert s3._path == Path("1")

        s3._path = Path("1/2")
        await s3.cd("..")
        assert s3._path == Path("1")

        s3._path = Path("1/2")
        await s3.cd("3")
        assert s3._path == Path("1/2/3")

        s3._path = Path("1/2")
        await s3.cd("3", override=True)
        assert s3._path == Path("3")
示例#7
0
    def __init__(
        self,
        pane_id: Pane,
        spinner_config: SpinnerConfig,
        linemode_config: LineModeConfig,
        app_config: AppConfig,
        redraw: Callable[[], None],
        layout_single: Condition,
        layout_vertical: Condition,
        focus: Callable[[], Pane],
        history: History,
        set_error: Callable[[Optional[Notification]], None],
    ) -> None:
        self._s3 = S3()
        self._fs = FS()
        self._mode = PaneMode.s3
        self._loaded = False
        self._files: List[File] = []
        self._filtered_files: List[File] = []
        self._searched_indices: Optional[Dict[int, List[int]]] = None
        self._loading = True
        self._dimension_offset = 0 if not app_config.border else 2
        self._padding = app_config.padding
        self._cycle = app_config.cycle
        self._id: Pane = pane_id
        self._single_mode = layout_single
        self._vertical_mode = layout_vertical
        self._focus = Condition(lambda: focus() == self._id)
        self._selected_file_index = 0
        self._width = 0
        self._linemode = linemode_config
        self._display_hidden = True
        self._first_line = 0
        self._last_line = self._get_height() - self._first_line
        self._history = history
        self._set_error = set_error

        self._spinner = Spinner(
            loading=Condition(lambda: self._loading),
            pattern=spinner_config.pattern,
            redraw=redraw,
            delay=spinner_config.delay,
            top=spinner_config.top,
            bottom=spinner_config.bottom,
            left=spinner_config.left,
            right=spinner_config.right,
            text=spinner_config.text,
        )

        super().__init__(
            content=FloatContainer(
                content=VSplit(
                    [
                        Window(
                            content=FormattedTextControl(" "),
                            width=LayoutDimension.exact(self._padding),
                        ),
                        HSplit([
                            Window(
                                content=FormattedTextControl(
                                    self._get_pane_info),
                                height=LayoutDimension.exact(1),
                            ),
                            Window(
                                content=FormattedTextControl(
                                    self._get_formatted_files,
                                    focusable=True,
                                    show_cursor=False,
                                ),
                                width=self._get_width_dimension,
                            ),
                        ]),
                        Window(
                            content=FormattedTextControl(" "),
                            width=LayoutDimension.exact(self._padding),
                        ),
                    ],
                    height=self._get_height_dimension,
                ),
                floats=[self._spinner],
            ),
            filter=~self._single_mode | self._focus,
        )
示例#8
0
    async def test_get_buckets(self, mocker: MockerFixture):
        with Path(__file__).resolve().parent.joinpath(
                "../data/s3_list_buckets.json").open("r") as file:
            response = json.load(file)

        curr_time = datetime.now()
        for bucket in response["Buckets"]:
            bucket["CreationDate"] = curr_time

        patched_s3 = mocker.patch.object(S3, "_list_buckets")
        patched_s3.return_value = response

        s3 = S3()
        assert await s3._get_buckets() == [
            File(
                name="bucket1/",
                type=FileType.bucket,
                info=str(curr_time),
                hidden=False,
                index=0,
                raw={
                    "Name": "bucket1",
                    "CreationDate": curr_time
                },
            ),
            File(
                name="bucket2/",
                type=FileType.bucket,
                info=str(curr_time),
                hidden=False,
                index=1,
                raw={
                    "Name": "bucket2",
                    "CreationDate": curr_time
                },
            ),
            File(
                name="bucket3/",
                type=FileType.bucket,
                info=str(curr_time),
                hidden=False,
                index=2,
                raw={
                    "Name": "bucket3",
                    "CreationDate": curr_time
                },
            ),
            File(
                name="bucket4/",
                type=FileType.bucket,
                info=str(curr_time),
                hidden=False,
                index=3,
                raw={
                    "Name": "bucket4",
                    "CreationDate": curr_time
                },
            ),
            File(
                name="bucket5/",
                type=FileType.bucket,
                info=str(curr_time),
                hidden=False,
                index=4,
                raw={
                    "Name": "bucket5",
                    "CreationDate": curr_time
                },
            ),
        ]