we will see different scenarios, in each scenario the actions should written in the controller module, the routing should written in router module, and the test should written in test module as Same as previously
scenario 1
in this scenario, we will create 2 actions one of them is add_user used to add user to mongoengine db and return user ip, the second one update_user used to update user data and return '1' in case success or '0' in case fail
the return type is string so the content_type of response is 'text/plain'
actions
note: we can use self.request because Controller1 inherit from j25.web.Controller
routing
unit test
scenario 2
- in this scenario the 2 actions return mongoengine object, j25 will implicitly encode it, just u need to tell him in the router which format u need, in this scenario we use json format
- the 2 actions have the same number of parameters so each one should have different route,
actions
router
unit test
scenario 3
this action return list of objects, don't worry j25 will encode them to list of dicts :)
action
router
unit test
scenario 4
the 2 actions used to return success operations with no content
in this scenario we use the same path to access the 2 actions , with two different conditions
actions
router
unit test
scenario 5
in this scenario we will see different formats for returned data
if the returned data is string format, the default format is text as we see Previously in scenario 1
if the returned data is dict formated, the default format is html and need template to render data to it
action
routing
unit test
template
open the browser then write the following paths and compare the output
http://127.0.0.1:8800/kalamna/Controller1/test_format.json
http://127.0.0.1:8800/kalamna/Controller1/test_format
the output of first link
the output of second link
*
*
