title: How can I mock object with nested attributes in Python?
body: <p>Consider the following code:</p>
  <pre><code>class Foo:
      @staticmethod
      def is_room_member(invitee, msg):
          return invitee in msg.frm.room.occupants
  </code></pre>
  <p>I want to test the method <code>is_room_member</code> where <code>invitee</code> is a string and
  <code>occupants</code> is a list of string.</p>
  <p>If <code>invitee = 'batman'</code> and <code>occupants = ['batman', 'superman']</code> the method <code>is_room_member</code> returns <code>True</code>.</p>
  <p><code>msg</code> is the object which needs to be mocked so that I can test this method.</p>
  <p>How can I test this method, since it'll require this <code>msg</code> object which has nested attributes?</p>
  <p>I want the test to be something like:</p>
  <pre><code>class Testing(unittest.TestCase):
      def test_is_room_member(self):
          occupants = ['batman', 'superman']
          # mocking 
          # msg = MagicMock()
          # msg.frm.room.occupants = occupants
          self.assertTrue(Foo.is_room_member('batman', msg))
  </code></pre>