Skip to content

Commit

Permalink
[#43] Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Nov 7, 2024
1 parent f327837 commit 35b9518
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 1 addition & 5 deletions log_outgoing_requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

0 comments on commit 35b9518

Please sign in to comment.