courtbot-python icon indicating copy to clipboard operation
courtbot-python copied to clipboard

updated website view tests

Open jeremiahbrem opened this issue 5 years ago • 5 comments

I updated the website views test cases with the changed post endpoint name, different phone numbers, and updated success message.

jeremiahbrem avatar Jul 11 '20 21:07 jeremiahbrem

Run tests with 'python manage.py test'

jeremiahbrem avatar Jul 11 '20 21:07 jeremiahbrem

I can, or I can implement some mocking so we don't have to rely on actual case data, which changes.

jeremiahbrem avatar Aug 05 '20 01:08 jeremiahbrem

Actually, I'm not sure how to mock a request made within another request. I can just change the case number for now.

jeremiahbrem avatar Aug 05 '20 02:08 jeremiahbrem

Actually, I'm not sure how to mock a request made within another request. I can just change the case number for now.

The trick to mocking calls from inside another request is to mock it with the full context from where it is being called:

e.g.



some_module.py
from some_library import some_function

def another_function():
    return some_function()

test.py
import some_module

@mock.patch('some_library.some_function')
def test_one(self):
    result = some_library.another_function()

hope this helps.

jdungan avatar Aug 05 '20 02:08 jdungan

Awesome, thanks jdungan. I'll get to work on that and commit again

jeremiahbrem avatar Aug 05 '20 03:08 jeremiahbrem