prismacloud-api-python icon indicating copy to clipboard operation
prismacloud-api-python copied to clipboard

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

Open kalidor opened this issue 2 years ago • 1 comments

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. :information_source: 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 =)

kalidor avatar Jul 05 '23 09:07 kalidor

:tada: Thanks for opening your first issue here! Welcome to the community!