Skip to content

Suggest use PrismaClouApi object instead of global pc_api variable which cause circle-ci or github actions to fail #153

@kalidor

Description

@kalidor

First of all: thanks for this SDK.

Documentation link

README.md and all scripts examples use pc_api which is instantiate internally.

Describe the problem

We use this SDK in our project, and use circle-ci and github actions to perform lint, tests and build.
One of ours tests check authentication failure. In your SDK, it raises a SystemExit and the test do not catch the expected exception.

Our code was as below:

from prismacloud.api import pc_api
pc_api.configure(
  "url": config.url,
  "identity": config.client_id,
  "secret": config.client_secret,
)
try:
    self.prismacloud.statuses_intelligence()
except SystemExit as exc:
    raise ConfigurationError("PrismaCloud invalid configuration") from exc

our test:

if expected_error:
    with pytest.raises(Exception) as excinfo:  # noqa: PT011
        cli_run(**kwargs)

The error on both circle-ci and GHA:

if expected_error:
>               with pytest.raises(Exception) as excinfo:  # noqa: PT011
E               Failed: DID NOT RAISE <class 'Exception'>

So the test expect an Exception which he doesn't get.
ℹ️ locally the tests run fine. Tests on circle-ic and GHA are run differently it seems...
This is potentially due to the use of pc_api as global variable.

Suggested fix

Suggest to use the following, if user is developing something more complex than a simple script if it's supposed to be tested on circle-ci and/or GHA:

from prismacloud.api import PrismaCloudAPI
pc_api = PrismaCloudApi()

It will save some time to find why this is failing =)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions