Closed sydoluciani closed 4 years ago
@sydoluciani this looks good to me, but I would like to get a smarter person than myself to review it as well to provide guidance. I'm reaching out to a few colleagues, and we'll see. Thank you for your perseverance!
I got a tip to try using pyramid.testing.DummyRequest
. It's used throughout many Pylons Project projects.
I might have time to try it this weekend. I got a couple of deadlines at the moment.
That is good to know, it has session and get_csrf_token. I should be able to complete testing renderer.py in weekend, then we can exchange notes.
@stevepiercy
Replaced MagicMock with DummyRequest: https://github.com/sydoluciani/deform/blob/drop-py27-py34/deform/tests/test_schema.py#L28
Added test_renderer.py and used the example provided within the renderer.py.
Currently testing if default_renderer is instance of ZPTRendererFactory.
https://github.com/sydoluciani/deform/blob/drop-py27-py34/deform/tests/test_renderer.py#L22
And if the additional 'custom_widgets' exists in new search_path: https://github.com/sydoluciani/deform/blob/drop-py27-py34/deform/tests/test_renderer.py#L26
Replaced bootstrap 3 files with bootstrap 4:
bootstrap.min.css
bootstrap.min.js
Have you signed https://github.com/Pylons/deform/blob/master/CONTRIBUTORS.txt yet?
Just updated the CONTRIBUTORS.txt.
@sydoluciani thank you for your work on this!
@sydoluciani thank you for your work on this!
@stevepiercy Thank you for your guidance.
@stevepiercy coverage fails on this line of schema.py: https://github.com/Pylons/deform/blob/master/deform/schema.py#L29
And the only way to get 100 percent coverage on schema.py, is to call the fucntion with the same number of arguments, however invoking deferred_csrf_value directly, means accessing request object to get the CSRF token, and apparently creating a request object not easily possible in test environment and outside of the view. the request object needs to have a session and a CSRF token to pass the test, so created a mock version of request and session to return null instead of CSRF just to pass the test.
Technically we are recreating "@colander.deferred" by mocking request object, before directly calling deferred_csrf_value, to make sure request is not being called until later on, and now we are getting 100 percent coverage against schema.py: https://travis-ci.org/github/Pylons/deform/jobs/686742943#L306
Please check the code and let me know if it is acceptable, because this is the way going to implement test for renderer.py as well.
https://github.com/sydoluciani/deform/blob/drop-py27-py34/deform/tests/test_schema.py#L23
Thanks