Skip to content

Commit

Permalink
Make api tests deterministic
Browse files Browse the repository at this point in the history
Signed-off-by: Shivam Sandbhor <[email protected]>
  • Loading branch information
sbs2001 committed Mar 6, 2021
1 parent 5420c29 commit 1debd52
Showing 1 changed file with 39 additions and 65 deletions.
104 changes: 39 additions & 65 deletions vulnerabilities/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,80 +204,54 @@ def test_bulk_packages_api(self):
]
}
response = self.client.post(
"/api/packages/bulk_search/", data=request_body, content_type="application/json"
).data
"/api/packages/bulk_search/",
data=request_body,
content_type="application/json",
).json()

expected_response = [
{},
{
"name": "datadog-api-client",
"namespace": "com.datadoghq",
"purl": "pkg:maven/com.datadoghq/[email protected]",
"qualifiers": {},
"resolved_vulnerabilities": [],
"subpath": "",
"type": "maven",
"url": "http://testserver/api/packages/3467",
"unresolved_vulnerabilities": [
OrderedDict(
[
("url", "http://testserver/api/vulnerabilities/60"),
("vulnerability_id", "CVE-2021-21331"),
(
"references",
[
OrderedDict(
[
("source", ""),
("reference_id", "GHSA-2cxf-6567-7pp6"),
(
"url",
"https://github.com/advisories/GHSA-2cxf-6567-7pp6",
),
("scores", []),
]
),
OrderedDict(
[
("source", ""),
("reference_id", ""),
(
"url",
"https://nvd.nist.gov/vuln/detail/CVE-2021-21331",
),
("scores", []),
]
),
OrderedDict(
[
("source", ""),
("reference_id", "GHSA-2cxf-6567-7pp6"),
(
"url",
"https://github.com/DataDog/datadog-api-client-java/security/advisories/GHSA-2cxf-6567-7pp6",
),
(
"scores",
[
OrderedDict(
[
("value", "LOW"),
("scoring_system", "cvssv3.1_qr"),
]
)
],
),
]
),
],
),
]
)
{
"url": "http://testserver/api/vulnerabilities/60",
"vulnerability_id": "CVE-2021-21331",
"references": [
{
"source": "",
"reference_id": "GHSA-2cxf-6567-7pp6",
"url": "https://github.com/advisories/GHSA-2cxf-6567-7pp6",
"scores": [],
},
{
"source": "",
"reference_id": "",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-21331",
"scores": [],
},
{
"source": "",
"reference_id": "GHSA-2cxf-6567-7pp6",
"url": "https://github.com/DataDog/datadog-api-client-java/security/advisories/GHSA-2cxf-6567-7pp6",
"scores": [{"value": "LOW", "scoring_system": "cvssv3.1_qr"}],
},
],
}
],
"url": "http://testserver/api/packages/3467",
"resolved_vulnerabilities": [],
"purl": "pkg:maven/com.datadoghq/[email protected]",
"type": "maven",
"namespace": "com.datadoghq",
"name": "datadog-api-client",
"version": "1.0.0-beta.7",
"subpath": "",
"qualifiers": {},
},
]
assert response == expected_response

print(response)
assert all([purl_response in expected_response for purl_response in response])

def test_invalid_request_bulk_packages(self):
error_response = {
Expand Down

0 comments on commit 1debd52

Please sign in to comment.