Skip to content

Commit 1b27dc6

Browse files
committed
feat(utils): remove dataclass from ResponseMessage
1 parent 203c43c commit 1b27dc6

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
from __future__ import annotations
2-
import dataclasses
2+
from typing import Optional
33

44
from .base_response_message import BaseResponseMessage
55

6-
@dataclasses.dataclass
6+
77
class ResponseMessage(BaseResponseMessage):
88
"""
99
Response message object, that is used for validating responses from data interactions.
1010
"""
11-
# TODO should we make this more flexible by using a base class without elements?
12-
text: str
13-
body: str = None
11+
12+
def __init__(self, text: str, body: Optional[str] = None):
13+
self._text = text
14+
self._body = body
1415

1516
def __str__(self):
16-
return f'"{self.text}"'
17+
return f'ResponseMessage<"{self.text}">'
1718

1819
def __eq__(self, other):
1920
# TODO allow regular expressions?
2021
return self.text == other.text and self.body == other.body
22+
23+
@property
24+
def text(self) -> str:
25+
"""
26+
:return: returns the response message main text
27+
"""
28+
return self._text
29+
30+
@property
31+
def body(self) -> Optional[str]:
32+
"""
33+
:return: returns an optional body of the response message or None otherwise
34+
"""
35+
return self._body

tests/scenarios/scenario_utils_response_message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def test_response_message_init_with_text_and_body(self):
2020

2121
def test_response_message_str_returns_text(self):
2222
msg = ResponseMessage(text="Warning message", body="Extra details")
23-
assert str(msg) == '"Warning message"'
23+
assert str(msg) == 'ResponseMessage<"Warning message">'
2424

2525
def test_response_message_str_with_text_only(self):
2626
msg = ResponseMessage(text="Info")
27-
assert str(msg) == '"Info"'
27+
assert str(msg) == 'ResponseMessage<"Info">'
2828

2929
def test_response_message_equality_both_text_and_body_match(self):
3030
msg1 = ResponseMessage(text="Error", body="Details")

tests/scenarios/scenario_utils_response_message_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def test_response_message_list_str_empty(self):
5050

5151
def test_response_message_list_str_single_item(self):
5252
msg_list = ResponseMessageList(["Error"])
53-
assert str(msg_list) == 'ResponseMessageList(["Error"])'
53+
assert str(msg_list) == 'ResponseMessageList([ResponseMessage<"Error">])'
5454

5555
def test_response_message_list_str_multiple_items(self):
5656
msg_list = ResponseMessageList(["Error 1", "Error 2"])
57-
assert str(msg_list) == 'ResponseMessageList(["Error 1", "Error 2"])'
57+
assert str(msg_list) == 'ResponseMessageList([ResponseMessage<"Error 1">, ResponseMessage<"Error 2">])'
5858

5959
def test_response_message_list_bool_empty_is_false(self):
6060
msg_list = ResponseMessageList()

0 commit comments

Comments
 (0)