Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kalidor opened this issue Jul 5, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@kalidor
Copy link

kalidor commented Jul 5, 2023

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 =)

@kalidor kalidor added the documentation Improvements or additions to documentation label Jul 5, 2023
@welcome-to-palo-alto-networks
Copy link

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

@kalidor kalidor changed the title Use global pc_api variable cause circle-ci or github actions to fail Suggest use PrismaClouApi object instead of global pc_api variable which cause circle-ci or github actions to fail Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant