← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~enriqueesanchz/launchpad:fix-sossrecord-packages-order into launchpad:master

 

Enrique Sánchez has proposed merging ~enriqueesanchz/launchpad:fix-sossrecord-packages-order into launchpad:master.

Commit message:
Fix SOSSRecord.Packages ordering

This also fix a broken SVT test: Blob should be a binary string

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~enriqueesanchz/launchpad/+git/launchpad/+merge/493367
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~enriqueesanchz/launchpad:fix-sossrecord-packages-order into launchpad:master.
diff --git a/lib/lp/bugs/scripts/soss/models.py b/lib/lp/bugs/scripts/soss/models.py
index 5b8a273..ca9d202 100644
--- a/lib/lp/bugs/scripts/soss/models.py
+++ b/lib/lp/bugs/scripts/soss/models.py
@@ -60,7 +60,7 @@ class SOSSRecord(SVTRecord):
         def __lt__(self, other) -> bool:
             try:
                 self_ver = self.value.split(":")[-1].split("/")[0]
-                other_ver = self.value.split(":")[-1].split("/")[0]
+                other_ver = other.value.split(":")[-1].split("/")[0]
                 return Version(self_ver) < Version(other_ver)
             except Exception:
                 return self.value < other.value
diff --git a/lib/lp/bugs/scripts/soss/tests/sampledata/CVE-2005-1544 b/lib/lp/bugs/scripts/soss/tests/sampledata/CVE-2005-1544
index 15536ad..7590a12 100644
--- a/lib/lp/bugs/scripts/soss/tests/sampledata/CVE-2005-1544
+++ b/lib/lp/bugs/scripts/soss/tests/sampledata/CVE-2005-1544
@@ -20,13 +20,13 @@ Packages:
     Note: ''
   unpackaged:
   - Name: opencv
-    Channel: jammy:4.8.0/stable
+    Channel: jammy:4.7.0/stable
     Repositories:
     - soss-src-stable-local
     Status: ignored
     Note: ''
   - Name: opencv
-    Channel: jammy:4.7.0/stable
+    Channel: jammy:4.8.0/stable
     Repositories:
     - soss-src-stable-local
     Status: ignored
diff --git a/lib/lp/bugs/scripts/soss/tests/test_sossrecord.py b/lib/lp/bugs/scripts/soss/tests/test_sossrecord.py
index c8405d6..a4d0285 100644
--- a/lib/lp/bugs/scripts/soss/tests/test_sossrecord.py
+++ b/lib/lp/bugs/scripts/soss/tests/test_sossrecord.py
@@ -361,3 +361,22 @@ class TestSOSSRecord(TestCase):
 
         for f in files:
             self._verify_import_export_yaml(f)
+
+    def test_order_packages(self):
+        """Test that SOSSRecord.Packages are ordered by name and version."""
+        self.soss_record.packages[SOSSRecord.PackageTypeEnum.PYTHON].append(
+            SOSSRecord.Package(
+                name="ray",
+                channel=SOSSRecord.Channel("jammy:2.22.1/stable"),
+                repositories=["nvidia-pb3-python-stable-local"],
+                status=SOSSRecord.PackageStatusEnum.RELEASED,
+                note="2.22.1+soss.1",
+            ),
+        )
+
+        ordered_list = self.soss_record.packages[
+            SOSSRecord.PackageTypeEnum.PYTHON
+        ]
+        unordered_list = ordered_list[::-1]
+
+        self.assertEqual(sorted(unordered_list), ordered_list)
diff --git a/lib/lp/bugs/tests/test_importvulnerabilityjob.py b/lib/lp/bugs/tests/test_importvulnerabilityjob.py
index 6624f31..3c33886 100644
--- a/lib/lp/bugs/tests/test_importvulnerabilityjob.py
+++ b/lib/lp/bugs/tests/test_importvulnerabilityjob.py
@@ -372,7 +372,7 @@ class ImportVulnerabilityJobTests(TestCaseWithFactory):
 
     def test_run_import_soss(self):
         """Run ImportVulnerabilityJob."""
-        with open(self.soss_cve_path, encoding="utf-8") as file:
+        with open(self.soss_cve_path, "rb") as file:
             self.useFixture(
                 GitHostingFixture(
                     blob=file.read(),
@@ -412,7 +412,7 @@ class ImportVulnerabilityJobTests(TestCaseWithFactory):
 
     def test_run_import_uct(self):
         """Run ImportVulnerabilityJob."""
-        with open(self.uct_cve_path, encoding="utf-8") as file:
+        with open(self.uct_cve_path, "rb") as file:
             self.useFixture(
                 GitHostingFixture(
                     blob=file.read(),