-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: disable broken website alerts #18061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ef394fd
d6ccca4
3963103
da12336
482b38c
10fabc0
facbc42
47c9c6a
208350d
f090240
70e942b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,52 @@ | |
|
|
||
| """Test for alerts.""" | ||
|
|
||
| from django.test.utils import override_settings | ||
| from django.test import TestCase, override_settings | ||
| from django.urls import reverse | ||
|
|
||
| from weblate.lang.models import Language | ||
| from weblate.trans.models import Unit | ||
| from weblate.trans.models import Component, Project, Unit | ||
| from weblate.trans.tests.test_views import ViewTestCase | ||
|
|
||
|
|
||
| class WebsiteAlertSettingTest(TestCase): | ||
| """Test WEBSITE_ALERTS_ENABLED setting.""" | ||
|
|
||
| def setUp(self): | ||
| # Create a test project with a broken website URL | ||
| self.project = Project.objects.create( | ||
| name="Test Project", | ||
| slug="test-project", | ||
| web="https://this-website-does-not-exist-404.com", | ||
| ) | ||
| self.component = Component.objects.create( | ||
|
Check failure on line 25 in weblate/trans/tests/test_alert.py
|
||
| project=self.project, | ||
| name="Test Component", | ||
| slug="test-component", | ||
| # ... other required fields ... | ||
| ) | ||
|
|
||
| @override_settings(WEBSITE_ALERTS_ENABLED=False) | ||
| def test_website_alerts_disabled(self): | ||
| """Test that website alerts are not created when setting is False.""" | ||
| # Run alert check | ||
| # ... code to trigger alert check ... | ||
|
|
||
| # Assert no broken website alert was created | ||
| alerts = self.component.alert_set.filter(name="BrokenProjectWebsite") | ||
|
||
| self.assertEqual(alerts.count(), 0) | ||
|
|
||
| @override_settings(WEBSITE_ALERTS_ENABLED=True) | ||
| def test_website_alerts_enabled(self): | ||
| """Test that website alerts are created when setting is True.""" | ||
| # Run alert check | ||
| # ... code to trigger alert check ... | ||
|
|
||
| # Assert broken website alert was created | ||
| alerts = self.component.alert_set.filter(name="BrokenProjectWebsite") | ||
|
||
| self.assertGreater(alerts.count(), 0) | ||
|
Comment on lines
+15
to
+50
|
||
|
|
||
|
|
||
| class AlertTest(ViewTestCase): | ||
| def create_component(self): | ||
| return self._create_component("po", "po-duplicates/*.dpo", manage_units=True) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Component.objects.create() call is missing required fields. Components in Weblate require several fields including file_format, filemask, repo, and vcs to be valid. This test will fail at runtime. Consider using the existing test infrastructure like ViewTestCase which properly sets up components, or look at how other tests create components (e.g., in test_license which uses self.component that's created by the test infrastructure).