From 646d741adb6d2d8e85dd3e577a9d4a07a20c5c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Braghi=C8=99?= <31622+zerolab@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:46:34 +0100 Subject: [PATCH] Fix nightly job (#844) * Add requests as a dependency when testing against wagtailmain * Fix gravatar URL for Wagtail 6.4+ * Move some test data creation in `setUpTestData` * Fix nightly build script - we're not in CirleCI anymore --- .../scripts/report_nightly_build_failure.py | 14 +++-- .github/workflows/nigthly-tests.yml | 2 +- tox.ini | 2 +- .../tests/test_edit_translation.py | 55 ++++++++++++------- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/.github/scripts/report_nightly_build_failure.py b/.github/scripts/report_nightly_build_failure.py index 79685b29..8d2cb9d9 100644 --- a/.github/scripts/report_nightly_build_failure.py +++ b/.github/scripts/report_nightly_build_failure.py @@ -1,5 +1,5 @@ """ -Called by CircleCI when the nightly build fails. +Called by GitHub Action when the nightly build fails. This reports an error to the #nightly-build-failures Slack channel. """ @@ -10,16 +10,20 @@ if "SLACK_WEBHOOK_URL" in os.environ: + # https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables + repository = os.environ["GITHUB_REPOSITORY"] + run_id = os.environ["GITHUB_RUN_ID"] + url = f"https://github.com/{repository}/actions/runs/{run_id}" + print("Reporting to #nightly-build-failures slack channel") - response = requests.post( + response = requests.post( # noqa: S113 os.environ["SLACK_WEBHOOK_URL"], json={ - "text": "A Nightly build failed. See " + os.environ["CIRCLE_BUILD_URL"], + "text": f"A Nightly build failed. See {url}", }, - timeout=30, ) - print("Slack responded with:", response) + print(f"Slack responded with: {response}") else: print( diff --git a/.github/workflows/nigthly-tests.yml b/.github/workflows/nigthly-tests.yml index 3a96a774..b5f6d11c 100644 --- a/.github/workflows/nigthly-tests.yml +++ b/.github/workflows/nigthly-tests.yml @@ -24,7 +24,7 @@ jobs: python-version: '3.13' - name: Install dependencies run: | - python -m pip install --upgrade pip tox + python -m pip install --upgrade pip tox requests - name: Test id: test continue-on-error: true diff --git a/tox.ini b/tox.ini index 46ff0bf6..cce224c9 100644 --- a/tox.ini +++ b/tox.ini @@ -68,7 +68,7 @@ commands = [testenv:wagtailmain] description = Test with latest Wagtail main branch -base_python = python3.12 +base_python = python3.13 deps = wagtailmain: git+https://github.com/wagtail/wagtail.git@main#egg=Wagtail diff --git a/wagtail_localize/tests/test_edit_translation.py b/wagtail_localize/tests/test_edit_translation.py index e62e5b0e..4bbe5a16 100644 --- a/wagtail_localize/tests/test_edit_translation.py +++ b/wagtail_localize/tests/test_edit_translation.py @@ -7,7 +7,6 @@ import polib from django.contrib.admin.utils import quote -from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.contrib.contenttypes.models import ContentType from django.contrib.messages import get_messages @@ -25,6 +24,7 @@ ) from rest_framework.settings import api_settings from rest_framework.test import APITestCase +from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin.panels import FieldPanel, TitleFieldPanel from wagtail.blocks import StreamValue from wagtail.documents.models import Document @@ -110,27 +110,41 @@ def patched_translate_html(html): class EditTranslationTestData(WagtailTestUtils): - def setUp(self): - self.login() - self.user = get_user_model().objects.get() + @classmethod + def setUpTestData(cls): + cls.user = cls.create_test_user() + cls.moderators_group = Group.objects.get(name="Moderators") # Convert the user into an editor - self.moderators_group = Group.objects.get(name="Moderators") for permission in Permission.objects.filter( content_type=ContentType.objects.get_for_model(TestSnippet) ): - self.moderators_group.permissions.add(permission) + cls.moderators_group.permissions.add(permission) for permission in Permission.objects.filter( content_type=ContentType.objects.get_for_model(NonTranslatableSnippet) ): - self.moderators_group.permissions.add(permission) - self.user.is_superuser = False - self.user.groups.add(self.moderators_group) - self.user.save() + cls.moderators_group.permissions.add(permission) + cls.user.groups.add(cls.moderators_group) + cls.user.is_superuser = False + cls.user.save(update_fields=["is_superuser"]) + + cls.home_page = Page.objects.get(depth=2) + cls.fr_locale = Locale.objects.create(language_code="fr") + + if WAGTAIL_VERSION >= (6, 4, 0, "alpha", 0): + cls.avatar_url = ( + "//www.gravatar.com/avatar/93942e96f5acd83e2e047ad8fe03114d?d=mp&s=50" + ) + else: + cls.avatar_url = ( + "//www.gravatar.com/avatar/93942e96f5acd83e2e047ad8fe03114d?s=50&d=mm" + ) + + def setUp(self): + self.login(username=self.user.username) # Create page self.snippet = TestSnippet.objects.create(field="Test snippet") - self.home_page = Page.objects.get(depth=2) self.page = self.home_page.add_child( instance=TestPage( title="The title", @@ -152,8 +166,6 @@ def setUp(self): ) # Create translations - self.fr_locale = Locale.objects.create(language_code="fr") - self.snippet_source, created = TranslationSource.get_or_create_from_instance( self.snippet ) @@ -2305,7 +2317,7 @@ def test_create_string_translation(self): "error": None, "comment": "Translated manually on 21 August 2020", "last_translated_by": { - "avatar_url": "//www.gravatar.com/avatar/93942e96f5acd83e2e047ad8fe03114d?s=50&d=mm", + "avatar_url": self.avatar_url, "full_name": "", }, }, @@ -2353,7 +2365,7 @@ def test_update_string_translation(self): "error": None, "comment": "Translated manually on 21 August 2020", "last_translated_by": { - "avatar_url": "//www.gravatar.com/avatar/93942e96f5acd83e2e047ad8fe03114d?s=50&d=mm", + "avatar_url": self.avatar_url, "full_name": "", }, }, @@ -2401,7 +2413,7 @@ def test_update_string_translation_with_bad_html(self): "error": "