Skip to content

Commit

Permalink
Enable test_models.py and fix failing tests #1228
Browse files Browse the repository at this point in the history
Reference: #1228

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
  • Loading branch information
johnmhoran committed Nov 22, 2023
1 parent 4ce5d51 commit f1a0530
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
1 change: 0 additions & 1 deletion vulnerabilities/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def no_rmtree(monkeypatch):
# Step 2: Run test for importer only if it is activated (pytestmark = pytest.mark.skipif(...))
# Step 3: Migrate all the tests
collect_ignore = [
"test_models.py",
"test_package_managers.py",
"test_ruby.py",
"test_rust.py",
Expand Down
62 changes: 34 additions & 28 deletions vulnerabilities/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from packageurl import PackageURL
from univers import versions
from univers.version_range import RANGE_CLASS_BY_SCHEMES
from univers.version_range import AlpineLinuxVersionRange

from vulnerabilities import models
from vulnerabilities.models import Alias
Expand Down Expand Up @@ -62,8 +63,9 @@ def test_vulnerability_save_without_vulnerability_id(self):
== 1
)

@pytest.mark.django_db
def test_cwe_not_present_in_weaknesses_db(self):
w1 = models.Weakness.objects.create(name="189")
w1 = models.Weakness.objects.create(cwe_id=189)
assert w1.weakness is None
assert w1.name is ""
assert w1.description is ""
Expand Down Expand Up @@ -239,7 +241,7 @@ def test_fixed_package_details(self):
name="redis",
version="4.1.1",
),
"closest_non_vulnerable": PackageURL(
"next_non_vulnerable": PackageURL(
type="pypi",
name="redis",
version="5.0.0b1",
Expand All @@ -255,42 +257,45 @@ def test_fixed_package_details(self):
"vulnerabilities": [
{
"vulnerability": self.vuln_VCID_g2fu_45jw_aaan,
"fixed_by_purl": PackageURL(
type="pypi",
namespace=None,
name="redis",
version="4.3.6",
qualifiers={},
subpath=None,
),
"fixed_by_purl_vulnerabilities": [self.vuln_VCID_rqe1_dkmg_aaad],
"fixed_by_package_details": [
{
"fixed_by_purl": PackageURL(
type="pypi",
namespace=None,
name="redis",
version="4.3.6",
qualifiers={},
subpath=None,
),
"fixed_by_purl_vulnerabilities": [self.vuln_VCID_rqe1_dkmg_aaad],
}
],
"fixed_by_purl": [],
"fixed_by_purl_vulnerabilities": [],
},
{
"vulnerability": self.vuln_VCID_rqe1_dkmg_aaad,
"fixed_by_purl": PackageURL(
type="pypi",
namespace=None,
name="redis",
version="5.0.0b1",
qualifiers={},
subpath=None,
),
"fixed_by_package_details": [
{
"fixed_by_purl": PackageURL(
type="pypi",
namespace=None,
name="redis",
version="5.0.0b1",
qualifiers={},
subpath=None,
),
"fixed_by_purl_vulnerabilities": [],
}
],
"fixed_by_purl": [],
"fixed_by_purl_vulnerabilities": [],
},
],
}

assert searched_for_package_details == package_details

assert searched_for_package_details.get("closest_non_vulnerable") == PackageURL(
type="pypi",
namespace=None,
name="redis",
version="5.0.0b1",
qualifiers={},
subpath=None,
)

assert searched_for_package_details.get("latest_non_vulnerable") == PackageURL(
type="pypi",
namespace=None,
Expand Down Expand Up @@ -401,6 +406,7 @@ def test_univers_version_class(self):
pypi_package_version = RANGE_CLASS_BY_SCHEMES[pypi_package.type].version_class
assert pypi_package_version == versions.PypiVersion

RANGE_CLASS_BY_SCHEMES["alpine"] = AlpineLinuxVersionRange
alpine_version = RANGE_CLASS_BY_SCHEMES["alpine"].version_class
assert alpine_version == versions.AlpineLinuxVersion

Expand Down

0 comments on commit f1a0530

Please sign in to comment.