mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-10 08:01:17 +00:00
Whitespace/flake8
This commit is contained in:
@@ -12,9 +12,9 @@ class MessagingServiceConfig(models.Model):
|
||||
kind = models.CharField(choices=[("slack", "Slack (or compatible)"), ], max_length=20, default="slack")
|
||||
|
||||
config = models.TextField(blank=False)
|
||||
|
||||
|
||||
# Alert backend failure tracking
|
||||
last_failure_timestamp = models.DateTimeField(null=True, blank=True,
|
||||
last_failure_timestamp = models.DateTimeField(null=True, blank=True,
|
||||
help_text="When the last failure occurred")
|
||||
last_failure_status_code = models.IntegerField(null=True, blank=True,
|
||||
help_text="HTTP status code of the failed request")
|
||||
@@ -30,7 +30,7 @@ class MessagingServiceConfig(models.Model):
|
||||
def get_backend(self):
|
||||
# once we have multiple backends: lookup by kind.
|
||||
return SlackBackend(self)
|
||||
|
||||
|
||||
def clear_failure_status(self):
|
||||
"""Clear all failure tracking fields on successful operation"""
|
||||
self.last_failure_timestamp = None
|
||||
@@ -39,7 +39,7 @@ class MessagingServiceConfig(models.Model):
|
||||
self.last_failure_is_json = None
|
||||
self.last_failure_error_type = None
|
||||
self.last_failure_error_message = None
|
||||
|
||||
|
||||
def has_recent_failure(self):
|
||||
"""Check if this config has a recent failure"""
|
||||
return self.last_failure_timestamp is not None
|
||||
|
||||
@@ -37,20 +37,20 @@ def _safe_markdown(text):
|
||||
def _store_failure_info(service_config_id, exception, response=None):
|
||||
"""Store failure information in the MessagingServiceConfig with immediate_atomic"""
|
||||
from alerts.models import MessagingServiceConfig
|
||||
|
||||
|
||||
with immediate_atomic(only_if_needed=True):
|
||||
try:
|
||||
config = MessagingServiceConfig.objects.get(id=service_config_id)
|
||||
|
||||
|
||||
config.last_failure_timestamp = timezone.now()
|
||||
config.last_failure_error_type = type(exception).__name__
|
||||
config.last_failure_error_message = str(exception)
|
||||
|
||||
|
||||
# Handle requests-specific errors
|
||||
if response is not None:
|
||||
config.last_failure_status_code = response.status_code
|
||||
config.last_failure_response_text = response.text[:2000] # Limit response text size
|
||||
|
||||
|
||||
# Check if response is JSON
|
||||
try:
|
||||
json.loads(response.text)
|
||||
@@ -62,7 +62,7 @@ def _store_failure_info(service_config_id, exception, response=None):
|
||||
config.last_failure_status_code = None
|
||||
config.last_failure_response_text = None
|
||||
config.last_failure_is_json = None
|
||||
|
||||
|
||||
config.save()
|
||||
except MessagingServiceConfig.DoesNotExist:
|
||||
# Config was deleted while task was running
|
||||
@@ -72,7 +72,7 @@ def _store_failure_info(service_config_id, exception, response=None):
|
||||
def _store_success_info(service_config_id):
|
||||
"""Clear failure information on successful operation"""
|
||||
from alerts.models import MessagingServiceConfig
|
||||
|
||||
|
||||
with immediate_atomic(only_if_needed=True):
|
||||
try:
|
||||
config = MessagingServiceConfig.objects.get(id=service_config_id)
|
||||
@@ -146,7 +146,9 @@ def slack_backend_send_test_message(webhook_url, project_name, display_name, ser
|
||||
|
||||
|
||||
@shared_task
|
||||
def slack_backend_send_alert(webhook_url, issue_id, state_description, alert_article, alert_reason, service_config_id, unmute_reason=None):
|
||||
def slack_backend_send_alert(
|
||||
webhook_url, issue_id, state_description, alert_article, alert_reason, service_config_id, unmute_reason=None):
|
||||
|
||||
issue = Issue.objects.get(id=issue_id)
|
||||
|
||||
issue_url = get_settings().BASE_URL + issue.get_absolute_url()
|
||||
|
||||
@@ -166,9 +166,9 @@ class TestSlackBackendErrorHandling(DjangoTestCase):
|
||||
|
||||
# Send test message
|
||||
slack_backend_send_test_message(
|
||||
"https://hooks.slack.com/test",
|
||||
"Test project",
|
||||
"Test Slack",
|
||||
"https://hooks.slack.com/test",
|
||||
"Test project",
|
||||
"Test Slack",
|
||||
self.config.id
|
||||
)
|
||||
|
||||
@@ -184,7 +184,7 @@ class TestSlackBackendErrorHandling(DjangoTestCase):
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 404
|
||||
mock_response.text = '{"error": "webhook_not_found"}'
|
||||
|
||||
|
||||
# Create the HTTPError with response attached
|
||||
http_error = requests.HTTPError()
|
||||
http_error.response = mock_response
|
||||
@@ -195,9 +195,9 @@ class TestSlackBackendErrorHandling(DjangoTestCase):
|
||||
# Send test message and expect it to raise
|
||||
with self.assertRaises(requests.HTTPError):
|
||||
slack_backend_send_test_message(
|
||||
"https://hooks.slack.com/test",
|
||||
"Test project",
|
||||
"Test Slack",
|
||||
"https://hooks.slack.com/test",
|
||||
"Test project",
|
||||
"Test Slack",
|
||||
self.config.id
|
||||
)
|
||||
|
||||
@@ -215,7 +215,7 @@ class TestSlackBackendErrorHandling(DjangoTestCase):
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 500
|
||||
mock_response.text = 'Internal Server Error'
|
||||
|
||||
|
||||
# Create the HTTPError with response attached
|
||||
http_error = requests.HTTPError()
|
||||
http_error.response = mock_response
|
||||
@@ -226,9 +226,9 @@ class TestSlackBackendErrorHandling(DjangoTestCase):
|
||||
# Send test message and expect it to raise
|
||||
with self.assertRaises(requests.HTTPError):
|
||||
slack_backend_send_test_message(
|
||||
"https://hooks.slack.com/test",
|
||||
"Test project",
|
||||
"Test Slack",
|
||||
"https://hooks.slack.com/test",
|
||||
"Test project",
|
||||
"Test Slack",
|
||||
self.config.id
|
||||
)
|
||||
|
||||
@@ -247,9 +247,9 @@ class TestSlackBackendErrorHandling(DjangoTestCase):
|
||||
# Send test message and expect it to raise
|
||||
with self.assertRaises(requests.ConnectionError):
|
||||
slack_backend_send_test_message(
|
||||
"https://hooks.slack.com/test",
|
||||
"Test project",
|
||||
"Test Slack",
|
||||
"https://hooks.slack.com/test",
|
||||
"Test project",
|
||||
"Test Slack",
|
||||
self.config.id
|
||||
)
|
||||
|
||||
|
||||
2
theme/static/css/dist/styles.css
vendored
2
theme/static/css/dist/styles.css
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user