A lot of the pyramid docs will have view callable examples similar to this
to the toy code I've provided below. (I'm using traversal which means I am
given a context object, but using url dispatch is similar).
@view_config(name='edit', context='model.user.User', renderer='template/
I had a lot of code that was almost trivial thanks to use of traversal and
form_encode libraries. Because of this, even though I cringed a bit I
never wrote a 'manager' layer of code for a lot of domain entities that
would take care of more complex validations beyond just form validation.
The big problem here I've found is that code like the above is very
untestable. I have to test the rendered view to make sure the user object
changed correctly when edited (eg: first name changed). But, while I think
important, testing a rendered view for strings etc, is very fragile and
breaks every time the designer comes in and changes the template code.
It would be nicer to test a manager layer of code which returns the objects
where values can be tested directly (these tests would be in addition to
direct tests on the model itself - because we want to test manager layer
validation is working correctly). But it seems unfortunate to introduce a
whole new layer of code throughout the app just for testability.
*Does anyone have any good recommendations on a better approach/design to
view - model interaction to increase testability? *And does the Pyramid
community have recommended ways to work with designers, templates and test