enable cinder queues with per-env prefixes (#21437)

This commit is contained in:
Andrew Williamson 2023-11-14 17:25:10 +00:00 коммит произвёл GitHub
Родитель f058921dd8
Коммит 8217740103
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 38 добавлений и 10 удалений

Просмотреть файл

@ -1,13 +1,18 @@
from django.conf import settings
from django.utils.functional import classproperty
import requests
class CinderEntity:
# This queue is for reports that T&S / TaskUs look at
queue = 'amo-content-infringement'
_queue = 'content-infringement'
type = None # Needs to be defined by subclasses
@classproperty
def queue(cls):
return f'{settings.CINDER_QUEUE_PREFIX}{cls._queue}'
@property
def id(self):
# Ideally override this in subclasses to be more efficient
@ -238,7 +243,7 @@ class CinderCollection(CinderEntity):
class CinderAddonHandledByReviewers(CinderAddon):
# This queue is not monitored on cinder - reports are resolved via AMO instead
queue = 'amo-addon-infringement'
_queue = 'addon-infringement'
def flag_for_human_review(self, appeal=False):
from olympia.reviewers.models import NeedsHumanReview

Просмотреть файл

@ -1,4 +1,5 @@
from django.conf import settings
from django.test.utils import override_settings
import responses
@ -27,6 +28,10 @@ from ..cinder import (
class BaseTestCinderCase:
cinder_class = None # Override in child classes
@override_settings(CINDER_QUEUE_PREFIX='amo-env-')
def test_queue(self):
assert self.cinder_class.queue == 'amo-env-content-infringement'
def _create_dummy_target(self, **kwargs):
raise NotImplementedError
@ -283,6 +288,10 @@ class TestCinderAddon(BaseTestCinderCase, TestCase):
class TestCinderAddonHandledByReviewers(TestCinderAddon):
cinder_class = CinderAddonHandledByReviewers
@override_settings(CINDER_QUEUE_PREFIX='amo-env-')
def test_queue(self):
assert self.cinder_class.queue == 'amo-env-addon-infringement'
def setUp(self):
user_factory(id=settings.TASK_USER_ID)
@ -512,7 +521,7 @@ class TestCinderRating(BaseTestCinderCase, TestCase):
report_text=reason, category=None, reporter=None
)
assert data == {
'queue_slug': 'amo-content-infringement',
'queue_slug': self.cinder_class.queue,
'entity_type': 'amo_rating',
'entity': {
'id': str(rating.id),
@ -604,6 +613,6 @@ class TestCinderCollection(BaseTestCinderCase, TestCase):
'slug': collection.slug,
},
'entity_type': 'amo_collection',
'queue_slug': 'amo-content-infringement',
'queue_slug': self.cinder_class.queue,
'reasoning': 'bad collection!',
}

Просмотреть файл

@ -215,7 +215,7 @@ def test_addon_report_to_cinder():
'slug': addon.slug,
},
'entity_type': 'amo_addon',
'queue_slug': 'amo-content-infringement',
'queue_slug': 'amo-dev-content-infringement',
'reasoning': 'This is bad',
}
@ -260,7 +260,7 @@ def test_addon_appeal_to_cinder():
},
'appealer_entity_type': 'amo_unauthenticated_reporter',
'decision_to_appeal_id': '4815162342-abc',
'queue_slug': 'amo-content-infringement',
'queue_slug': 'amo-dev-content-infringement',
'reasoning': 'I appeal',
}
@ -303,7 +303,7 @@ def test_addon_appeal_to_cinder_authenticated():
},
'appealer_entity_type': 'amo_user',
'decision_to_appeal_id': '4815162342-abc',
'queue_slug': 'amo-content-infringement',
'queue_slug': 'amo-dev-content-infringement',
'reasoning': 'I appeal',
}

Просмотреть файл

@ -786,6 +786,7 @@ class TestUserAbuseViewSetLoggedIn(UserAbuseViewSetTestBase, TestCase):
@override_settings(CINDER_WEBHOOK_TOKEN='webhook-token')
@override_settings(CINDER_QUEUE_PREFIX='amo-')
class TestCinderWebhook(TestCase):
def get_data(self):
webhook_file = os.path.join(TESTS_DIR, 'assets', 'cinder_webhook.json')
@ -859,10 +860,8 @@ class TestCinderWebhook(TestCase):
assert response.status_code == 201
assert response.data == {'amo': {'received': True, 'handled': True}}
def test_wrong_queue(self):
def _test_wrong_queue(self, data):
self._setup_report()
data = self.get_data()
data['payload']['source']['job']['queue']['slug'] = 'another-queue'
req = self.get_request(data=data)
with mock.patch.object(CinderReport, 'process_decision') as process_mock:
response = cinder_webhook(req)
@ -876,6 +875,16 @@ class TestCinderWebhook(TestCase):
}
}
def test_wrong_queue_slug(self):
data = self.get_data()
data['payload']['source']['job']['queue']['slug'] = 'amo-another-queue'
self._test_wrong_queue(data)
@override_settings(CINDER_QUEUE_PREFIX='amo-stage')
def test_wrong_queue_prefix(self):
data = self.get_data()
self._test_wrong_queue(data)
def test_not_decision_event(self):
self._setup_report()
data = self.get_data()

Просмотреть файл

@ -75,3 +75,5 @@ REMOTE_SETTINGS_WRITER_BUCKET = 'staging'
# See: https://bugzilla.mozilla.org/show_bug.cgi?id=1633746
BIGQUERY_AMO_DATASET = 'amo_prod'
CINDER_QUEUE_PREFIX = 'amo-'

Просмотреть файл

@ -78,3 +78,5 @@ REMOTE_SETTINGS_WRITER_URL = env(
'REMOTE_SETTINGS_WRITER_URL', default='https://remote-settings.allizom.org/v1/'
)
REMOTE_SETTINGS_WRITER_BUCKET = 'staging'
CINDER_QUEUE_PREFIX = 'amo-stage-'

Просмотреть файл

@ -1520,3 +1520,4 @@ CINDER_SERVER_URL = env(
)
CINDER_API_TOKEN = env('CINDER_API_TOKEN', default=None)
CINDER_WEBHOOK_TOKEN = env('CINDER_WEBHOOK_TOKEN', default=None)
CINDER_QUEUE_PREFIX = 'amo-dev-'