Skip to content

Storage

FileStorage

Bases: Protocol

Protocol for representing required file uploader interfaces.

Source code in pytest_qaseio/storage.py
 8
 9
10
11
12
13
class FileStorage(typing.Protocol):
    """Protocol for representing required file uploader interfaces."""

    def save_file_obj(self, content: bytes, filename: str) -> str:
        """Upload file to storage and return URL."""
        ...

save_file_obj(content, filename)

Upload file to storage and return URL.

Source code in pytest_qaseio/storage.py
11
12
13
def save_file_obj(self, content: bytes, filename: str) -> str:
    """Upload file to storage and return URL."""
    ...

QaseFileStorage

Upload files to Qase S3 bucket as attachment.

Source code in pytest_qaseio/storage.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class QaseFileStorage:
    """Upload files to Qase S3 bucket as attachment."""

    def __init__(
        self,
        qase_token: str,
        qase_project_code: str,
    ) -> None:
        """Prepare ApiClient for qase io using credentials."""
        self._client = ApiClient(
            configuration=qaseio_config.Configuration(
                api_key={
                    "TokenAuth": qase_token,
                },
            ),
        )
        self._project_code = qase_project_code

    def save_file_obj(self, content: bytes, filename: str) -> str:
        """Upload file to Qase.io S3 bucket via attachment API."""
        attachment_response_result = (
            AttachmentsApi(
                self._client,
            )
            .upload_attachment(
                code=self._project_code,
                file=[content],
            )
            .result
        )
        assert attachment_response_result is not None  # noqa: S101

        return typing.cast(str, attachment_response_result[0].url)

__init__(qase_token, qase_project_code)

Prepare ApiClient for qase io using credentials.

Source code in pytest_qaseio/storage.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def __init__(
    self,
    qase_token: str,
    qase_project_code: str,
) -> None:
    """Prepare ApiClient for qase io using credentials."""
    self._client = ApiClient(
        configuration=qaseio_config.Configuration(
            api_key={
                "TokenAuth": qase_token,
            },
        ),
    )
    self._project_code = qase_project_code

save_file_obj(content, filename)

Upload file to Qase.io S3 bucket via attachment API.

Source code in pytest_qaseio/storage.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def save_file_obj(self, content: bytes, filename: str) -> str:
    """Upload file to Qase.io S3 bucket via attachment API."""
    attachment_response_result = (
        AttachmentsApi(
            self._client,
        )
        .upload_attachment(
            code=self._project_code,
            file=[content],
        )
        .result
    )
    assert attachment_response_result is not None  # noqa: S101

    return typing.cast(str, attachment_response_result[0].url)