I am writing a unittest. How can I patch self.conf in the init method in class MyValidator? In my unittest, I want to create a fake self.conf and get the response to make assertion of each element in self.conf.
class MyValidator(wsgi.Middleware):
def __init__(self, app):
self.app = app
self.conf = {
'auth_uri': CONF.someuri
'admin_domain_name': CONF.somedomainname,
'admin_user': CONF.someuser,
'admin_password': CONF.get_admin_password(),
'domain_name': CONF.somedomainname
}
For unittest, I am thinking to do.. (I know this is wrong.. but you get the idea)
@mock.patch('my_module.MyValidator.__init__.conf')
def setUp(self, mock_config):
@webob.dec.wsgify()
def fake_app(req):
return webob.Response()
self.request = webob.Request.blank('/')
mock_config = {
'auth_uri': 'testuri'
....
....
}
self.middleware = MyValidator(fake_app)
def test_auth_uri(self):
auth_uri = 'testuri'
env_auth_uri = self.request.environ.get('auth_uri', None)
self.assertEqual(auth_uri, env_auth_uri)
What should be done to patch self.conf to get intended response?