I see this action repeated quite a bit throughout the code:
for x in children:
if x.name is not None:
button_list.append(x.name)
buttons.append([KeyboardButton(text=x.name)])
It seems like you could make it a method on the Element class or just a standalone method (whichever makes more sense), to DRY up the code, and return both the button_list and buttons. I would also then suggest a set of tests against that method, to test for things like:
Empty list of children
Mix of children with .name and without .name
Make sure right number of buttons come back, with the right names and object type (for buttons)
Unicode values in .name (I assume the name comes from the user, and can be anything?)
Empty name string (you may want to have form validation that prevents this?)...do you want that to show up?
Newlines in the name field, or other weird space characters / tabs / etc.
Are there any unallowable name characters, from Telegram's point of view (do their API docs mention any)? Should guard against those in the code (strip them out or encode them) and verify with a test
I see this action repeated quite a bit throughout the code:
It seems like you could make it a method on the
Element
class or just a standalone method (whichever makes more sense), to DRY up the code, and return both thebutton_list
andbuttons
. I would also then suggest a set of tests against that method, to test for things like:.name
and without.name
buttons
).name
(I assume thename
comes from the user, and can be anything?)name
field, or other weird space characters / tabs / etc.name
characters, from Telegram's point of view (do their API docs mention any)? Should guard against those in the code (strip them out or encode them) and verify with a test