Add the method to get formated item name and count.
continuous-integration/drone/push Build is failing
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -17,3 +17,18 @@ class ItemFormatter(AbstractFormatter):
|
|||||||
|
|
||||||
return formated_message
|
return formated_message
|
||||||
|
|
||||||
|
def get_name_and_count_from_parts(self, parts: list):
|
||||||
|
line = " ".join(parts)
|
||||||
|
|
||||||
|
if not ', ' in line:
|
||||||
|
return {
|
||||||
|
'error': 'Не правильний формат'
|
||||||
|
}
|
||||||
|
|
||||||
|
name, count = line.split(', ')
|
||||||
|
|
||||||
|
return {
|
||||||
|
'name': name,
|
||||||
|
'count': int(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,3 +36,26 @@ def test_format_items():
|
|||||||
|
|
||||||
assert expected_format == items_fmt
|
assert expected_format == items_fmt
|
||||||
|
|
||||||
|
def test_get_name_and_count_from_parts():
|
||||||
|
name_and_count = 'Дуже довга назва страви, 10'
|
||||||
|
|
||||||
|
expected_name = 'Дуже довга назва страви'
|
||||||
|
expected_count = 10
|
||||||
|
|
||||||
|
formatter = ItemFormatter()
|
||||||
|
|
||||||
|
item = formatter.get_name_and_count_from_parts(name_and_count)
|
||||||
|
item_name, item_count = item['name'], item['count']
|
||||||
|
|
||||||
|
assert expected_name == item_name
|
||||||
|
assert expected_count == item_count
|
||||||
|
|
||||||
|
def test_get_name_and_count_from_parts_invalid_command():
|
||||||
|
name_and_count = 'Дуже довга назва страви 10'
|
||||||
|
|
||||||
|
formatter = ItemFormatter()
|
||||||
|
|
||||||
|
error = formatter.get_name_and_count_from_parts(name_and_count)
|
||||||
|
|
||||||
|
assert 'Не правильний формат' == error['error']
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user