<filename>specs/secure/scanning/scanning_vulnerability_spec.py
import os

from expects import equal, expect, have_keys
from mamba import before, context, description, it

from sdcclient import SdScanningClient
from specs import be_successful_api_call

with description("Scanning vulnerability details", "integration") as self:
    with before.each:
        self.client = SdScanningClient(sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"),
                                       token=os.getenv("SDC_SECURE_TOKEN"))

    with context("when retrieving a simple vulnerability"):
        with it("retrieves the vulnerability details correctly if exists"):
            vuln_id = "VULNDB-140292"
            ok, res = self.client.get_vulnerability_details(id=vuln_id)

            expect((ok, res)).to(be_successful_api_call)
            expect(res).to(
                have_keys("description", "severity", "vendor_data", "nvd_data", "references",
                          "affected_packages", id=equal(vuln_id))
            )

        with it("fails if it does not exist"):
            non_existing_vuln_id = "VULNDB-NOEXISTS"
            ok, res = self.client.get_vulnerability_details(id=non_existing_vuln_id)

            expect((ok, res)).to_not(be_successful_api_call)
            expect(res).to(equal(f"Vulnerability {non_existing_vuln_id} was not found"))

        with it("fails if no id was provided"):
            non_existing_vuln_id = None
            ok, res = self.client.get_vulnerability_details(id=non_existing_vuln_id)

            expect((ok, res)).to_not(be_successful_api_call)
            expect(res).to(equal("No vulnerability ID provided"))

<filename>specs/secure/scanning/scanning_vulnerability_spec.py
import os

from expects import equal, expect, have_keys
from mamba import before, context, description, it

from sdcclient import SdScanningClient
from specs import be_successful_api_call

with description("Scanning vulnerability details", "integration") as self:
    with before.each:
        self.client = SdScanningClient(sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"),
                                       token=os.getenv("SDC_SECURE_TOKEN"))

    with context("when retrieving a simple vulnerability"):
        with it("retrieves the vulnerability details correctly if exists"):
            vuln_id = "VULNDB-140292"
            ok, res = self.client.get_vulnerability_details(id=vuln_id)

            expect((ok, res)).to(be_successful_api_call)
            expect(res).to(
                have_keys("description", "severity", "vendor_data", "nvd_data", "references",
                          "affected_packages", id=equal(vuln_id))
            )

        with it("fails if it does not exist"):
            non_existing_vuln_id = "VULNDB-NOEXISTS"
            ok, res = self.client.get_vulnerability_details(id=non_existing_vuln_id)

            expect((ok, res)).to_not(be_successful_api_call)
            expect(res).to(equal(f"Vulnerability {non_existing_vuln_id} was not found"))

        with it("fails if no id was provided"):
            non_existing_vuln_id = None
            ok, res = self.client.get_vulnerability_details(id=non_existing_vuln_id)

            expect((ok, res)).to_not(be_successful_api_call)
            expect(res).to(equal("No vulnerability ID provided"))
