[extensions-web/wip/visual-tag] review: do not auto-approve extension when session-modes changed



commit 8e8728a6fec08e6c8a2d3cb968b0e7646cdf2819
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Mon May 9 18:25:34 2022 +0400

    review: do not auto-approve extension when session-modes changed
    
    Closes: https://gitlab.gnome.org/Infrastructure/extensions-web/-/issues/187

 sweettooth/review/tests/tests.py | 57 +++++++++++++++++++++++++++++++++++++---
 sweettooth/review/views.py       | 10 +++++++
 2 files changed, 63 insertions(+), 4 deletions(-)
---
diff --git a/sweettooth/review/tests/tests.py b/sweettooth/review/tests/tests.py
index 2a851bc..0a66df7 100644
--- a/sweettooth/review/tests/tests.py
+++ b/sweettooth/review/tests/tests.py
@@ -1,13 +1,23 @@
+"""
+    GNOME Shell Extensions Repository
+    Copyright (C) 2013 Jasper St. Pierre <jstpierre mecheye net>
+    Copyright (C) 2022 Yuri Konotopov <ykonotopov gnome org>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+"""
 
 from django.test import TestCase
-from django.core.files.base import File, ContentFile, StringIO
+from django.core.files.base import File, ContentFile
 
 from sweettooth.extensions import models
-from sweettooth.review.views import get_old_version, should_auto_approve_changeset
+from sweettooth.extensions.tests import get_test_zipfile
+from sweettooth.review.views import get_old_version, should_auto_approve, should_auto_approve_changeset
 
 from sweettooth.testutils import BasicUserTestCase
 
-from .tests_diff import DiffTest
 
 class DiffViewTest(BasicUserTestCase, TestCase):
     def test_get_zipfiles(self):
@@ -31,7 +41,8 @@ class DiffViewTest(BasicUserTestCase, TestCase):
                                                           status=models.STATUS_UNREVIEWED)
         self.assertEqual(version1, get_old_version(version3))
 
-class TestAutoApproveLogic(TestCase):
+
+class TestAutoApproveLogic(BasicUserTestCase, TestCase):
     def build_changeset(self, added=None, deleted=None, changed=None, unchanged=None):
         return dict(added=added or [],
                     deleted=deleted or [],
@@ -48,3 +59,41 @@ class TestAutoApproveLogic(TestCase):
         self.assertFalse(should_auto_approve_changeset(self.build_changeset(changed=['secret_keys.json'])))
         
self.assertFalse(should_auto_approve_changeset(self.build_changeset(changed=['libbignumber/BigInteger.js'])))
         
self.assertFalse(should_auto_approve_changeset(self.build_changeset(added=['libbignumber/BigInteger.js'])))
+
+    def test_auto_approve_metadata(self):
+        metadata = {
+            "uuid": "something1 example com",
+            "name": "Test Metadata",
+            "shell-version": ["42"],
+        }
+        zipfile = get_test_zipfile("SimpleExtension")
+
+        extension: models.Extension = models.Extension.objects.create_from_metadata(
+            metadata,
+            creator=self.user
+        )
+        version = models.ExtensionVersion.objects.create(
+            extension=extension,
+            source=File(zipfile, "version1.zip"),
+            status=models.STATUS_ACTIVE
+        )
+        version.parse_metadata_json(metadata)
+        version.save()
+
+        version: models.ExtensionVersion = models.ExtensionVersion.objects.create(
+            extension=extension,
+            source=File(zipfile, "version2.zip"),
+            status=models.STATUS_UNREVIEWED
+        )
+        version.parse_metadata_json(metadata | { 'session-modes': ['user']})
+        version.save()
+        self.assertFalse(should_auto_approve(version))
+
+        version: models.ExtensionVersion = models.ExtensionVersion.objects.create(
+            extension=extension,
+            source=File(zipfile, "version3.zip"),
+            status=models.STATUS_UNREVIEWED
+        )
+        version.parse_metadata_json(metadata | { 'shell-version': ['43']})
+        version.save()
+        self.assertTrue(should_auto_approve(version))
diff --git a/sweettooth/review/views.py b/sweettooth/review/views.py
index 8355bf2..e6392f9 100644
--- a/sweettooth/review/views.py
+++ b/sweettooth/review/views.py
@@ -1,5 +1,6 @@
 
 import base64
+from collections import Counter
 import itertools
 import os.path
 
@@ -379,6 +380,15 @@ def should_auto_approve(version):
     if old_version is None:
         return False
 
+    old_session_modes = set(
+        x.mode
+        for x in old_version.session_modes.all()
+    )
+    session_modes = [x.mode for x in version.session_modes.all()]
+
+    if Counter(old_session_modes) != Counter(session_modes):
+        return False
+
     old_zipfile, new_zipfile = get_zipfiles(old_version, version)
     changeset = get_file_changeset(old_zipfile, new_zipfile)
     return should_auto_approve_changeset(changeset)


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