@mock.patch.object(group_sync.db.Key, 'from_path')
  @mock.patch.object(group_sync.models.User, 'all')
  def testGet(self, all_mock, from_path_mock):
    self.g._BatchDatastoreOp = mock.Mock()
    self.g._GetGroupMembersAndPermissions = mock.Mock()
    self.g._MakeUserEntity = mock.Mock()

    group_users = {
        'u2@example.com': {'type1': set(['read', 'write'])},
        'u3@example.com': {'type1': set(['read', 'write'])},
        'u1@example.com': {'type1': set(['read', 'write', 'list']),
                           'type2': set(['read', 'write'])},
        }

    to_del_user = 'todelete@example.com'

    self.g._GetGroupMembersAndPermissions.return_value = group_users

    mock_key_to_del = mock.MagicMock()
    mock_key_u1 = mock.MagicMock()

    all_mock.return_value = [mock_key_to_del, mock_key_u1]

    mock_key_to_del.name.return_value = to_del_user
    mock_key_u1.name.return_value = 'u1@example.com'

    from_path_mock.return_value = 'todeluserkey'

    to_add = []

    calls = []
    for u, p in group_users.iteritems():
      calls.append((u, p, 'toadd-%s' % u))
      to_add.append('toadd-%s' % u)

    def MatchCallSideEffect(a1, a2):
      for u, p, r in calls:
        if u != a1 or p != a2:
          continue
        return r
      raise ValueError
    self.g._MakeUserEntity.side_effect = MatchCallSideEffect

    self.g.get()

    from_path_mock.assert_called_once_with(
        group_sync.models.User.__name__, to_del_user)

    self.g._BatchDatastoreOp.assert_has_calls([
        mock.call(group_sync.db.delete, ['todeluserkey']),
        mock.call(group_sync.db.put, to_add)])
dataset/ETHPy150Open google/cauliflowervest/src/tests/cauliflowervest/server/cron/group_sync_test.py/GroupSyncTest.testGet/original