mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-11 07:41:19 +00:00
Remove usages of Ping.body
This commit is contained in:
parent
daaee30c88
commit
997154e3b0
5 changed files with 4 additions and 37 deletions
hc
templates/front
|
@ -667,14 +667,12 @@ class Ping(models.Model):
|
|||
return result
|
||||
|
||||
def has_body(self) -> bool:
|
||||
if self.body or self.body_raw or self.object_size:
|
||||
if self.body_raw or self.object_size:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def get_body_bytes(self) -> bytes | None:
|
||||
if self.body:
|
||||
return self.body.encode()
|
||||
if self.object_size and self.n:
|
||||
return get_object(str(self.owner.code), self.n)
|
||||
if self.body_raw:
|
||||
|
@ -690,8 +688,6 @@ class Ping(models.Model):
|
|||
return None
|
||||
|
||||
def get_body_size(self) -> int:
|
||||
if self.body:
|
||||
return len(self.body)
|
||||
if self.body_raw:
|
||||
return len(self.body_raw)
|
||||
if self.object_size:
|
||||
|
|
|
@ -173,7 +173,7 @@ class NotifyEmailTestCase(BaseTestCase):
|
|||
self.assertIn("Europe/Riga", html)
|
||||
|
||||
def test_it_truncates_long_body(self) -> None:
|
||||
self.ping.body = "X" * 10000 + ", and the rest gets cut off"
|
||||
self.ping.body_raw = b"X" * 10000 + b", and the rest gets cut off"
|
||||
self.ping.save()
|
||||
|
||||
self.channel.notify(self.flip)
|
||||
|
|
|
@ -33,16 +33,6 @@ class LogTestCase(BaseTestCase):
|
|||
self.assertContains(r, "Browser's time zone", status_code=200)
|
||||
self.assertContains(r, "hello world")
|
||||
|
||||
def test_it_displays_body(self) -> None:
|
||||
self.ping.body = "hello world"
|
||||
self.ping.body_raw = None
|
||||
self.ping.save()
|
||||
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get(self.url)
|
||||
self.assertContains(r, "Browser's time zone", status_code=200)
|
||||
self.assertContains(r, "hello world")
|
||||
|
||||
@patch("hc.api.models.get_object")
|
||||
def test_it_does_not_load_body_from_object_storage(self, get_object: Mock) -> None:
|
||||
self.ping.body_raw = None
|
||||
|
|
|
@ -56,13 +56,6 @@ class PingDetailsTestCase(BaseTestCase):
|
|||
r = self.client.get(self.url)
|
||||
self.assertContains(r, "this is body", status_code=200)
|
||||
|
||||
def test_it_displays_body(self) -> None:
|
||||
Ping.objects.create(owner=self.check, n=1, body="this is body")
|
||||
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get(self.url)
|
||||
self.assertContains(r, "this is body", status_code=200)
|
||||
|
||||
def test_it_displays_duration(self) -> None:
|
||||
expected_duration = td(minutes=5)
|
||||
end_time = now()
|
||||
|
@ -171,18 +164,6 @@ class PingDetailsTestCase(BaseTestCase):
|
|||
self.assertContains(r, "aGVsbG8gd29ybGQ=")
|
||||
self.assertContains(r, "hello world")
|
||||
|
||||
def test_it_decodes_plaintext_email_body_str(self) -> None:
|
||||
body = PLAINTEXT_EMAIL.decode()
|
||||
Ping.objects.create(owner=self.check, n=1, scheme="email", body=body)
|
||||
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get(self.url)
|
||||
|
||||
fragment = """<div id="email-body-plain" class="tab-pane active">"""
|
||||
self.assertContains(r, fragment, status_code=200)
|
||||
self.assertContains(r, "aGVsbG8gd29ybGQ=")
|
||||
self.assertContains(r, "hello world")
|
||||
|
||||
def test_it_handles_bad_base64_in_email_body(self) -> None:
|
||||
Ping.objects.create(
|
||||
owner=self.check, n=1, scheme="email", body_raw=BAD_BASE64_EMAIL
|
||||
|
@ -214,7 +195,7 @@ class PingDetailsTestCase(BaseTestCase):
|
|||
owner=self.check,
|
||||
n=1,
|
||||
scheme="email",
|
||||
body="Subject: =?UTF-8?B?aGVsbG8gd29ybGQ=?=",
|
||||
body_raw=b"Subject: =?UTF-8?B?aGVsbG8gd29ybGQ=?=",
|
||||
)
|
||||
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
{% if event.rid %}<span class="label rid">{{ event.rid|first5 }}</span> {% endif %}
|
||||
{% if event.scheme == "email" %}{{ event.ua }}{% else %}
|
||||
{{ event.scheme|upper }} {{ event.method }}{% if event.remote_addr %} from {{ event.remote_addr }}{% endif %}
|
||||
<code>{% if event.body or event.body_raw %}- {{ event.get_body|truncatechars:150 }}{% elif event.object_size %}- {{ event.object_size }} byte body{% endif %}{% if event.ua %} - {{ event.ua|truncatechars:80 }}{% endif %}</code>
|
||||
<code>{% if event.body_raw %}- {{ event.get_body|truncatechars:150 }}{% elif event.object_size %}- {{ event.object_size }} byte body{% endif %}{% if event.ua %} - {{ event.ua|truncatechars:80 }}{% endif %}</code>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Add table
Reference in a new issue