title: How to let MagicMock behave like a dict?
body: <p>mock(<a href="http://mock.readthedocs.org/en/latest/index.html" rel="noreferrer">http://mock.readthedocs.org/en/latest/index.html</a>) is a great tool in python for unit test. It can conveniently mock a method or class or dict.But I encountered a problem which I couldn't find a  straightforward way to deal with by mock. </p>
  
  <p>This is the function to be tested:</p>
  
  <pre><code>def function_to_be_tested(id, responses):
      if not id in responses:
          print '%s not exist'%pole_id
          return 
  
      if id in responses.redundantErrorResponses:
          print '%s is redundant'%pole_id
          return
  
      do_something()
  </code></pre>
  
  <p>argument <strong>responses</strong> is a dict like object which has some other attributes(such as redundantErrorResponses) except dict inherent features. Now I want to construct a mock responses to let <code>id in responses</code>to be True and <code>id in responses.redundantErrorResponses</code> to be False. This is what I do:</p>
  
  <pre><code>pole_id = 30
  pole_value = 100
  pole_dic = {pole_id:pole_value}
  mock_responses = MagicMock()
  mock_responses.__getitem__.side_effect = lambda k: pole_dic[k]
  mock_responses.__iter__.side_effect = iter(pole_dic)
  mock_responses.redundantErrorResponses = {}
  </code></pre>
  
  <p>But error occurred:</p>
  
  <pre><code>function_to_be_tested(pole_id, mock_responses)
  
  &gt;&gt;30 not exist
  </code></pre>
  
  <p>So how can I construct a MagicMock object meanwhile can iterate like a dict or how can I construct a dict meanwhile support MagicMock features(add attribute freely)?</p>