Skip to content

Commit

Permalink
Fix nightly job (#844)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zerolab authored Dec 23, 2024
1 parent 6d40c66 commit 646d741
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
14 changes: 9 additions & 5 deletions .github/scripts/report_nightly_build_failure.py
Original file line number Diff line number Diff line change
@@ -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.
"""
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nigthly-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
55 changes: 35 additions & 20 deletions wagtail_localize/tests/test_edit_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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
)
Expand Down Expand Up @@ -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": "",
},
},
Expand Down Expand Up @@ -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": "",
},
},
Expand Down Expand Up @@ -2401,7 +2413,7 @@ def test_update_string_translation_with_bad_html(self):
"error": "<script> tag is not allowed. Strings can only contain standard HTML inline tags (such as <b>, <a>)",
"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": "",
},
},
Expand Down Expand Up @@ -2450,7 +2462,7 @@ def test_update_string_translation_with_unkown_links(self):
"error": "Unrecognised id found in an <a> tag: a42",
"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": "",
},
},
Expand Down Expand Up @@ -3719,9 +3731,13 @@ class TestEditAlias(WagtailTestUtils, TestCase):
that have a different locale to their original.
"""

@classmethod
def setUpTestData(cls):
cls.user = cls.create_test_user()
cls.fr_locale = Locale.objects.create(language_code="fr")

def setUp(self):
self.login()
self.user = get_user_model().objects.get()
self.login(username=self.user.username)

# Create a test page
self.home_page = Page.objects.get(depth=2)
Expand All @@ -3733,7 +3749,6 @@ def setUp(self):
)

# Set up French locale
self.fr_locale = Locale.objects.create(language_code="fr")
self.fr_home_page = self.home_page.copy_for_translation(self.fr_locale)

def test_edit_translatable_alias(self):
Expand Down

0 comments on commit 646d741

Please sign in to comment.