英文:
django viewflow how to mock viewflow handlers
问题
Say I have a flow class app1/flows.py
class MyFlow(Flow):
start = ...
do_stuff = flow.Handler(this.do_stuff_handler).Next(...)
end = ...
def do_stuff_handler(self, activation):
...
If I want to mock do_stuff_handler
to assert if it has been called
class MyFlowTest(TestCase):
@mock.patch('app1.flows.MyFlow.do_stuff_handler')
def test_do_stuff_handler_called(self, mock_do_stuff_handler):
...
It appears the do_stuff_handler
did not get patched. I did notice the flow class gets instantiated when starting up Django see here. I am struggling to find the correct path to patch the handler method. Any ideas?
英文:
Say I have a flow class app1/flows.py
class MyFlow(Flow):
start = ...
do_stuff = flow.Handler(this.do_stuff_handler).Next(...)
end = ...
def do_stuff_handler(self, activation):
...
If I want to mock do_stuff_handler
to assert if it has been called
class MyFlowTest(TestCase):
@mock.patch('app1.flows.MyFlow.do_stuff_handler')
def test_do_stuff_handler_called(self, mock_do_stuff_handler):
...
It appears the do_stuff_handler
did not get patched. I did notice the flow class gets instantiated when starting up Django see here I am struggling to find the correct path to patch the handler method. Any ideas?
答案1
得分: 1
this-references are resolved at a class import time, and kept inside flow.Handler member variable.
So I think mocking the app1.flows.MyFlow.instance.do_stuff.handler
could helps.
英文:
this-references are resolved at a class import time, and kept inside flow.Handler member variable.
So I think mocking the app1.flows.MyFlow.instance.do_stuff.handler
could helps
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论