[extensions-web/deploy] extensions: use safer "best" version detection.



commit 6fb746ececd503d2d773d3baf5351ffeb88b8c62
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Thu Mar 28 21:36:33 2019 +0400

    extensions: use safer "best" version detection.
    
    Do not try to provide latest extension version if minimum Shell version
    supported by extension is lower than requested Shell version.
    Instead let's choose extension version that support latest Shell version
    older than requested.
    
    Bug: https://gitlab.gnome.org/Infrastructure/extensions-web/issues/82

 sweettooth/extensions/tests.py | 27 ++++++++++++++++++++-------
 sweettooth/extensions/views.py |  3 +++
 2 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index 9fcc920..a0bd669 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -657,22 +657,35 @@ class QueryExtensionsTest(BasicUserTestCase, TestCase):
         extension = self.create_extension("extension")
 
         v = models.ExtensionVersion.objects.create(extension=extension, status=models.STATUS_ACTIVE)
-        v.parse_metadata_json({"shell-version": ["3.10"]})
+        v.parse_metadata_json({"shell-version": ["3.10", "3.11.1", "3.12"]})
 
         v = models.ExtensionVersion.objects.create(extension=extension, status=models.STATUS_ACTIVE)
-        v.parse_metadata_json({"shell-version": ["3.13.4"]})
+        v.parse_metadata_json({"shell-version": ["3.13.4", "3.14", "3.15.2", "3.16.0", "3.16.1"]})
+
+        v = models.ExtensionVersion.objects.create(extension=extension, status=models.STATUS_ACTIVE)
+        v.parse_metadata_json({"shell-version": ["3.16", "3.16.1", "3.17.1", "3.18.2"]})
 
         v = models.ExtensionVersion.objects.create(extension=extension, status=models.STATUS_ACTIVE)
         v.parse_metadata_json({"shell-version": ["3.20.0"]})
 
-        self.assertEqual(views.grab_proper_extension_version(extension, "3.20.0").version, 3)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.17.1").version, 3)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.20.0").version, 4)
         self.assertEqual(views.grab_proper_extension_version(extension, "3.2.0"), None)
         self.assertEqual(views.grab_proper_extension_version(extension, "3.4.0"), None)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.20.1"), None)
         self.assertEqual(views.grab_proper_extension_version(extension, "3.4.0", True).version, 1)
         self.assertEqual(views.grab_proper_extension_version(extension, "3.7.4.1", True).version, 1)
         self.assertEqual(views.grab_proper_extension_version(extension, "3.10.0", True).version, 1)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.11.2", True).version, 1)
         self.assertEqual(views.grab_proper_extension_version(extension, "3.13.4", True).version, 2)
-        self.assertEqual(views.grab_proper_extension_version(extension, "3.11.2", True).version, 3)
-        self.assertEqual(views.grab_proper_extension_version(extension, "3.20.0", True).version, 3)
-        self.assertEqual(views.grab_proper_extension_version(extension, "3.24.0", True).version, 3)
-        self.assertEqual(views.grab_proper_extension_version(extension, "4.14.0", True).version, 3)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.15.1", True).version, 2)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.15.2", True).version, 2)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.15.3", True).version, 2)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.16", True).version, 3)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.16.1", True).version, 3)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.16.2", True).version, 3)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.17.3", True).version, 3)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.18.3", True).version, 3)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.20.0", True).version, 4)
+        self.assertEqual(views.grab_proper_extension_version(extension, "3.24.0", True).version, 4)
+        self.assertEqual(views.grab_proper_extension_version(extension, "4.14.0", True).version, 4)
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index 1c54444..c888612 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -63,6 +63,9 @@ def grab_proper_extension_version(extension, shell_version, disable_version_vali
                 supported_shell_versions[0].point), requested_shell_version) > 0:
             versions = visible_versions.filter(shell_versions=supported_shell_versions[0])
         else:
+            supported_shell_versions = list(shell_version
+                                           for shell_version in supported_shell_versions
+                                           if (shell_version.major, shell_version.minor, 
shell_version.point) <= requested_shell_version)
             versions = visible_versions.filter(shell_versions=supported_shell_versions[-1])
 
         return versions.order_by('-version')[0]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]