From 35b95183fa9817f5199a1882de18b91cca673e7a Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Thu, 7 Nov 2024 15:15:54 +0100 Subject: [PATCH] [#43] Improvements --- log_outgoing_requests/models.py | 6 +----- tests/test_admin.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/log_outgoing_requests/models.py b/log_outgoing_requests/models.py index a870c0e..c6136a1 100644 --- a/log_outgoing_requests/models.py +++ b/log_outgoing_requests/models.py @@ -179,14 +179,10 @@ def response_content_length(self) -> str: """ Get Response content length by reading `len(body)`. """ - content_length = "" - if self.response_body_decoded: - content_length = str(len(self.response_body_decoded)) - return content_length + return str(len(self.response_body_decoded)) response_content_length.short_description = _("Content length") # type: ignore - def get_default_max_content_length(): """ Get default value for max content length from settings. diff --git a/tests/test_admin.py b/tests/test_admin.py index a2d143f..60399a0 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -156,16 +156,16 @@ def test_response_content_length_empty(admin_client): assert request_body == "-" assert response_body == "-" - assert content_length == "-" + assert content_length == "0" @pytest.mark.django_db -def test_decoded_content_display(admin_client): +def test_response_content_length_displayed(admin_client): """Assert the length of the content of the response is displayed""" log = OutgoingRequestsLog.objects.create( id=1, - req_body=b"I'm a lumberjack and I'm okay.", - res_body=b"I sleep all night and work all day.", + req_body=b"Test request", + res_body=b"Test Response", timestamp=timezone.now(), ) url = reverse( @@ -181,6 +181,7 @@ def test_decoded_content_display(admin_client): response_body = doc.find(".field-response_body .readonly").text() content_length = doc.find(".field-response_content_length .readonly").text() - assert request_body == "I'm a lumberjack and I'm okay." - assert response_body == "I sleep all night and work all day." - assert content_length == "35" + assert request_body == "Test request" + assert response_body == "Test Response" + assert content_length == "13" + assert content_length == log.response_content_length