-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stub method when using Flask LiveServerTestCase #107
Comments
Unfortunately using the LiveServerTestCase means that mocking will have no effect. The app object is being deployed via the In general its better to use the regular TestCase with the fake client if you are planning on mocking. In your case it doesn't seem like that is possible. However, there are a couple of solutions that I can think of depending on what the rest of that code looks like
Does that help? |
you can patch at the time when the LiveServer is created: @patch("util.ldapClient.LDAPCLient.connect")
@patch("util.ldapClient.LDAPCLient.login")
@patch("...")
@patch("...")
@patch("...")
@patch("...")
def __call__(self, result, *mocklist):
"""
Override the __call__ to patch the connect and login out
"""
for lmock in mocklist:
if '_mock_name' in lmock.__dict__:
self.mocks[lmock.__dict__['_mock_name']] = lmock
super(FrontendTest, self).__call__(result=result) the Good luck |
We're trying to test a frontend feature that sends a request to a Third Party API when a button is clicked. The click will trigger an internal API call to our Flask application, which will translate this to a request for the ThirdPartyApi.
We try to test this using Splinter, Flask Testing and PhantomJS. Because we don't want to hit the actual API, we want to stub out the method that will perform this request. However, the stub doesn't seem to work and the actual http call is performed. We suspect it has something to do with the difference between the test context and the app context, but we were not able to solve it with the app_context() provided by Flask.
Do you have suggestions how to fix this? Below is a simplified version of the test code we are using.
The text was updated successfully, but these errors were encountered: