Update the CityFormatter to have the header as an argument.
This commit is contained in:
@@ -5,8 +5,8 @@ class CityFormatter(AbstractFormatter):
|
|||||||
name = city['name']
|
name = city['name']
|
||||||
return f"- {name}\n"
|
return f"- {name}\n"
|
||||||
|
|
||||||
def format_all(self, cities: dict) -> str:
|
def format_all(self, cities: dict, header: str = "# Міста\n\n") -> str:
|
||||||
formated_message = "Cities:\n\n"
|
formated_message = header
|
||||||
|
|
||||||
for city in cities['data']:
|
for city in cities['data']:
|
||||||
formated_item = self.format(city)
|
formated_item = self.format(city)
|
||||||
|
|||||||
@@ -10,3 +10,21 @@ def test_city_format():
|
|||||||
|
|
||||||
assert '- Chernihiv\n' == city_fmt
|
assert '- Chernihiv\n' == city_fmt
|
||||||
|
|
||||||
|
def test_format_cities():
|
||||||
|
cities = {'data': [
|
||||||
|
{'name': 'Київ'},
|
||||||
|
{'name': 'Чернігів'}
|
||||||
|
]}
|
||||||
|
|
||||||
|
expected_format = "".join([
|
||||||
|
"# Міста\n\n",
|
||||||
|
"- Київ\n",
|
||||||
|
"- Чернігів\n",
|
||||||
|
])
|
||||||
|
|
||||||
|
formatter = CityFormatter()
|
||||||
|
|
||||||
|
cities_fmt = formatter.format_all(cities)
|
||||||
|
|
||||||
|
assert expected_format == cities_fmt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user