You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wf...@apache.org on 2014/11/06 07:00:10 UTC

[1/2] Convert most uses of Mock to create_autospec, remove some uses of mocking altogether.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 0ad2fcabb -> d01f0c382


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_create.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_create.py b/src/test/python/apache/aurora/client/commands/test_create.py
index be69ed5..d7c32b3 100644
--- a/src/test/python/apache/aurora/client/commands/test_create.py
+++ b/src/test/python/apache/aurora/client/commands/test_create.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from pystachio.config import Config
 from twitter.common.contextutil import temporary_file
 
@@ -38,23 +38,24 @@ class TestClientCreateCommand(AuroraClientCommandTest):
   @classmethod
   def setup_mock_options(cls):
     """set up to get a mock options object."""
-    mock_options = Mock()
+    mock_options = create_autospec(spec={}, instance=True)
     mock_options.json = False
     mock_options.bindings = {}
     mock_options.open_browser = False
     mock_options.cluster = None
     mock_options.wait_until = 'RUNNING'  # or 'FINISHED' for other tests
     mock_options.disable_all_hooks = False
+    mock_options.disable_all_hooks_reason = None
     return mock_options
 
   @classmethod
   def create_mock_task(cls, task_id, instance_id, initial_time, status):
-    mock_task = Mock(spec=ScheduledTask)
-    mock_task.assignedTask = Mock(spec=AssignedTask)
+    mock_task = create_autospec(spec=ScheduledTask, instance=True)
+    mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
     mock_task.assignedTask.taskId = task_id
     mock_task.assignedTask.instanceId = instance_id
     mock_task.status = status
-    mock_task_event = Mock(spec=TaskEvent)
+    mock_task_event = create_autospec(spec=TaskEvent, instance=True)
     mock_task_event.timestamp = initial_time
     mock_task.taskEvents = [mock_task_event]
     return mock_task
@@ -62,7 +63,10 @@ class TestClientCreateCommand(AuroraClientCommandTest):
   @classmethod
   def create_mock_status_query_result(cls, scheduleStatus):
     mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
+    mock_query_result.result.scheduleStatusResult = create_autospec(
+        spec=ScheduleStatusResult,
+        spec_set=False,
+        instance=True)
     mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
     mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
     mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_diff.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_diff.py b/src/test/python/apache/aurora/client/commands/test_diff.py
index 9a486c3..b48b53d 100644
--- a/src/test/python/apache/aurora/client/commands/test_diff.py
+++ b/src/test/python/apache/aurora/client/commands/test_diff.py
@@ -15,7 +15,7 @@
 import contextlib
 import os
 
-from mock import Mock, patch
+from mock import create_autospec, Mock, patch
 from pystachio.config import Config
 from twitter.common.contextutil import temporary_file
 
@@ -32,6 +32,7 @@ from gen.apache.aurora.api.ttypes import (
     JobKey,
     PopulateJobResult,
     ResponseCode,
+    Result,
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
@@ -59,14 +60,13 @@ class TestDiffCommand(AuroraClientCommandTest):
   def create_mock_scheduled_tasks(cls):
     jobs = []
     for name in ['foo', 'bar', 'baz']:
-      job = Mock(spec=ScheduledTask)
+      job = create_autospec(spec=ScheduledTask, instance=True)
       job.failure_count = 0
-      job.assignedTask = Mock(spec=AssignedTask)
+      job.assignedTask = create_autospec(spec=AssignedTask, instance=True)
       job.assignedTask.slaveHost = 'slavehost'
-      job.assignedTask.task = Mock(spec=TaskConfig)
+      job.assignedTask.task = create_autospec(spec=TaskConfig, instance=True)
       job.assignedTask.task.maxTaskFailures = 1
-      job.assignedTask.task.executorConfig = Mock(spec=ExecutorConfig)
-      job.assignedTask.task.executorConfig.data = Mock()
+      job.assignedTask.task.executorConfig = ExecutorConfig(name='name', data='fake data')
       job.assignedTask.task.metadata = []
       job.assignedTask.task.job = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
       job.assignedTask.task.owner = Identity(role='mchucarroll')
@@ -78,7 +78,7 @@ class TestDiffCommand(AuroraClientCommandTest):
       job.assignedTask.instanceId = 4237894
       job.assignedTask.assignedPorts = None
       job.status = ScheduleStatus.RUNNING
-      mockEvent = Mock(spec=TaskEvent)
+      mockEvent = create_autospec(spec=TaskEvent, instance=True)
       mockEvent.timestamp = 28234726395
       mockEvent.status = ScheduleStatus.RUNNING
       mockEvent.message = "Hi there"
@@ -89,8 +89,8 @@ class TestDiffCommand(AuroraClientCommandTest):
   @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    resp.result.scheduleStatusResult.tasks = set(cls.create_mock_scheduled_tasks())
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(tasks=set(cls.create_mock_scheduled_tasks())))
     return resp
 
   @classmethod
@@ -100,10 +100,12 @@ class TestDiffCommand(AuroraClientCommandTest):
   @classmethod
   def setup_populate_job_config(cls, api):
     populate = cls.create_simple_success_response()
-    populate.result.populateJobResult = Mock(spec=PopulateJobResult)
+
     api.populateJobConfig.return_value = populate
     tasks = set(task.assignedTask.task for task in cls.create_mock_scheduled_tasks())
-    populate.result.populateJobResult.populatedDEPRECATED = tasks
+    populate.result = Result(populateJobResult=PopulateJobResult(
+      populatedDEPRECATED=tasks
+    ))
     return populate
 
   def test_successful_diff(self):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_hooks.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_hooks.py b/src/test/python/apache/aurora/client/commands/test_hooks.py
index 638fba6..de1781e 100644
--- a/src/test/python/apache/aurora/client/commands/test_hooks.py
+++ b/src/test/python/apache/aurora/client/commands/test_hooks.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.commands.core import create
@@ -25,6 +25,7 @@ from .util import AuroraClientCommandTest
 
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
+    Result,
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
@@ -50,7 +51,7 @@ class TestClientCreateCommand(AuroraClientCommandTest):
   @classmethod
   def setup_mock_options(cls):
     """set up to get a mock options object."""
-    mock_options = Mock()
+    mock_options = create_autospec(spec={}, instance=True)
     mock_options.json = False
     mock_options.bindings = {}
     mock_options.open_browser = False
@@ -61,12 +62,12 @@ class TestClientCreateCommand(AuroraClientCommandTest):
 
   @classmethod
   def create_mock_task(cls, task_id, instance_id, initial_time, status):
-    mock_task = Mock(spec=ScheduledTask)
-    mock_task.assignedTask = Mock(spec=AssignedTask)
+    mock_task = create_autospec(spec=ScheduledTask, instance=True)
+    mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
     mock_task.assignedTask.taskId = task_id
     mock_task.assignedTask.instanceId = instance_id
     mock_task.status = status
-    mock_task_event = Mock(spec=TaskEvent)
+    mock_task_event = create_autospec(spec=TaskEvent, instance=True)
     mock_task_event.timestamp = initial_time
     mock_task.taskEvents = [mock_task_event]
     return mock_task
@@ -74,14 +75,15 @@ class TestClientCreateCommand(AuroraClientCommandTest):
   @classmethod
   def create_mock_status_query_result(cls, scheduleStatus):
     mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
+
     if scheduleStatus == ScheduleStatus.INIT:
       # status query result for before job is launched.
-      mock_query_result.result.scheduleStatusResult.tasks = []
+      tasks = []
     else:
       mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
       mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
-      mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]
+      tasks = [mock_task_one, mock_task_two]
+    mock_query_result.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
     return mock_query_result
 
   @classmethod

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_kill.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_kill.py b/src/test/python/apache/aurora/client/commands/test_kill.py
index 8194c96..4ac742f 100644
--- a/src/test/python/apache/aurora/client/commands/test_kill.py
+++ b/src/test/python/apache/aurora/client/commands/test_kill.py
@@ -13,8 +13,9 @@
 #
 
 import contextlib
+import threading
 
-from mock import Mock, patch
+from mock import create_autospec, Mock, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.commands.core import CoreCommandHook, kill, killall
@@ -31,6 +32,7 @@ from gen.apache.aurora.api.ttypes import (
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
+    TaskConfig,
     TaskEvent,
     TaskQuery
 )
@@ -41,7 +43,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
   @classmethod
   def setup_mock_options(cls):
     """set up to get a mock options object."""
-    mock_options = Mock()
+    mock_options = create_autospec(spec=[], instance=True)
     mock_options.open_browser = False
     mock_options.shards = None
     mock_options.cluster = None
@@ -49,12 +51,14 @@ class TestClientKillCommand(AuroraClientCommandTest):
     mock_options.batch_size = None
     mock_options.max_total_failures = 1
     mock_options.disable_all_hooks = False
+    mock_options.disable_all_hooks_reason = None
+    mock_options.max_failures_option = None
     return mock_options
 
   @classmethod
   def setup_mock_api_factory(cls):
     mock_api_factory, mock_api = cls.create_mock_api_factory()
-    mock_api_factory.return_value.kill_job.return_value = cls.get_kill_job_response()
+    mock_api_factory('x').return_value.kill_job.return_value = cls.get_kill_job_response()
     return mock_api_factory
 
   @classmethod
@@ -71,12 +75,12 @@ class TestClientKillCommand(AuroraClientCommandTest):
 
   @classmethod
   def create_mock_task(cls, task_id, instance_id, initial_time, status):
-    mock_task = Mock(spec=ScheduledTask)
-    mock_task.assignedTask = Mock(spec=AssignedTask)
+    mock_task = create_autospec(spec=ScheduledTask, instance=True)
+    mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
     mock_task.assignedTask.taskId = task_id
     mock_task.assignedTask.instanceId = instance_id
     mock_task.status = status
-    mock_task_event = Mock(spec=TaskEvent)
+    mock_task_event = create_autospec(spec=TaskEvent, instance=True)
     mock_task_event.timestamp = initial_time
     mock_task.taskEvents = [mock_task_event]
     return mock_task
@@ -84,7 +88,10 @@ class TestClientKillCommand(AuroraClientCommandTest):
   @classmethod
   def create_mock_status_query_result(cls, scheduleStatus):
     mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
+    mock_query_result.result.scheduleStatusResult = create_autospec(
+        spec=ScheduleStatusResult,
+        spec_set=False,
+        instance=True)
     task = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
     mock_query_result.result.scheduleStatusResult.tasks = [task]
     return mock_query_result
@@ -143,14 +150,13 @@ class TestClientKillCommand(AuroraClientCommandTest):
         patch('twitter.common.app.get_options', return_value=mock_options),
         patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
 
-      mock_api = mock_api_factory.return_value
+      mock_api = mock_api_factory('x').return_value
       with temporary_file() as fp:
         fp.write(self.get_valid_config())
         fp.flush()
         self.assertRaises(SystemExit, kill, ['west/mchucarroll/test/hello', fp.name], mock_options)
 
-      # Now check that the right API calls got made.
-      mock_api.kill_job.call_count == 0
+      assert mock_api.kill_job.call_count == 0
 
   def test_simple_successful_killall_job(self):
     """Run a test of the "kill" command against a mocked-out API:
@@ -168,19 +174,20 @@ class TestClientKillCommand(AuroraClientCommandTest):
         self.create_mock_status_query_result(ScheduleStatus.KILLED),
     ]
     mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = mock_query_results
+    mock_event = create_autospec(spec=threading.Event)
     with contextlib.nested(
         patch('time.sleep'),
         patch('apache.aurora.client.commands.core.make_client',
             return_value=mock_api),
         patch('twitter.common.app.get_options', return_value=mock_options),
-        patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
+        patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config),
+        patch('threading._Event.wait', return_value=mock_event)):
 
       with temporary_file() as fp:
         fp.write(self.get_valid_config())
         fp.flush()
         killall(['west/mchucarroll/test/hello', fp.name], mock_options)
 
-      # Now check that the right API calls got made.
       self.assert_kill_job_called(mock_api)
       mock_api.kill_job.assert_called_with(
         AuroraJobKey(cluster=self.TEST_CLUSTER, role=self.TEST_ROLE, env=self.TEST_ENV,
@@ -216,18 +223,13 @@ class TestClientKillCommand(AuroraClientCommandTest):
         patch('apache.aurora.client.commands.core.make_client',
             return_value=mock_api),
         patch('twitter.common.app.get_options', return_value=mock_options),
-        patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)) as (
-            sleep,
-            mock_make_client,
-            options,
-            mock_get_job_config):
+        patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
 
       with temporary_file() as fp:
         fp.write(self.get_valid_config())
         fp.flush()
         killall(['west/mchucarroll/test/hello', fp.name], mock_options)
 
-      # Now check that the right API calls got made.
       self.assert_kill_job_called(mock_api)
       mock_api.kill_job.assert_called_with(
         AuroraJobKey(cluster=self.TEST_CLUSTER, role=self.TEST_ROLE, env=self.TEST_ENV,
@@ -259,11 +261,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
         patch('apache.aurora.client.commands.core.make_client',
             return_value=mock_api),
         patch('twitter.common.app.get_options', return_value=mock_options),
-        patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)) as (
-            sleep,
-            mock_make_client,
-            options,
-            mock_get_job_config):
+        patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
 
       with temporary_file() as fp:
         fp.write(self.get_valid_config())
@@ -272,31 +270,28 @@ class TestClientKillCommand(AuroraClientCommandTest):
             SystemExit, killall, ['west/mchucarroll/test/hello', fp.name], mock_options)
 
       CoreCommandHook.clear_hooks()
-      mock_api.kill_job.call_count == 0
+      assert mock_api.kill_job.call_count == 0
 
   def create_status_call_result(cls):
     """Set up the mock status call that will be used to get a task list for
     a batched kill command.
     """
-    status_response = Mock(spec=Response)
-    status_response.responseCode = ResponseCode.OK
-    status_response.messageDEPRECATED = "Ok"
-    status_response.result = Mock(spec=Result)
-    schedule_status = Mock(spec=ScheduleStatusResult)
-    status_response.result.scheduleStatusResult = schedule_status
-    mock_task_config = Mock()
-    # This should be a list of ScheduledTask's.
-    schedule_status.tasks = []
+    tasks = []
     for i in range(20):
-      task_status = Mock(spec=ScheduledTask)
-      task_status.assignedTask = Mock(spec=AssignedTask)
-      task_status.assignedTask.instanceId = i
-      task_status.assignedTask.taskId = "Task%s" % i
-      task_status.assignedTask.slaveId = "Slave%s" % i
-      task_status.slaveHost = "Slave%s" % i
-      task_status.assignedTask.task = mock_task_config
-      schedule_status.tasks.append(task_status)
-    return status_response
+      tasks.append(ScheduledTask(
+        assignedTask=AssignedTask(
+          instanceId=i,
+          taskId='Task%s' % i,
+          slaveId='Slave%s' % i,
+          slaveHost='SlaveHost%s' % i,
+          task=TaskConfig()
+        )
+      ))
+    return Response(
+        responseCode=ResponseCode.OK,
+        messageDEPRECATED='Ok',
+        result=Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
+    )
 
   def test_successful_batched_killall_job(self):
     """Run a test of the "kill" command against a mocked-out API:
@@ -439,6 +434,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
     mock_options = self.setup_mock_options()
     mock_options.batch_size = 2
     mock_options.shards = [0, 1, 2, 3]
+    mock_options.max_failures_option = 3
     mock_config = Mock()
     mock_config.hooks = []
     mock_config.raw.return_value.enable_hooks.return_value.get.return_value = False
@@ -460,7 +456,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
         # We should get an exception in this case, because the one of the two calls fails.
         self.assertRaises(SystemExit, kill, ['west/mchucarroll/test/hello', fp.name], mock_options)
 
-      # killTasks should still have gotten called twice - the first error shouldn't abort
+      # killTasks should still have been called twice - the first error shouldn't abort
       # the second batch.
       assert mock_scheduler_proxy.killTasks.call_count == 2
       query = self.get_expected_task_query([2, 3])

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_listjobs.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_listjobs.py b/src/test/python/apache/aurora/client/commands/test_listjobs.py
index d9fa617..a7cb98f 100644
--- a/src/test/python/apache/aurora/client/commands/test_listjobs.py
+++ b/src/test/python/apache/aurora/client/commands/test_listjobs.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, Mock, patch
 
 from apache.aurora.client.commands.core import list_jobs
 
@@ -46,7 +46,7 @@ class TestListJobs(AuroraClientCommandTest):
   @classmethod
   def create_listjobs_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.getJobsResult = Mock(spec=GetJobsResult)
+    resp.result.getJobsResult = create_autospec(spec=GetJobsResult, instance=True)
     resp.result.getJobsResult.configs = set(cls.create_mock_jobs())
     return resp
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_restart.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_restart.py b/src/test/python/apache/aurora/client/commands/test_restart.py
index 6da9e73..3789f3b 100644
--- a/src/test/python/apache/aurora/client/commands/test_restart.py
+++ b/src/test/python/apache/aurora/client/commands/test_restart.py
@@ -14,8 +14,9 @@
 
 import contextlib
 import functools
+from collections import namedtuple
 
-from mock import Mock, patch
+from mock import call, create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.api.health_check import Retriable, StatusHealthCheck
@@ -23,38 +24,53 @@ from apache.aurora.client.commands.core import restart
 
 from .util import AuroraClientCommandTest
 
+from gen.apache.aurora.api.constants import ACTIVE_STATES
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
     JobKey,
     PopulateJobResult,
+    Result,
     ScheduledTask,
     ScheduleStatusResult,
-    TaskConfig
+    TaskConfig,
+    TaskQuery
 )
 
 
-class TestRestartCommand(AuroraClientCommandTest):
+class FakeOptions(namedtuple('FakeOptions', ['max_total_failures',
+     'disable_all_hooks_reason',
+     'batch_size',
+     'restart_threshold',
+     'watch_secs',
+     'max_per_shard_failures',
+     'shards',
+     'health_check_interval_seconds',
+     'open_browser'])):
+
+  def __new__(cls,
+      max_total_failures=None,
+      disable_all_hooks_reason=None,
+      batch_size=None,
+      restart_threshold=None,
+      watch_secs=None,
+      max_per_shard_failures=None,
+      shards=None,
+      health_check_interval_seconds=None,
+      open_browser=None):
+    return super(FakeOptions, cls).__new__(
+        cls,
+        max_total_failures,
+        disable_all_hooks_reason,
+        batch_size,
+        restart_threshold,
+        watch_secs,
+        max_per_shard_failures,
+        shards,
+        health_check_interval_seconds,
+        open_browser)
 
-  @classmethod
-  def setup_mock_options(cls):
-    """set up to get a mock options object."""
-    mock_options = Mock(
-        spec=['json', 'bindings', 'open_browser', 'shards', 'cluster',
-              'health_check_interval_seconds', 'batch_size', 'max_per_shard_failures',
-              'max_total_failures', 'restart_threshold', 'watch_secs'])
-    mock_options.json = False
-    mock_options.bindings = {}
-    mock_options.open_browser = False
-    mock_options.shards = None
-    mock_options.cluster = None
-    mock_options.health_check_interval_seconds = 3
-    mock_options.batch_size = 5
-    mock_options.max_per_shard_failures = 0
-    mock_options.max_total_failures = 0
-    mock_options.restart_threshold = 30
-    mock_options.watch_secs = 30
-    mock_options.disable_all_hooks_reason = None
-    return mock_options
+
+class TestRestartCommand(AuroraClientCommandTest):
 
   @classmethod
   def setup_mock_scheduler_for_simple_restart(cls, api):
@@ -67,61 +83,63 @@ class TestRestartCommand(AuroraClientCommandTest):
   @classmethod
   def setup_populate_job_config(cls, api):
     populate = cls.create_simple_success_response()
-    populate.result.populateJobResult = Mock(spec=PopulateJobResult)
+    populate.result.populateJobResult = create_autospec(
+        spec=PopulateJobResult,
+        spec_set=False,
+        instance=True,
+        watch_secs=None)
     api.populateJobConfig.return_value = populate
     configs = []
     for i in range(20):
-      task_config = Mock(spec=TaskConfig)
+      task_config = create_autospec(spec=TaskConfig, instance=True)
       configs.append(task_config)
     populate.result.populateJobResult.populatedDEPRECATED = set(configs)
     return populate
 
   @classmethod
   def setup_get_tasks_status_calls(cls, scheduler):
+
+    tasks = []
+    for i in range(20):
+      tasks.append(ScheduledTask(
+        assignedTask=AssignedTask(
+          slaveHost='slave%s' % i,
+          instanceId=i,
+          taskId='task%s' % i,
+          slaveId='slave%s' % i,
+          task=TaskConfig())))
     status_response = cls.create_simple_success_response()
+    status_response.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
     scheduler.getTasksWithoutConfigs.return_value = status_response
-    schedule_status = Mock(spec=ScheduleStatusResult)
-    status_response.result.scheduleStatusResult = schedule_status
-    mock_task_config = Mock()
-    # This should be a list of ScheduledTask's.
-    schedule_status.tasks = []
-    for i in range(20):
-      task_status = Mock(spec=ScheduledTask)
-      task_status.assignedTask = Mock(spec=AssignedTask)
-      task_status.assignedTask.instanceId = i
-      task_status.assignedTask.taskId = "Task%s" % i
-      task_status.assignedTask.slaveId = "Slave%s" % i
-      task_status.slaveHost = "Slave%s" % i
-      task_status.assignedTask.task = mock_task_config
-      schedule_status.tasks.append(task_status)
 
   @classmethod
   def setup_health_checks(cls, mock_api):
-    mock_health_check = Mock(spec=StatusHealthCheck)
+    mock_health_check = create_autospec(spec=StatusHealthCheck, instance=True)
     mock_health_check.health.return_value = Retriable.alive()
     return mock_health_check
 
   def test_restart_simple(self):
-    # Test the client-side restart logic in its simplest case: everything succeeds
-    mock_options = self.setup_mock_options()
+    options = FakeOptions(
+        max_total_failures=1,
+        batch_size=5,
+        restart_threshold=10,
+        watch_secs=10)
     (mock_api, mock_scheduler_proxy) = self.create_mock_api()
     mock_health_check = self.setup_health_checks(mock_api)
     self.setup_mock_scheduler_for_simple_restart(mock_api)
     with contextlib.nested(
-        patch('twitter.common.app.get_options', return_value=mock_options),
+        patch('twitter.common.app.get_options', return_value=options),
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
         patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('apache.aurora.client.api.instance_watcher.StatusHealthCheck',
             return_value=mock_health_check),
         patch('time.time', side_effect=functools.partial(self.fake_time, self)),
-        patch('threading._Event.wait')
-    ) as (options, scheduler_proxy_class, test_clusters, mock_health_check_factory,
-        time_patch, sleep_patch):
+        patch('threading._Event.wait')):
 
       with temporary_file() as fp:
         fp.write(self.get_valid_config())
         fp.flush()
-        restart(['west/mchucarroll/test/hello'], mock_options)
+        restart(['west/mchucarroll/test/hello'], options)
 
         # Like the update test, the exact number of calls here doesn't matter.
         # what matters is that it must have been called once before batching, plus
@@ -134,43 +152,37 @@ class TestRestartCommand(AuroraClientCommandTest):
             role=self.TEST_ROLE, name=self.TEST_JOB), [15, 16, 17, 18, 19], None)
 
   def test_restart_simple_invalid_max_failures(self):
-    # Test the client-side restart logic in its simplest case: everything succeeds
-    mock_options = self.setup_mock_options()
-    mock_options.max_total_failures = -1
-    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+    options = FakeOptions(
+        max_total_failures=None,
+        batch_size=5,
+        restart_threshold=10,
+        watch_secs=10)
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
     mock_health_check = self.setup_health_checks(mock_api)
     self.setup_mock_scheduler_for_simple_restart(mock_api)
     with contextlib.nested(
-        patch('twitter.common.app.get_options', return_value=mock_options),
+        patch('twitter.common.app.get_options', return_value=options),
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
         patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('apache.aurora.client.api.instance_watcher.StatusHealthCheck',
             return_value=mock_health_check),
         patch('time.time', side_effect=functools.partial(self.fake_time, self)),
-        patch('threading._Event.wait')
-    ) as (options, scheduler_proxy_class, test_clusters, mock_health_check_factory,
-        time_patch, sleep_patch):
+        patch('threading._Event.wait')):
 
       with temporary_file() as fp:
         fp.write(self.get_valid_config())
         fp.flush()
-        self.assertRaises(SystemExit, restart, ['west/mchucarroll/test/hello'], mock_options)
-
-        # Like the update test, the exact number of calls here doesn't matter.
-        # what matters is that it must have been called once before batching, plus
-        # at least once per batch, and there are 4 batches.
-        assert mock_scheduler_proxy.getTasksWithoutConfigs.call_count == 0
-        # called once per batch
-        assert mock_scheduler_proxy.restartShards.call_count == 0
+        self.assertRaises(SystemExit, restart, ['west/mchucarroll/test/hello'], options)
+        assert mock_scheduler_proxy.mock_calls == []
 
   def test_restart_failed_status(self):
-    mock_options = self.setup_mock_options()
-    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+    options = FakeOptions()
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
     mock_health_check = self.setup_health_checks(mock_api)
     self.setup_mock_scheduler_for_simple_restart(mock_api)
     mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_error_response()
     with contextlib.nested(
-        patch('twitter.common.app.get_options', return_value=mock_options),
+        patch('twitter.common.app.get_options', return_value=options),
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
         patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('apache.aurora.client.api.instance_watcher.StatusHealthCheck',
@@ -183,34 +195,39 @@ class TestRestartCommand(AuroraClientCommandTest):
       with temporary_file() as fp:
         fp.write(self.get_valid_config())
         fp.flush()
-        self.assertRaises(SystemExit, restart, ['west/mchucarroll/test/hello'], mock_options)
-        assert mock_scheduler_proxy.getTasksWithoutConfigs.call_count == 1
-        assert mock_scheduler_proxy.restartShards.call_count == 0
+        self.assertRaises(SystemExit, restart, ['west/mchucarroll/test/hello'], options)
+        # TODO(wfarner): Spread this pattern further, as it flags unexpected method calls.
+        assert mock_scheduler_proxy.mock_calls == [
+          call.getTasksWithoutConfigs(
+              TaskQuery(jobKeys=[JobKey('mchucarroll', 'test', 'hello')], statuses=ACTIVE_STATES))
+        ]
 
   def test_restart_failed_restart(self):
-    # Test the client-side updater logic in its simplest case: everything succeeds, and no rolling
-    # updates.
-    mock_options = self.setup_mock_options()
-    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+    options = FakeOptions(
+        max_total_failures=1,
+        batch_size=5,
+        restart_threshold=10,
+        watch_secs=10)
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
     mock_health_check = self.setup_health_checks(mock_api)
     self.setup_mock_scheduler_for_simple_restart(mock_api)
     mock_scheduler_proxy.restartShards.return_value = self.create_error_response()
     with contextlib.nested(
-        patch('twitter.common.app.get_options', return_value=mock_options),
+        patch('twitter.common.app.get_options', return_value=options),
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
         patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('apache.aurora.client.api.instance_watcher.StatusHealthCheck',
             return_value=mock_health_check),
         patch('time.time', side_effect=functools.partial(self.fake_time, self)),
-        patch('threading._Event.wait')
-    ) as (options, scheduler_proxy_class, test_clusters, mock_health_check_factory,
-        time_patch, sleep_patch):
+        patch('threading._Event.wait')):
 
       with temporary_file() as fp:
         fp.write(self.get_valid_config())
         fp.flush()
-        self.assertRaises(SystemExit, restart, ['west/mchucarroll/test/hello'], mock_options)
+        self.assertRaises(SystemExit, restart, ['west/mchucarroll/test/hello'], options)
         assert mock_scheduler_proxy.getTasksWithoutConfigs.call_count == 1
         assert mock_scheduler_proxy.restartShards.call_count == 1
-        mock_scheduler_proxy.restartShards.assert_called_with(JobKey(environment=self.TEST_ENV,
-            role=self.TEST_ROLE, name=self.TEST_JOB), [0, 1, 2, 3, 4], None)
+        mock_scheduler_proxy.restartShards.assert_called_with(
+            JobKey(environment=self.TEST_ENV, role=self.TEST_ROLE, name=self.TEST_JOB),
+            [0, 1, 2, 3, 4],
+            None)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_run.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_run.py b/src/test/python/apache/aurora/client/commands/test_run.py
index 738a42b..528c3e9 100644
--- a/src/test/python/apache/aurora/client/commands/test_run.py
+++ b/src/test/python/apache/aurora/client/commands/test_run.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, Mock, patch
 
 from apache.aurora.client.commands.run import run
 
@@ -26,6 +26,7 @@ from gen.apache.aurora.api.ttypes import (
     Identity,
     JobKey,
     ResponseCode,
+    ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
     TaskConfig,
@@ -49,39 +50,41 @@ class TestRunCommand(AuroraClientCommandTest):
 
   @classmethod
   def create_mock_scheduled_tasks(cls):
-    jobs = []
+    tasks = []
     for name in ['foo', 'bar', 'baz']:
-      job = Mock()
-      job.key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
-      job.failure_count = 0
-      job.assignedTask = Mock(spec=AssignedTask)
-      job.assignedTask.taskId = 1287391823
-      job.assignedTask.slaveHost = 'slavehost'
-      job.assignedTask.task = Mock(spec=TaskConfig)
-      job.assignedTask.task.executorConfig = Mock()
-      job.assignedTask.task.maxTaskFailures = 1
-      job.assignedTask.task.metadata = []
-      job.assignedTask.task.owner = Identity(role='mchucarroll')
-      job.assignedTask.task.environment = 'test'
-      job.assignedTask.task.jobName = 'woops'
-      job.assignedTask.task.numCpus = 2
-      job.assignedTask.task.ramMb = 2
-      job.assignedTask.task.diskMb = 2
-      job.assignedTask.instanceId = 4237894
-      job.assignedTask.assignedPorts = {}
-      job.status = ScheduleStatus.RUNNING
-      mockEvent = Mock(spec=TaskEvent)
-      mockEvent.timestamp = 28234726395
-      mockEvent.status = ScheduleStatus.RUNNING
-      mockEvent.message = "Hi there"
-      job.taskEvents = [mockEvent]
-      jobs.append(job)
-    return jobs
+      task = ScheduledTask(
+        failureCount=0,
+        status=ScheduleStatus.RUNNING,
+        taskEvents=[
+            TaskEvent(timestamp=123, status=ScheduleStatus.RUNNING, message='Fake message')],
+        assignedTask=AssignedTask(
+            assignedPorts={},
+            slaveHost='slavehost',
+            instanceId=0,
+            taskId='taskid',
+            task=TaskConfig(
+                maxTaskFailures=1,
+                executorConfig='fake data',
+                metadata=[],
+                owner=Identity(role='fakerole'),
+                environment='test',
+                jobName=name,
+                numCpus=2,
+                ramMb=2,
+                diskMb=2
+            )
+        )
+      )
+      tasks.append(task)
+    return tasks
 
   @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
+    resp.result.scheduleStatusResult = create_autospec(
+        spec=ScheduleStatusResult,
+        spec_set=False,
+        instance=True)
     resp.result.scheduleStatusResult.tasks = cls.create_mock_scheduled_tasks()
     return resp
 
@@ -127,6 +130,6 @@ class TestRunCommand(AuroraClientCommandTest):
       # The mock status call returns 3 three ScheduledTasks, so three commands should have been run
       assert mock_subprocess.call_count == 3
       mock_subprocess.assert_called_with(['ssh', '-n', '-q', 'mchucarroll@slavehost',
-          'cd /slaveroot/slaves/*/frameworks/*/executors/thermos-1287391823/runs/'
+          'cd /slaveroot/slaves/*/frameworks/*/executors/thermos-taskid/runs/'
           'slaverun/sandbox;ls'],
           stderr=-2, stdout=-1)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_ssh.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_ssh.py b/src/test/python/apache/aurora/client/commands/test_ssh.py
index 6d51bb3..5af9133 100644
--- a/src/test/python/apache/aurora/client/commands/test_ssh.py
+++ b/src/test/python/apache/aurora/client/commands/test_ssh.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, Mock, patch
 
 from apache.aurora.client.commands.ssh import ssh
 
@@ -54,10 +54,10 @@ class TestSshCommand(AuroraClientCommandTest):
       job = Mock()
       job.key = job_key
       job.failure_count = 0
-      job.assignedTask = Mock(spec=AssignedTask)
+      job.assignedTask = create_autospec(spec=AssignedTask, instance=True)
       job.assignedTask.taskId = 1287391823
       job.assignedTask.slaveHost = 'slavehost'
-      job.assignedTask.task = Mock(spec=TaskConfig)
+      job.assignedTask.task = create_autospec(spec=TaskConfig, instance=True)
       job.assignedTask.task.executorConfig = Mock()
       job.assignedTask.task.maxTaskFailures = 1
       job.assignedTask.task.metadata = []
@@ -71,7 +71,7 @@ class TestSshCommand(AuroraClientCommandTest):
       job.assignedTask.instanceId = 4237894
       job.assignedTask.assignedPorts = {}
       job.status = ScheduleStatus.RUNNING
-      mockEvent = Mock(spec=TaskEvent)
+      mockEvent = create_autospec(spec=TaskEvent, instance=True)
       mockEvent.timestamp = 28234726395
       mockEvent.status = ScheduleStatus.RUNNING
       mockEvent.message = "Hi there"

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_status.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_status.py b/src/test/python/apache/aurora/client/commands/test_status.py
index 062b132..003af25 100644
--- a/src/test/python/apache/aurora/client/commands/test_status.py
+++ b/src/test/python/apache/aurora/client/commands/test_status.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import patch
 
 from apache.aurora.client.commands.core import status
 
@@ -25,6 +25,8 @@ from gen.apache.aurora.api.ttypes import (
     Identity,
     JobKey,
     ResponseCode,
+    Result,
+    ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
     TaskConfig,
@@ -35,44 +37,30 @@ from gen.apache.aurora.api.ttypes import (
 
 class TestListJobs(AuroraClientCommandTest):
   @classmethod
-  def setup_mock_options(cls):
-    """set up to get a mock options object."""
-    mock_options = Mock()
-    mock_options.pretty = False
-    mock_options.show_cron = False
-    mock_options.disable_all_hooks = False
-    return mock_options
-
-  @classmethod
   def create_mock_scheduled_tasks(cls):
-    jobs = []
+    tasks = []
     for name in ['foo', 'bar', 'baz']:
-      job_key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
-      job = Mock()
-      job.key = job_key
-      job.failure_count = 0
-      job.assignedTask = Mock(spec=AssignedTask)
-      job.assignedTask.slaveHost = 'slavehost'
-      job.assignedTask.task = Mock(spec=TaskConfig)
-      job.assignedTask.task.maxTaskFailures = 1
-      job.assignedTask.task.metadata = []
-      job.assignedTask.task.job = job_key
-      job.assignedTask.task.owner = Identity(role=cls.TEST_ROLE)
-      job.assignedTask.task.environment = cls.TEST_ENV
-      job.assignedTask.task.jobName = name
-      job.assignedTask.task.numCpus = 2
-      job.assignedTask.task.ramMb = 2
-      job.assignedTask.task.diskMb = 2
-      job.assignedTask.instanceId = 4237894
-      job.assignedTask.assignedPorts = None
-      job.status = ScheduleStatus.RUNNING
-      mockEvent = Mock(spec=TaskEvent)
-      mockEvent.timestamp = 28234726395
-      mockEvent.status = ScheduleStatus.RUNNING
-      mockEvent.message = "Hi there"
-      job.taskEvents = [mockEvent]
-      jobs.append(job)
-    return jobs
+      tasks.append(ScheduledTask(
+          status=ScheduleStatus.RUNNING,
+          failureCount=0,
+          taskEvents=[TaskEvent(timestamp=123, status=ScheduleStatus.RUNNING, message='Hi there')],
+          assignedTask=AssignedTask(
+              instanceId=0,
+              assignedPorts={},
+              task=TaskConfig(
+                  maxTaskFailures=1,
+                  metadata={},
+                  job=JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name),
+                  owner=Identity(role=cls.TEST_ROLE),
+                  environment=cls.TEST_ENV,
+                  jobName=name,
+                  numCpus=2,
+                  ramMb=2,
+                  diskMb=2
+              )
+          )
+      ))
+    return tasks
 
   @classmethod
   def create_mock_scheduled_task_no_metadata(cls):
@@ -84,15 +72,16 @@ class TestListJobs(AuroraClientCommandTest):
   @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    resp.result.scheduleStatusResult.tasks = set(cls.create_mock_scheduled_tasks())
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(tasks=set(cls.create_mock_scheduled_tasks())))
     return resp
 
   @classmethod
   def create_status_null_metadata(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    resp.result.scheduleStatusResult.tasks = set(cls.create_mock_scheduled_task_no_metadata())
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(
+            tasks=set(cls.create_mock_scheduled_task_no_metadata())))
     return resp
 
   @classmethod
@@ -102,15 +91,15 @@ class TestListJobs(AuroraClientCommandTest):
   def test_successful_status(self):
     """Test the status command."""
     # Calls api.check_status, which calls scheduler_proxy.getJobs
-    mock_options = self.setup_mock_options()
+    fake_options = {}
     (mock_api, mock_scheduler_proxy) = self.create_mock_api()
     mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_status_response()
     with contextlib.nested(
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
         patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
-        patch('twitter.common.app.get_options', return_value=mock_options)):
+        patch('twitter.common.app.get_options', return_value=fake_options)):
 
-      status(['west/mchucarroll/test/hello'], mock_options)
+      status(['west/mchucarroll/test/hello'], fake_options)
       # The status command sends a getTasksWithoutConfigs query to the scheduler,
       # and then prints the result.
       mock_scheduler_proxy.getTasksWithoutConfigs.assert_called_with(

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_update.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_update.py b/src/test/python/apache/aurora/client/commands/test_update.py
index e359d32..3f5f83e 100644
--- a/src/test/python/apache/aurora/client/commands/test_update.py
+++ b/src/test/python/apache/aurora/client/commands/test_update.py
@@ -15,7 +15,7 @@
 import contextlib
 import functools
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.api.health_check import Retriable, StatusHealthCheck
@@ -35,8 +35,10 @@ from gen.apache.aurora.api.ttypes import (
     AssignedTask,
     JobConfiguration,
     JobKey,
+    Lock,
     PopulateJobResult,
     ResponseCode,
+    Result,
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
@@ -56,21 +58,20 @@ class TestUpdateCommand(AuroraClientCommandTest):
   @classmethod
   def setup_mock_options(cls):
     """set up to get a mock options object."""
-    mock_options = Mock()
-    mock_options.json = False
-    mock_options.bindings = {}
-    mock_options.open_browser = False
-    mock_options.cluster = None
-    mock_options.force = True
-    mock_options.env = None
-    mock_options.shards = None
-    mock_options.health_check_interval_seconds = 3
-    mock_options.disable_all_hooks = False
+    mock_options = create_autospec(
+        spec=object,
+        spec_set=False,
+        instance=True,
+        json=False,
+        shards=None,
+        health_check_interval_seconds=3,
+        force=True,
+        disable_all_hooks_reason='Fake reason')
     return mock_options
 
   @classmethod
   def setup_mock_updater(cls):
-    updater = Mock(spec=Updater)
+    updater = create_autospec(spec=Updater, instance=True)
     return updater
 
   # First, we pretend that the updater isn't really client-side, and test
@@ -117,8 +118,7 @@ class TestUpdateCommand(AuroraClientCommandTest):
     """Set up all of the API mocks for scheduler calls during a simple update"""
     sched_proxy = api.scheduler_proxy
     # First, the updater acquires a lock
-    sched_proxy.acquireLock.return_value = cls.create_acquire_lock_response(ResponseCode.OK,
-         'OK', 'token', False)
+    sched_proxy.acquireLock.return_value = cls.create_acquire_lock_response(ResponseCode.OK, 'OK')
     # Then in gets the status of the tasks for the updating job.
     cls.setup_get_tasks_status_calls(sched_proxy)
     # Next, it needs to populate the update config.
@@ -145,7 +145,7 @@ class TestUpdateCommand(AuroraClientCommandTest):
   @classmethod
   def setup_populate_job_config(cls, api):
     populate = cls.create_simple_success_response()
-    populate.result.populateJobResult = Mock(spec=PopulateJobResult)
+
     api.populateJobConfig.return_value = populate
     configs = []
     for _ in range(20):
@@ -154,18 +154,18 @@ class TestUpdateCommand(AuroraClientCommandTest):
           ramMb=1,
           diskMb=1,
           job=JobKey(role='mchucarroll', environment='test', name='hello'))
-
       configs.append(task_config)
-    populate.result.populateJobResult.populatedDEPRECATED = set(configs)
+    populate.result = Result(populateJobResult=PopulateJobResult(
+        populatedDEPRECATED=set(configs)
+    ))
     return populate
 
   @classmethod
-  def create_acquire_lock_response(cls, code, msg, token, rolling):
+  def create_acquire_lock_response(cls, code, msg):
     """Set up the response to a startUpdate API call."""
     start_update_response = cls.create_blank_response(code, msg)
-    start_update_response.result.acquireLockResult = Mock(spec=AcquireLockResult)
-    start_update_response.result.acquireLockResult.lock = "foo"
-    start_update_response.result.acquireLockResult.updateToken = 'token'
+    start_update_response.result = Result(
+        acquireLockResult=AcquireLockResult(lock=Lock(key='foo', token='token')))
     return start_update_response
 
   @classmethod
@@ -180,7 +180,7 @@ class TestUpdateCommand(AuroraClientCommandTest):
     status_response = cls.create_simple_success_response()
     scheduler_proxy.getTasksStatus.return_value = status_response
     scheduler_proxy.getTasksWithoutConfigs.return_value = status_response
-    schedule_status = Mock(spec=ScheduleStatusResult)
+    schedule_status = create_autospec(spec=ScheduleStatusResult, instance=True)
     status_response.result.scheduleStatusResult = schedule_status
     task_config = TaskConfig(
         numCpus=1.0,
@@ -191,8 +191,8 @@ class TestUpdateCommand(AuroraClientCommandTest):
     # This should be a list of ScheduledTask's.
     schedule_status.tasks = []
     for i in range(20):
-      task_status = Mock(spec=ScheduledTask)
-      task_status.assignedTask = Mock(spec=AssignedTask)
+      task_status = create_autospec(spec=ScheduledTask, instance=True)
+      task_status.assignedTask = create_autospec(spec=AssignedTask, instance=True)
       task_status.assignedTask.instanceId = i
       task_status.assignedTask.taskId = "Task%s" % i
       task_status.assignedTask.slaveId = "Slave%s" % i
@@ -207,20 +207,20 @@ class TestUpdateCommand(AuroraClientCommandTest):
 
   @classmethod
   def setup_health_checks(cls, mock_api):
-    mock_health_check = Mock(spec=StatusHealthCheck)
+    mock_health_check = create_autospec(spec=StatusHealthCheck, instance=True)
     mock_health_check.health.return_value = Retriable.alive()
     return mock_health_check
 
   @classmethod
   def setup_quota_check(cls):
-    mock_quota_check = Mock(spec=QuotaCheck)
+    mock_quota_check = create_autospec(spec=QuotaCheck, instance=True)
     mock_quota_check.validate_quota_from_requested.return_value = (
         cls.create_simple_success_response())
     return mock_quota_check
 
   @classmethod
   def setup_job_monitor(cls):
-    mock_job_monitor = Mock(spec=JobMonitor)
+    mock_job_monitor = create_autospec(spec=JobMonitor, instance=True)
     mock_job_monitor.wait_until.return_value = True
     return mock_job_monitor
 
@@ -286,7 +286,7 @@ class TestUpdateCommand(AuroraClientCommandTest):
             jobKeys=[JobKey(role='mchucarroll', environment='test', name='hello')],
             instanceIds=frozenset([19]),
             statuses=ACTIVE_STATES),
-        'foo')
+        Lock(key='foo', token='token'))
 
   @classmethod
   def assert_correct_status_calls(cls, api):
@@ -302,7 +302,7 @@ class TestUpdateCommand(AuroraClientCommandTest):
       status_call[0][0] == TaskQuery(
         taskIds=None,
         jobKeys=[JobKey(role='mchucarroll', environment='test', name='hello')],
-        statuses=set([ScheduleStatus.RUNNING]))
+        statuses={ScheduleStatus.RUNNING})
 
     # getTasksStatus is called only once to build an generate update instructions
     assert api.getTasksStatus.call_count == 1

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/util.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/util.py b/src/test/python/apache/aurora/client/commands/util.py
index fb84258..c06de50 100644
--- a/src/test/python/apache/aurora/client/commands/util.py
+++ b/src/test/python/apache/aurora/client/commands/util.py
@@ -15,7 +15,7 @@
 import unittest
 from collections import defaultdict
 
-from mock import Mock
+from mock import create_autospec
 
 from apache.aurora.client.api.sla import DomainUpTimeSlaVector, JobUpTimeDetails
 from apache.aurora.client.hooks.hooked_api import HookedAuroraClientAPI
@@ -23,16 +23,19 @@ from apache.aurora.common.aurora_job_key import AuroraJobKey
 from apache.aurora.common.cluster import Cluster
 from apache.aurora.common.clusters import Clusters
 
+from ..api.api_util import SchedulerProxyApiSpec
+
 from gen.apache.aurora.api.ttypes import Response, ResponseCode, Result
 
 
 class AuroraClientCommandTest(unittest.TestCase):
   @classmethod
   def create_blank_response(cls, code, msg):
-    response = Mock(spec=Response)
+    # TODO(wfarner): Don't use a mock here.
+    response = create_autospec(spec=Response, instance=True)
     response.responseCode = code
     response.messageDEPRECATED = msg
-    response.result = Mock(spec=Result)
+    response.result = create_autospec(spec=Result, instance=True)
     response.details = []
     return response
 
@@ -47,25 +50,24 @@ class AuroraClientCommandTest(unittest.TestCase):
   @classmethod
   def create_mock_api(cls):
     """Builds up a mock API object, with a mock SchedulerProxy"""
-    # This looks strange, but we set up the same object to use as both
-    # the SchedulerProxy and the SchedulerClient. These tests want to observe
-    # what API calls get made against the scheduler, and both of these objects
-    # delegate calls to the scheduler. It doesn't matter which one is used:
-    # what we care about is that the right API calls get made.
-    mock_scheduler_proxy = Mock()
+    """Builds up a mock API object, with a mock SchedulerProxy.
+    Returns the API and the proxy"""
+    mock_scheduler_proxy = create_autospec(
+        spec=SchedulerProxyApiSpec,
+        spec_set=False,
+        instance=True)
     mock_scheduler_proxy.url = "http://something_or_other"
     mock_scheduler_proxy.scheduler_client.return_value = mock_scheduler_proxy
-    mock_api = Mock(spec=HookedAuroraClientAPI)
+    mock_api = create_autospec(spec=HookedAuroraClientAPI)
     mock_api.scheduler_proxy = mock_scheduler_proxy
-    return (mock_api, mock_scheduler_proxy)
+    return mock_api, mock_scheduler_proxy
 
   @classmethod
   def create_mock_api_factory(cls):
     """Create a collection of mocks for a test that wants to mock out the client API
     by patching the api factory."""
     mock_api, mock_scheduler_proxy = cls.create_mock_api()
-    mock_api_factory = Mock()
-    mock_api_factory.return_value = mock_api
+    mock_api_factory = lambda x: mock_api
     return mock_api_factory, mock_scheduler_proxy
 
   FAKE_TIME = 42131
@@ -132,7 +134,7 @@ jobs = [HELLO_WORLD]
 
   @classmethod
   def create_mock_probe_hosts_vector(cls, side_effects):
-    mock_vector = Mock(spec=DomainUpTimeSlaVector)
+    mock_vector = create_autospec(spec=DomainUpTimeSlaVector, instance=True)
     mock_vector.probe_hosts.side_effect = side_effects
     return mock_vector
 
@@ -143,8 +145,9 @@ jobs = [HELLO_WORLD]
     hosts[hostname].append(JobUpTimeDetails(job, predicted, safe, safe_in))
     return [hosts]
 
+  #TODO(wfarner): Remove this, force tests to call out their flags.
   @classmethod
   def setup_mock_options(cls):
-    mock_options = Mock(spec=['verbosity'])
+    mock_options = create_autospec(spec=['verbosity'], instance=True)
     mock_options.verbosity = 'verbose'
     return mock_options

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/hooks/test_hooked_api.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/hooks/test_hooked_api.py b/src/test/python/apache/aurora/client/hooks/test_hooked_api.py
index 496bdb0..c2063f2 100644
--- a/src/test/python/apache/aurora/client/hooks/test_hooked_api.py
+++ b/src/test/python/apache/aurora/client/hooks/test_hooked_api.py
@@ -14,7 +14,7 @@
 
 from inspect import getargspec
 
-from mock import Mock
+from mock import create_autospec, Mock
 
 from apache.aurora.client.api import AuroraClientAPI
 from apache.aurora.client.hooks.hooked_api import HookedAuroraClientAPI, NonHookedAuroraClientAPI
@@ -37,7 +37,7 @@ def test_api_methods_exist(method_name):
 
 
 def test_api_methods_params(method_name):
-  cluster = Mock(spec=Cluster)
+  cluster = create_autospec(spec=Cluster, instance=True)
   api = HookedAuroraClientAPI(cluster=cluster)  # cant use mock here; need to inspect methods
 
   hooked_method = getattr(api, method_name)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/common/test_transport.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/common/test_transport.py b/src/test/python/apache/aurora/common/test_transport.py
index e0fef91..dd066bf 100644
--- a/src/test/python/apache/aurora/common/test_transport.py
+++ b/src/test/python/apache/aurora/common/test_transport.py
@@ -15,8 +15,8 @@
 import logging
 from threading import Thread
 
-import mock
 import requests
+from mock import create_autospec, Mock
 from requests import exceptions as request_exceptions
 from thrift.protocol import TJSONProtocol
 from thrift.server import THttpServer
@@ -43,8 +43,6 @@ def test_request_transport_integration():
   server_thread.start()
   _, server_port = server.httpd.socket.getsockname()
 
-  response = None
-
   try:
     transport = TRequestsTransport('http://localhost:%d' % server_port)
     protocol = TJSONProtocol.TJSONProtocol(transport)
@@ -62,9 +60,9 @@ def test_request_transport_integration():
 
 
 def test_request_transport_timeout():
-  session = mock.MagicMock(spec=requests.Session)
+  session = create_autospec(spec=requests.Session, instance=True)
   session.headers = {}
-  session.post = mock.Mock(side_effect=request_exceptions.Timeout())
+  session.post = Mock(side_effect=request_exceptions.Timeout())
   transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
   protocol = TJSONProtocol.TJSONProtocol(transport)
   client = ReadOnlyScheduler.Client(protocol)
@@ -81,9 +79,9 @@ def test_request_transport_timeout():
 
 
 def test_request_any_other_exception():
-  session = mock.MagicMock(spec=requests.Session)
+  session = create_autospec(spec=requests.Session, instance=True)
   session.headers = {}
-  session.post = mock.Mock(side_effect=request_exceptions.ConnectionError())
+  session.post = Mock(side_effect=request_exceptions.ConnectionError())
   transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
   protocol = TJSONProtocol.TJSONProtocol(transport)
   client = ReadOnlyScheduler.Client(protocol)
@@ -104,6 +102,6 @@ def test_requests_transports_lowers_logging_level():
 
   TRequestsTransport(
       'http://localhost:12345',
-      session_factory=lambda: mock.MagicMock(spec=requests.Session))
+      session_factory=lambda: create_autospec(spec=requests.Session, instance=True))
 
   assert logging.getLogger('requests').level == logging.WARNING

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/executor/common/test_announcer.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/executor/common/test_announcer.py b/src/test/python/apache/aurora/executor/common/test_announcer.py
index a4ab532..e329a90 100644
--- a/src/test/python/apache/aurora/executor/common/test_announcer.py
+++ b/src/test/python/apache/aurora/executor/common/test_announcer.py
@@ -14,10 +14,10 @@
 
 import threading
 
-import mock
 import pytest
 from kazoo.client import KazooClient
 from kazoo.exceptions import KazooException
+from mock import create_autospec, MagicMock, patch
 from twitter.common.quantity import Amount, Time
 from twitter.common.testing.clock import ThreadedClock
 from twitter.common.zookeeper.serverset import Endpoint, ServerSet
@@ -72,10 +72,10 @@ def test_announcer_under_normal_circumstances():
     joined.set()
     return 'membership foo'
 
-  mock_serverset = mock.MagicMock(spec=ServerSet)
-  mock_serverset.join = mock.MagicMock()
+  mock_serverset = create_autospec(spec=ServerSet, instance=True)
+  mock_serverset.join = MagicMock()
   mock_serverset.join.side_effect = joined_side_effect
-  mock_serverset.cancel = mock.MagicMock()
+  mock_serverset.cancel = MagicMock()
 
   endpoint = Endpoint('localhost', 12345)
   clock = ThreadedClock(31337.0)
@@ -125,10 +125,10 @@ def test_announcer_on_expiration():
     else:
       raise KazooException('Failed to reconnect')
 
-  mock_serverset = mock.MagicMock(spec=ServerSet)
-  mock_serverset.join = mock.MagicMock()
+  mock_serverset = create_autospec(spec=ServerSet, instance=True)
+  mock_serverset.join = MagicMock()
   mock_serverset.join.side_effect = joined_side_effect
-  mock_serverset.cancel = mock.MagicMock()
+  mock_serverset.cancel = MagicMock()
 
   endpoint = Endpoint('localhost', 12345)
   clock = ThreadedClock(31337.0)
@@ -160,13 +160,13 @@ def test_announcer_on_expiration():
 # TODO(wickman) https://issues.apache.org/jira/browse/AURORA-639
 @pytest.mark.skipif('True')
 def test_announcer_under_abnormal_circumstances():
-  mock_serverset = mock.MagicMock(spec=ServerSet)
-  mock_serverset.join = mock.MagicMock()
+  mock_serverset = create_autospec(spec=ServerSet, instance=True)
+  mock_serverset.join = MagicMock()
   mock_serverset.join.side_effect = [
       KazooException('Whoops the ensemble is down!'),
       'member0001',
   ]
-  mock_serverset.cancel = mock.MagicMock()
+  mock_serverset.cancel = MagicMock()
 
   endpoint = Endpoint('localhost', 12345)
   clock = ThreadedClock(31337.0)
@@ -244,15 +244,15 @@ def test_make_empty_endpoints():
   assert additional == {}
 
 
-@mock.patch('apache.aurora.executor.common.announcer.ServerSet')
-@mock.patch('apache.aurora.executor.common.announcer.KazooClient')
+@patch('apache.aurora.executor.common.announcer.ServerSet')
+@patch('apache.aurora.executor.common.announcer.KazooClient')
 def test_announcer_provider_with_timeout(mock_client_provider, mock_serverset_provider):
-  mock_client = mock.MagicMock(spec=KazooClient)
+  mock_client = create_autospec(spec=KazooClient, instance=True)
   mock_client_provider.return_value = mock_client
   client_connect_event = threading.Event()
   mock_client.start_async.return_value = client_connect_event
 
-  mock_serverset = mock.MagicMock(spec=ServerSet)
+  mock_serverset = create_autospec(spec=ServerSet, instance=True)
   mock_serverset_provider.return_value = mock_serverset
 
   dap = DefaultAnnouncerCheckerProvider('zookeeper.example.com', root='/aurora')
@@ -272,12 +272,12 @@ def test_announcer_provider_with_timeout(mock_client_provider, mock_serverset_pr
   assert checker.status is not None
 
 
-@mock.patch('apache.aurora.executor.common.announcer.ServerSet')
-@mock.patch('apache.aurora.executor.common.announcer.KazooClient')
+@patch('apache.aurora.executor.common.announcer.ServerSet')
+@patch('apache.aurora.executor.common.announcer.KazooClient')
 def test_default_announcer_provider(mock_client_provider, mock_serverset_provider):
-  mock_client = mock.MagicMock(spec=KazooClient)
+  mock_client = create_autospec(spec=KazooClient, instance=True)
   mock_client_provider.return_value = mock_client
-  mock_serverset = mock.MagicMock(spec=ServerSet)
+  mock_serverset = create_autospec(spec=ServerSet, instance=True)
   mock_serverset_provider.return_value = mock_serverset
 
   dap = DefaultAnnouncerCheckerProvider('zookeeper.example.com', root='/aurora')

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/executor/common/test_executor_timeout.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/executor/common/test_executor_timeout.py b/src/test/python/apache/aurora/executor/common/test_executor_timeout.py
index ce4cfc8..275981e 100644
--- a/src/test/python/apache/aurora/executor/common/test_executor_timeout.py
+++ b/src/test/python/apache/aurora/executor/common/test_executor_timeout.py
@@ -25,7 +25,7 @@ from apache.aurora.executor.common.executor_timeout import ExecutorTimeout
 class TestExecutorTimeout(TestCase):
   def test_run(self):
     event = Event()
-    mock_driver = mock.Mock(spec=ExecutorDriver)
+    mock_driver = mock.create_autospec(spec=ExecutorDriver, instance=True)
     event.set()
     executor_timeout = ExecutorTimeout(event, mock_driver, timeout=Amount(0, Time.SECONDS))
     executor_timeout.run()
@@ -33,7 +33,7 @@ class TestExecutorTimeout(TestCase):
 
   def test_run_timeout(self):
     event = Event()
-    mock_driver = mock.Mock(spec=ExecutorDriver)
+    mock_driver = mock.create_autospec(spec=ExecutorDriver, instance=True)
     executor_timeout = ExecutorTimeout(event, mock_driver, timeout=Amount(0, Time.SECONDS))
     executor_timeout.run()
     mock_driver.stop.assert_called_once_with()

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/executor/test_status_manager.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/executor/test_status_manager.py b/src/test/python/apache/aurora/executor/test_status_manager.py
index 8a0d48b..ce4679b 100644
--- a/src/test/python/apache/aurora/executor/test_status_manager.py
+++ b/src/test/python/apache/aurora/executor/test_status_manager.py
@@ -43,7 +43,7 @@ class TestStatusManager(TestCase):
     def callback(result):
       assert result == TaskState.Value('TASK_KILLED')
       self.callback_called = True
-    mock_time = mock.Mock(spec=time)
+    mock_time = mock.create_autospec(spec=time, instance=True)
     status_manager = StatusManager(checker, callback, mock_time)
     status_manager.run()
     assert mock_time.sleep.call_count == 2

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/thermos/core/test_helper.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/thermos/core/test_helper.py b/src/test/python/apache/thermos/core/test_helper.py
index fe368ff..35397ab 100644
--- a/src/test/python/apache/thermos/core/test_helper.py
+++ b/src/test/python/apache/thermos/core/test_helper.py
@@ -38,7 +38,7 @@ def set_side_effect(mock_obj, value):
 
 
 def mock_process(pid, username, uid=None):
-  process = mock.Mock(spec=psutil.Process, pid=pid)
+  process = mock.create_autospec(spec=psutil.Process, pid=pid, instance=True)
   set_side_effect(process.uids, uid)
   set_side_effect(process.username, username)
   process.create_time.return_value = CREATE_TIME


[2/2] git commit: Convert most uses of Mock to create_autospec, remove some uses of mocking altogether.

Posted by wf...@apache.org.
Convert most uses of Mock to create_autospec, remove some uses of mocking altogether.

Bugs closed: AURORA-889

Reviewed at https://reviews.apache.org/r/27628/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/d01f0c38
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/d01f0c38
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/d01f0c38

Branch: refs/heads/master
Commit: d01f0c382e18b065c5823e909cb07a573a6a551b
Parents: 0ad2fca
Author: Bill Farner <wf...@apache.org>
Authored: Wed Nov 5 21:06:40 2014 -0800
Committer: Bill Farner <wf...@apache.org>
Committed: Wed Nov 5 21:06:40 2014 -0800

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/update.py   |   5 +-
 .../python/apache/aurora/client/api/api_util.py | 111 ++++++++++++
 .../python/apache/aurora/client/api/test_api.py |  26 +--
 .../aurora/client/api/test_job_monitor.py       |   6 +-
 .../aurora/client/api/test_quota_check.py       |   6 +-
 .../aurora/client/api/test_scheduler_client.py  |  13 +-
 .../apache/aurora/client/api/test_task_util.py  |   8 +-
 .../aurora/client/cli/test_api_from_cli.py      |  49 ++---
 .../aurora/client/cli/test_cancel_update.py     |  29 +--
 .../aurora/client/cli/test_command_hooks.py     |  38 ++--
 .../apache/aurora/client/cli/test_create.py     |  18 +-
 .../apache/aurora/client/cli/test_cron.py       |  47 ++---
 .../apache/aurora/client/cli/test_diff.py       |  10 +-
 .../apache/aurora/client/cli/test_inspect.py    |   8 +-
 .../apache/aurora/client/cli/test_kill.py       |  23 ++-
 .../apache/aurora/client/cli/test_logging.py    |  15 +-
 .../apache/aurora/client/cli/test_plugins.py    |  15 +-
 .../apache/aurora/client/cli/test_quota.py      |  16 +-
 .../apache/aurora/client/cli/test_restart.py    |  12 +-
 .../python/apache/aurora/client/cli/test_sla.py |   7 +-
 .../apache/aurora/client/cli/test_status.py     |  23 ++-
 .../apache/aurora/client/cli/test_supdate.py    |   4 +-
 .../apache/aurora/client/cli/test_task_run.py   |  12 +-
 .../apache/aurora/client/cli/test_update.py     |  35 ++--
 .../python/apache/aurora/client/cli/util.py     |  55 +++---
 .../apache/aurora/client/commands/test_admin.py |  19 +-
 .../aurora/client/commands/test_admin_sla.py    |  34 ++--
 .../client/commands/test_cancel_update.py       |  24 +--
 .../aurora/client/commands/test_create.py       |  16 +-
 .../apache/aurora/client/commands/test_diff.py  |  24 +--
 .../apache/aurora/client/commands/test_hooks.py |  18 +-
 .../apache/aurora/client/commands/test_kill.py  |  82 ++++-----
 .../aurora/client/commands/test_listjobs.py     |   4 +-
 .../aurora/client/commands/test_restart.py      | 177 ++++++++++---------
 .../apache/aurora/client/commands/test_run.py   |  63 +++----
 .../apache/aurora/client/commands/test_ssh.py   |   8 +-
 .../aurora/client/commands/test_status.py       |  77 ++++----
 .../aurora/client/commands/test_update.py       |  58 +++---
 .../apache/aurora/client/commands/util.py       |  33 ++--
 .../aurora/client/hooks/test_hooked_api.py      |   4 +-
 .../apache/aurora/common/test_transport.py      |  14 +-
 .../aurora/executor/common/test_announcer.py    |  36 ++--
 .../executor/common/test_executor_timeout.py    |   4 +-
 .../aurora/executor/test_status_manager.py      |   2 +-
 .../python/apache/thermos/core/test_helper.py   |   2 +-
 45 files changed, 686 insertions(+), 604 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/main/python/apache/aurora/client/cli/update.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/update.py b/src/main/python/apache/aurora/client/cli/update.py
index 1d3fd66..0797e30 100644
--- a/src/main/python/apache/aurora/client/cli/update.py
+++ b/src/main/python/apache/aurora/client/cli/update.py
@@ -177,7 +177,7 @@ class ListUpdates(Verb):
     api = context.get_api(context.options.cluster)
     response = api.query_job_updates(
         role=context.options.role,
-        jobKey=context.options.jobspec,
+        job_key=context.options.jobspec,
         user=context.options.user,
         update_statuses=context.options.status)
     context.check_and_log_response(response)
@@ -221,8 +221,7 @@ class UpdateStatus(Verb):
 
   def _get_update_id(self, context, jobkey):
     api = context.get_api(context.options.jobspec.cluster)
-    response = api.query_job_updates(
-        jobKey=context.options.jobspec)
+    response = api.query_job_updates(job_key=context.options.jobspec)
     context.check_and_log_response(response, "")
     for summary in response.result.getJobUpdateSummariesResult.updateSummaries:
       if summary.jobKey == jobkey:

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/api/api_util.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/api_util.py b/src/test/python/apache/aurora/client/api/api_util.py
new file mode 100644
index 0000000..6e12154
--- /dev/null
+++ b/src/test/python/apache/aurora/client/api/api_util.py
@@ -0,0 +1,111 @@
+from apache.aurora.client.api.scheduler_client import SchedulerProxy
+
+from gen.apache.aurora.api import ReadOnlyScheduler
+
+
+class SchedulerThriftApiSpec(ReadOnlyScheduler.Iface):
+  """
+  A concrete definition of the thrift API used by the client. Intended primarily to be used as a
+  spec definition for unit testing, since the client effectively augments function signatures by
+  allowing callers to omit the session argument (in SchedulerProxy). These signatures should be
+  identical to those in AuroraAdmin.Iface, with the session removed.
+  """
+
+  def setQuota(self, ownerRole, quota):
+    pass
+
+  def forceTaskState(self, taskId, status):
+    pass
+
+  def performBackup(self):
+    pass
+
+  def listBackups(self):
+    pass
+
+  def stageRecovery(self, backupId):
+    pass
+
+  def queryRecovery(self, query):
+    pass
+
+  def deleteRecoveryTasks(self, query):
+    pass
+
+  def commitRecovery(self):
+    pass
+
+  def unloadRecovery(self):
+    pass
+
+  def startMaintenance(self, hosts):
+    pass
+
+  def drainHosts(self, hosts):
+    pass
+
+  def maintenanceStatus(self, hosts):
+    pass
+
+  def endMaintenance(self, hosts):
+    pass
+
+  def snapshot(self):
+    pass
+
+  def rewriteConfigs(self, request):
+    pass
+
+  def createJob(self, description, lock):
+    pass
+
+  def scheduleCronJob(self, description, lock):
+    pass
+
+  def descheduleCronJob(self, job, lock):
+    pass
+
+  def startCronJob(self, job):
+    pass
+
+  def restartShards(self, job, shardIds, lock):
+    pass
+
+  def killTasks(self, query, lock):
+    pass
+
+  def addInstances(self, config, lock):
+    pass
+
+  def acquireLock(self, lockKey):
+    pass
+
+  def releaseLock(self, lock, validation):
+    pass
+
+  def replaceCronTemplate(self, config, lock):
+    pass
+
+  def startJobUpdate(self, request):
+    pass
+
+  def pauseJobUpdate(self, jobKey):
+    pass
+
+  def resumeJobUpdate(self, jobKey):
+    pass
+
+  def abortJobUpdate(self, jobKey):
+    pass
+
+  def pulseJobUpdate(self, updateId):
+    pass
+
+
+class SchedulerProxyApiSpec(SchedulerThriftApiSpec, SchedulerProxy):
+  """
+  A concrete definition of the API provided by SchedulerProxy.
+  """
+
+  def url(self):
+    pass

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/api/test_api.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_api.py b/src/test/python/apache/aurora/client/api/test_api.py
index 47b5236..1f4e9fe 100644
--- a/src/test/python/apache/aurora/client/api/test_api.py
+++ b/src/test/python/apache/aurora/client/api/test_api.py
@@ -13,14 +13,18 @@
 #
 import unittest
 
-from mock import Mock
+from mock import create_autospec
 
 from apache.aurora.client.api import AuroraClientAPI
 from apache.aurora.common.aurora_job_key import AuroraJobKey
 from apache.aurora.common.cluster import Cluster
 from apache.aurora.config import AuroraConfig
+from apache.aurora.config.schema.base import UpdateConfig
+
+from .api_util import SchedulerThriftApiSpec
 
 from gen.apache.aurora.api.ttypes import (
+    JobConfiguration,
     JobUpdateQuery,
     JobUpdateRequest,
     JobUpdateSettings,
@@ -49,11 +53,11 @@ class TestJobUpdateApis(unittest.TestCase):
 
   @classmethod
   def create_blank_response(cls, code, msg):
-    response = Mock(spec=Response)
-    response.responseCode = code
-    response.messageDEPRECATED = msg
-    response.result = Mock(spec=Result)
-    return response
+    return Response(
+      responseCode=code,
+      messageDEPRECATED=msg,
+      result=create_autospec(spec=Result, spec_set=True, instance=True)
+    )
 
   @classmethod
   def create_simple_success_response(cls):
@@ -66,7 +70,7 @@ class TestJobUpdateApis(unittest.TestCase):
   @classmethod
   def mock_api(cls):
     api = AuroraClientAPI(Cluster(name="foo"))
-    mock_proxy = Mock()
+    mock_proxy = create_autospec(spec=SchedulerThriftApiSpec, spec_set=True, instance=True)
     api._scheduler_proxy = mock_proxy
     return api, mock_proxy
 
@@ -90,14 +94,14 @@ class TestJobUpdateApis(unittest.TestCase):
 
   @classmethod
   def mock_job_config(cls, error=None):
-    config = Mock(spec=AuroraConfig)
-    mock_get = Mock()
+    config = create_autospec(spec=AuroraConfig, instance=True)
+    mock_get = create_autospec(spec=UpdateConfig, instance=True)
     mock_get.get.return_value = cls.UPDATE_CONFIG
     if error:
       config.update_config.side_effect = error
     else:
       config.update_config.return_value = mock_get
-    mock_task_config = Mock()
+    mock_task_config = create_autospec(spec=JobConfiguration, instance=True)
     mock_task_config.taskConfig = TaskConfig()
     config.job.return_value = mock_task_config
     config.role.return_value = "role"
@@ -169,7 +173,7 @@ class TestJobUpdateApis(unittest.TestCase):
     job_key = AuroraJobKey("foo", "role", "env", "name")
     query = JobUpdateQuery(
         jobKey=job_key.to_thrift(),
-        updateStatuses=set([JobUpdateStatus.ROLLING_FORWARD]))
+        updateStatuses={JobUpdateStatus.ROLLING_FORWARD})
     api.query_job_updates(job_key=job_key, update_statuses=query.updateStatuses)
     mock_proxy.getJobUpdateSummaries.assert_called_once_with(query)
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/api/test_job_monitor.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_job_monitor.py b/src/test/python/apache/aurora/client/api/test_job_monitor.py
index cb2503e..27d8025 100644
--- a/src/test/python/apache/aurora/client/api/test_job_monitor.py
+++ b/src/test/python/apache/aurora/client/api/test_job_monitor.py
@@ -13,11 +13,13 @@
 #
 import unittest
 
-from mock import Mock
+from mock import create_autospec
 
 from apache.aurora.client.api.job_monitor import JobMonitor
 from apache.aurora.common.aurora_job_key import AuroraJobKey
 
+from .api_util import SchedulerThriftApiSpec
+
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
     JobKey,
@@ -49,7 +51,7 @@ class FakeEvent(object):
 class JobMonitorTest(unittest.TestCase):
 
   def setUp(self):
-    self._scheduler = Mock()
+    self._scheduler = create_autospec(spec=SchedulerThriftApiSpec, instance=True)
     self._job_key = AuroraJobKey('cl', 'johndoe', 'test', 'test_job')
     self._event = FakeEvent()
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/api/test_quota_check.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_quota_check.py b/src/test/python/apache/aurora/client/api/test_quota_check.py
index d75bd1b..cb443c2 100644
--- a/src/test/python/apache/aurora/client/api/test_quota_check.py
+++ b/src/test/python/apache/aurora/client/api/test_quota_check.py
@@ -15,10 +15,12 @@
 import unittest
 from copy import deepcopy
 
-from mock import Mock
+from mock import create_autospec
 
 from apache.aurora.client.api.quota_check import CapacityRequest, QuotaCheck
 
+from .api_util import SchedulerThriftApiSpec
+
 from gen.apache.aurora.api.ttypes import (
     GetQuotaResult,
     JobKey,
@@ -31,7 +33,7 @@ from gen.apache.aurora.api.ttypes import (
 
 class QuotaCheckTest(unittest.TestCase):
   def setUp(self):
-    self._scheduler = Mock()
+    self._scheduler = create_autospec(spec=SchedulerThriftApiSpec, instance=True)
     self._quota_checker = QuotaCheck(self._scheduler)
     self._role = 'mesos'
     self._name = 'quotajob'

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/api/test_scheduler_client.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_scheduler_client.py b/src/test/python/apache/aurora/client/api/test_scheduler_client.py
index af8353e..1f1c6e0 100644
--- a/src/test/python/apache/aurora/client/api/test_scheduler_client.py
+++ b/src/test/python/apache/aurora/client/api/test_scheduler_client.py
@@ -334,7 +334,7 @@ def test_url_when_not_connected_and_cluster_has_no_proxy_url(scheme):
   host = 'some-host.example.com'
   port = 31181
 
-  mock_zk = mock.MagicMock(spec=TwitterKazooClient)
+  mock_zk = mock.create_autospec(spec=TwitterKazooClient, instance=True)
 
   service_json = '''{
     "additionalEndpoints": {
@@ -382,7 +382,7 @@ def test_url_when_not_connected_and_cluster_has_no_proxy_url(scheme):
 @mock.patch('apache.aurora.client.api.scheduler_client.TRequestsTransport', spec=TRequestsTransport)
 def test_connect_scheduler(mock_client):
   mock_client.return_value.open.side_effect = [TTransport.TTransportException, True]
-  mock_time = mock.Mock(spec=time)
+  mock_time = mock.create_autospec(spec=time, instance=True)
   scheduler_client.SchedulerClient._connect_scheduler(
       'https://scheduler.example.com:1337',
       mock_time)
@@ -395,8 +395,11 @@ def test_connect_scheduler(mock_client):
             spec=scheduler_client.SchedulerClient)
 @mock.patch('threading._Event.wait')
 def test_transient_error(_, client):
-  mock_scheduler_client = mock.Mock(spec=scheduler_client.SchedulerClient)
-  mock_thrift_client = mock.Mock(spec=AuroraAdmin.Client)
+  mock_scheduler_client = mock.create_autospec(
+      spec=scheduler_client.SchedulerClient,
+      spec_set=False,
+      instance=True)
+  mock_thrift_client = mock.create_autospec(spec=AuroraAdmin.Client, instance=True)
   mock_thrift_client.killTasks.side_effect = [
       Response(responseCode=ResponseCode.ERROR_TRANSIENT,
                details=[ResponseDetail(message="message1"), ResponseDetail(message="message2")],
@@ -410,6 +413,6 @@ def test_transient_error(_, client):
   client.get.return_value = mock_scheduler_client
 
   proxy = TestSchedulerProxy(Cluster(name='local'))
-  proxy.killTasks(TaskQuery())
+  proxy.killTasks(TaskQuery(), None)
 
   assert mock_thrift_client.killTasks.call_count == 3

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/api/test_task_util.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_task_util.py b/src/test/python/apache/aurora/client/api/test_task_util.py
index 582c708..3e772b9 100644
--- a/src/test/python/apache/aurora/client/api/test_task_util.py
+++ b/src/test/python/apache/aurora/client/api/test_task_util.py
@@ -14,11 +14,13 @@
 
 import unittest
 
-from mock import Mock
+from mock import create_autospec
 
 from apache.aurora.client.api.scheduler_mux import SchedulerMux
 from apache.aurora.client.api.task_util import StatusMuxHelper
 
+from ..api.api_util import SchedulerThriftApiSpec
+
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
     Response,
@@ -49,13 +51,13 @@ class TaskUtilTest(unittest.TestCase):
 
   @classmethod
   def mock_mux(cls, tasks):
-    mux = Mock(spec=SchedulerMux)
+    mux = create_autospec(spec=SchedulerMux, instance=True)
     mux.enqueue_and_wait.return_value = tasks
     return mux
 
   @classmethod
   def mock_scheduler(cls, response_code=None):
-    scheduler = Mock()
+    scheduler = create_autospec(spec=SchedulerThriftApiSpec, instance=True)
     response_code = ResponseCode.OK if response_code is None else response_code
     resp = Response(responseCode=response_code, messageDEPRECATED='test')
     resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=cls.create_tasks()))

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_api_from_cli.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_api_from_cli.py b/src/test/python/apache/aurora/client/cli/test_api_from_cli.py
index 3e7006e..b855c3c 100644
--- a/src/test/python/apache/aurora/client/cli/test_api_from_cli.py
+++ b/src/test/python/apache/aurora/client/cli/test_api_from_cli.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 
 from apache.aurora.client.api.scheduler_client import SchedulerClient
 from apache.aurora.client.cli import EXIT_UNKNOWN_ERROR
@@ -24,10 +24,7 @@ from .util import AuroraClientCommandTest
 
 from gen.apache.aurora.api import AuroraAdmin
 from gen.apache.aurora.api.ttypes import (
-    GetJobsResult,
-    JobConfiguration,
     JobKey,
-    Response,
     ResponseCode,
     Result,
     ScheduleStatusResult,
@@ -48,36 +45,18 @@ class TestApiFromCLI(AuroraClientCommandTest):
     return result
 
   @classmethod
-  def create_getjobs_response(cls):
-    result = Mock(spec=Response)
-    result.responseCode = ResponseCode.OK
-    result.result = Mock(spec=Result)
-    result.result.getJobsResult = Mock(spec=GetJobsResult)
-    mock_job_one = Mock(spec=JobConfiguration)
-    mock_job_one.key = Mock(spec=JobKey)
-    mock_job_one.key.role = 'RoleA'
-    mock_job_one.key.environment = 'test'
-    mock_job_one.key.name = 'hithere'
-    mock_job_two = Mock(spec=JobConfiguration)
-    mock_job_two.key = Mock(spec=JobKey)
-    mock_job_two.key.role = 'bozo'
-    mock_job_two.key.environment = 'test'
-    mock_job_two.key.name = 'hello'
-    result.result.getJobsResult.configs = [mock_job_one, mock_job_two]
-    return result
-
-  @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    resp.result.scheduleStatusResult.tasks = set(cls.create_scheduled_tasks())
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(tasks=set(cls.create_scheduled_tasks())))
     return resp
 
   @classmethod
   def create_status_response_null_metadata(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    resp.result.scheduleStatusResult.tasks = set(cls.create_mock_scheduled_task_no_metadata())
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(
+            tasks=set(cls.create_mock_scheduled_task_no_metadata())))
     return resp
 
   @classmethod
@@ -87,20 +66,22 @@ class TestApiFromCLI(AuroraClientCommandTest):
   def test_successful_status_deep(self):
     """Test the status command more deeply: in a request with a fully specified
     job, it should end up doing a query using getTasksWithoutConfigs."""
-    _, mock_scheduler_proxy = self.create_mock_api()
-    mock_scheduler_proxy.query.return_value = self.create_status_response()
+    mock_scheduler_client = create_autospec(spec=SchedulerClient, instance=True)
+    mock_thrift_client = create_autospec(spec=AuroraAdmin.Client, instance=True)
+    mock_scheduler_client.get_thrift_client.return_value = mock_thrift_client
+    mock_thrift_client.getTasksWithoutConfigs.return_value = self.create_status_response()
     with contextlib.nested(
-        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.api.scheduler_client.SchedulerClient.get',
+            return_value=mock_scheduler_client),
         patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)):
       cmd = AuroraCommandLine()
       cmd.execute(['job', 'status', 'west/bozo/test/hello'])
-      mock_scheduler_proxy.getTasksWithoutConfigs.assert_called_with(
+      mock_thrift_client.getTasksWithoutConfigs.assert_called_with(
           TaskQuery(jobKeys=[JobKey(role='bozo', environment='test', name='hello')]))
 
   def test_status_api_failure(self):
-    # TODO(wfarner): Consider spec_set instead of spec.
-    mock_scheduler_client = Mock(spec=SchedulerClient)
-    mock_thrift_client = Mock(spec=AuroraAdmin.Client)
+    mock_scheduler_client = create_autospec(spec=SchedulerClient, instance=True)
+    mock_thrift_client = create_autospec(spec=AuroraAdmin.Client, instance=True)
     mock_scheduler_client.get_thrift_client.return_value = mock_thrift_client
 
     mock_thrift_client.getTasksWithoutConfigs.side_effect = IOError("Uh-Oh")

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_cancel_update.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_cancel_update.py b/src/test/python/apache/aurora/client/cli/test_cancel_update.py
index fb5a527..b0eef0e 100644
--- a/src/test/python/apache/aurora/client/cli/test_cancel_update.py
+++ b/src/test/python/apache/aurora/client/cli/test_cancel_update.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.cli.client import AuroraCommandLine
@@ -22,40 +22,17 @@ from apache.aurora.common.aurora_job_key import AuroraJobKey
 
 from .util import AuroraClientCommandTest, FakeAuroraCommandContext
 
-from gen.apache.aurora.api.ttypes import JobKey, ScheduleStatus, ScheduleStatusResult, TaskQuery
+from gen.apache.aurora.api.ttypes import JobKey, TaskQuery
 
 
 class TestClientCancelUpdateCommand(AuroraClientCommandTest):
 
   @classmethod
-  def setup_mock_api_factory(cls):
-    mock_api_factory, mock_api = cls.create_mock_api_factory()
-    mock_api_factory.return_value.cancel_update.return_value = cls.get_cancel_update_response()
-    return mock_api_factory
-
-  @classmethod
-  def create_mock_status_query_result(cls, scheduleStatus):
-    mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    if scheduleStatus == ScheduleStatus.INIT:
-      # status query result for before job is launched.
-      mock_query_result.result.scheduleStatusResult.tasks = []
-    else:
-      mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
-      mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
-      mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]
-    return mock_query_result
-
-  @classmethod
-  def get_cancel_update_response(cls):
-    return cls.create_simple_success_response()
-
-  @classmethod
   def assert_cancel_update_called(cls, mock_api):
     # Running cancel update should result in calling the API cancel_update
     # method once, with an AuroraJobKey parameter.
     assert mock_api.cancel_update.call_count == 1
-    assert mock_api.cancel_update.called_with(
+    mock_api.cancel_update.assert_called_with(
         AuroraJobKey(cls.TEST_CLUSTER, cls.TEST_ROLE, cls.TEST_ENV, cls.TEST_JOB),
         config=None)
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_command_hooks.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_command_hooks.py b/src/test/python/apache/aurora/client/cli/test_command_hooks.py
index eb4d413..d3b3b9d 100644
--- a/src/test/python/apache/aurora/client/cli/test_command_hooks.py
+++ b/src/test/python/apache/aurora/client/cli/test_command_hooks.py
@@ -14,7 +14,8 @@
 
 import contextlib
 
-from mock import Mock, patch
+import requests
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.cli import EXIT_PERMISSION_VIOLATION
@@ -27,6 +28,7 @@ from .util import AuroraClientCommandTest, FakeAuroraCommandContext
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
     JobKey,
+    Result,
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
@@ -99,27 +101,25 @@ class TestClientCreateCommand(AuroraClientCommandTest):
 
   @classmethod
   def create_mock_task(cls, task_id, instance_id, initial_time, status):
-    mock_task = Mock(spec=ScheduledTask)
-    mock_task.assignedTask = Mock(spec=AssignedTask)
-    mock_task.assignedTask.taskId = task_id
-    mock_task.assignedTask.instanceId = instance_id
-    mock_task.status = status
-    mock_task_event = Mock(spec=TaskEvent)
-    mock_task_event.timestamp = initial_time
-    mock_task.taskEvents = [mock_task_event]
-    return mock_task
+    return ScheduledTask(
+        status=status,
+        assignedTask=AssignedTask(
+          taskId=task_id,
+          instanceId=instance_id),
+        taskEvents=[TaskEvent(timestamp=initial_time)]
+    )
 
   @classmethod
   def create_mock_status_query_result(cls, scheduleStatus):
     mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
     if scheduleStatus == ScheduleStatus.INIT:
       # status query result for before job is launched.
-      mock_query_result.result.scheduleStatusResult.tasks = []
+      tasks = []
     else:
       mock_task_one = cls.create_mock_task("hello", 0, 1000, scheduleStatus)
       mock_task_two = cls.create_mock_task("hello", 1, 1004, scheduleStatus)
-      mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]
+      tasks = [mock_task_one, mock_task_two]
+    mock_query_result.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
     return mock_query_result
 
   @classmethod
@@ -158,11 +158,11 @@ class TestClientCreateCommand(AuroraClientCommandTest):
     with patch("apache.aurora.client.cli.jobs.Job.create_context", return_value=mock_context):
       mock_query = self.create_mock_query()
       mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.INIT))
+          self.create_mock_status_query_result(ScheduleStatus.INIT))
       mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
+          self.create_mock_status_query_result(ScheduleStatus.RUNNING))
       mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
+          self.create_mock_status_query_result(ScheduleStatus.RUNNING))
       mock_context.get_api("west").check_status.side_effect = (
         lambda x: self.create_mock_status_query_result(ScheduleStatus.RUNNING))
       api = mock_context.get_api("west")
@@ -253,7 +253,7 @@ class TestClientCreateCommand(AuroraClientCommandTest):
     """Load up a set of skips, specified in JSON, and then check a bunch of different
     cases to see that the skip rules work correctly.
     """
-    mock_response = Mock()
+    mock_response = create_autospec(spec=requests.Response, instance=True)
     mock_context = FakeAuroraCommandContext()
     with patch("requests.get", return_value=mock_response):
       mock_response.json.return_value = {
@@ -300,7 +300,7 @@ class TestClientCreateCommand(AuroraClientCommandTest):
     GlobalCommandHookRegistry.register_command_hook(command_hook)
     command_hook_two = SecondHookForTesting(False)
     GlobalCommandHookRegistry.register_command_hook(command_hook_two)
-    mock_response = Mock()
+    mock_response = create_autospec(spec=requests.Response, instance=True)
     mock_context = FakeAuroraCommandContext()
 
     with contextlib.nested(
@@ -350,7 +350,7 @@ class TestClientCreateCommand(AuroraClientCommandTest):
     GlobalCommandHookRegistry.register_command_hook(command_hook)
     command_hook_two = SecondHookForTesting(False)
     GlobalCommandHookRegistry.register_command_hook(command_hook_two)
-    mock_response = Mock()
+    mock_response = create_autospec(spec=requests.Response, instance=True)
     mock_context = FakeAuroraCommandContext()
 
     with contextlib.nested(

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_create.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_create.py b/src/test/python/apache/aurora/client/cli/test_create.py
index 6013fa1..1dec54c 100644
--- a/src/test/python/apache/aurora/client/cli/test_create.py
+++ b/src/test/python/apache/aurora/client/cli/test_create.py
@@ -16,7 +16,7 @@ import contextlib
 import os
 import shutil
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.cli import (
@@ -34,6 +34,7 @@ from .util import AuroraClientCommandTest, FakeAuroraCommandContext
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
     JobKey,
+    Result,
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
@@ -50,12 +51,12 @@ class TestClientCreateCommand(AuroraClientCommandTest):
 
   @classmethod
   def create_mock_task(cls, task_id, instance_id, initial_time, status):
-    mock_task = Mock(spec=ScheduledTask)
-    mock_task.assignedTask = Mock(spec=AssignedTask)
+    mock_task = create_autospec(spec=ScheduledTask, instance=True)
+    mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
     mock_task.assignedTask.taskId = task_id
     mock_task.assignedTask.instanceId = instance_id
     mock_task.status = status
-    mock_task_event = Mock(spec=TaskEvent)
+    mock_task_event = create_autospec(spec=TaskEvent, instance=True)
     mock_task_event.timestamp = initial_time
     mock_task.taskEvents = [mock_task_event]
     return mock_task
@@ -63,10 +64,10 @@ class TestClientCreateCommand(AuroraClientCommandTest):
   @classmethod
   def create_mock_status_query_result(cls, scheduleStatus):
     mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
-    mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
-    mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]
+    mock_query_result.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=[
+        cls.create_mock_task('hello', 0, 1000, scheduleStatus),
+        cls.create_mock_task('hello', 1, 1004, scheduleStatus)
+    ]))
     return mock_query_result
 
   @classmethod
@@ -249,7 +250,6 @@ class TestClientCreateCommand(AuroraClientCommandTest):
       # Check that create_job was not called.
       api = mock_context.get_api('west')
       assert api.create_job.call_count == 0
-      assert api.scheduler_proxy.test_simple_successful_create_job.call_count == 0
 
   def test_interrupt(self):
     mock_context = FakeAuroraCommandContext()

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_cron.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_cron.py b/src/test/python/apache/aurora/client/cli/test_cron.py
index b84bbfc..029a0c5 100644
--- a/src/test/python/apache/aurora/client/cli/test_cron.py
+++ b/src/test/python/apache/aurora/client/cli/test_cron.py
@@ -16,16 +16,17 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.cli import EXIT_API_ERROR, EXIT_INVALID_CONFIGURATION, EXIT_OK
 from apache.aurora.client.cli.client import AuroraCommandLine
 from apache.aurora.config import AuroraConfig
 
+from ..api.api_util import SchedulerProxyApiSpec
 from .util import AuroraClientCommandTest, FakeAuroraCommandContext
 
-from gen.apache.aurora.api.ttypes import JobKey
+from gen.apache.aurora.api.ttypes import GetJobsResult, JobConfiguration, JobKey, Result
 
 
 class TestCronNoun(AuroraClientCommandTest):
@@ -126,19 +127,16 @@ class TestCronNoun(AuroraClientCommandTest):
   @classmethod
   def _create_getjobs_response(cls):
     response = cls.create_simple_success_response()
-    response.result = Mock()
-    response.result.getJobsResult = Mock()
-    mockjob = Mock()
-    mockjob.cronSchedule = "* * * * *"
-    mockjob.key = Mock()
-    mockjob.key.environment = "test"
-    mockjob.key.name = "hello"
-    mockjob.key.role = "bozo"
-    response.result.getJobsResult.configs = [mockjob]
+    response.result = Result(getJobsResult=GetJobsResult(configs=[
+        JobConfiguration(
+            cronSchedule='* * * * *',
+            key=JobKey(role='bozo', environment='test', name='hello'))
+    ]))
     return response
 
   def test_cron_status(self):
-    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+    (_, mock_scheduler_proxy) = self.create_mock_api()
+    mock_scheduler_proxy = create_autospec(spec=SchedulerProxyApiSpec)
     with contextlib.nested(
         patch('time.sleep'),
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
@@ -154,7 +152,7 @@ class TestCronNoun(AuroraClientCommandTest):
       mock_print.assert_called_with("west/bozo/test/hello\t * * * * *")
 
   def test_cron_status_multiple_jobs(self):
-    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+    _, mock_scheduler_proxy = self.create_mock_api()
     with contextlib.nested(
         patch('time.sleep'),
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
@@ -162,21 +160,14 @@ class TestCronNoun(AuroraClientCommandTest):
         patch('apache.aurora.client.cli.context.AuroraCommandContext.print_out')) as (
             _, _, _, mock_print):
       response = self.create_simple_success_response()
-      response.result = Mock()
-      response.result.getJobsResult = Mock()
-      mockjob1 = Mock()
-      mockjob1.cronSchedule = "* * * * *"
-      mockjob1.key = Mock()
-      mockjob1.key.environment = "test"
-      mockjob1.key.name = "hello2"
-      mockjob1.key.role = "bozo"
-      mockjob2 = Mock()
-      mockjob2.cronSchedule = "* * * * *"
-      mockjob2.key = Mock()
-      mockjob2.key.environment = "test"
-      mockjob2.key.name = "hello"
-      mockjob2.key.role = "bozo"
-      response.result.getJobsResult.configs = [mockjob1, mockjob2]
+      response.result = Result(getJobsResult=GetJobsResult(configs=[
+          JobConfiguration(
+              key=JobKey(role='bozo', environment='test', name='hello'),
+              cronSchedule='* * * * *'),
+          JobConfiguration(
+              key=JobKey(role='bozo', environment='test', name='hello2'),
+              cronSchedule='* * * * *')
+      ]))
       mock_scheduler_proxy.getJobs.return_value = response
 
       cmd = AuroraCommandLine()

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_diff.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_diff.py b/src/test/python/apache/aurora/client/cli/test_diff.py
index f7c07f2..95c7c92 100644
--- a/src/test/python/apache/aurora/client/cli/test_diff.py
+++ b/src/test/python/apache/aurora/client/cli/test_diff.py
@@ -29,6 +29,7 @@ from gen.apache.aurora.api.ttypes import (
     JobKey,
     PopulateJobResult,
     ResponseCode,
+    Result,
     ScheduleStatusResult,
     TaskQuery
 )
@@ -50,8 +51,8 @@ class TestDiffCommand(AuroraClientCommandTest):
   @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    resp.result.scheduleStatusResult.tasks = set(cls.create_scheduled_tasks())
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(tasks=set(cls.create_scheduled_tasks())))
     return resp
 
   @classmethod
@@ -61,10 +62,11 @@ class TestDiffCommand(AuroraClientCommandTest):
   @classmethod
   def setup_populate_job_config(cls, api):
     populate = cls.create_simple_success_response()
-    populate.result.populateJobResult = Mock(spec=PopulateJobResult)
     api.populateJobConfig.return_value = populate
     tasks = set(task.assignedTask.task for task in cls.create_scheduled_tasks())
-    populate.result.populateJobResult.populatedDEPRECATED = tasks
+    populate.result = Result(populateJobResult=PopulateJobResult(
+        populatedDEPRECATED=tasks
+    ))
     return populate
 
   def test_successful_diff(self):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_inspect.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_inspect.py b/src/test/python/apache/aurora/client/cli/test_inspect.py
index b5b949b..1c07d91 100644
--- a/src/test/python/apache/aurora/client/cli/test_inspect.py
+++ b/src/test/python/apache/aurora/client/cli/test_inspect.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, Mock, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.cli.client import AuroraCommandLine
@@ -27,9 +27,9 @@ from gen.apache.aurora.api.ttypes import CronCollisionPolicy
 
 class TestInspectCommand(AuroraClientCommandTest):
   def get_mock_config(self):
-    config = Mock(spec=AuroraConfig)
-    # TODO(mchucarroll): figure out how to spec this. The raw_config is a Pystachio spec,
-    # and that seems to blow up mock.
+    config = create_autospec(spec=AuroraConfig, instance=True)
+    # TODO(wfarner): figure out how to spec this. The raw_config is a Pystachio spec, and that seems
+    # to blow up mock.
     raw_config = Mock()
     config.raw.return_value = raw_config
     raw_config.contact.return_value = "bozo@the.clown"

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_kill.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_kill.py b/src/test/python/apache/aurora/client/cli/test_kill.py
index 6f5b1bb..78f5f04 100644
--- a/src/test/python/apache/aurora/client/cli/test_kill.py
+++ b/src/test/python/apache/aurora/client/cli/test_kill.py
@@ -15,7 +15,7 @@
 import contextlib
 import unittest
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.cli import EXIT_TIMEOUT
@@ -23,9 +23,16 @@ from apache.aurora.client.cli.client import AuroraCommandLine
 from apache.aurora.client.cli.options import parse_instances
 from apache.aurora.common.aurora_job_key import AuroraJobKey
 
+from ..api.api_util import SchedulerThriftApiSpec
 from .util import AuroraClientCommandTest, FakeAuroraCommandContext
 
-from gen.apache.aurora.api.ttypes import JobKey, ScheduleStatus, ScheduleStatusResult, TaskQuery
+from gen.apache.aurora.api.ttypes import (
+    JobKey,
+    Result,
+    ScheduleStatus,
+    ScheduleStatusResult,
+    TaskQuery
+)
 
 
 class TestInstancesParser(unittest.TestCase):
@@ -65,7 +72,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
   def test_killall_job(self):
     """Test kill client-side API logic."""
     mock_context = FakeAuroraCommandContext()
-    mock_scheduler_proxy = Mock()
+    mock_scheduler_proxy = create_autospec(spec=SchedulerThriftApiSpec, instance=True)
     with contextlib.nested(
         patch('threading._Event.wait'),
         patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context),
@@ -92,7 +99,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
   def test_killall_job_wait_until_timeout(self):
     """Test kill client-side API logic."""
     mock_context = FakeAuroraCommandContext()
-    mock_scheduler_proxy = Mock()
+    mock_scheduler_proxy = create_autospec(spec=SchedulerThriftApiSpec, instance=True)
     with contextlib.nested(
         patch('threading._Event.wait'),
         patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context),
@@ -121,7 +128,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
   def test_killall_job_something_else(self):
     """Test kill client-side API logic."""
     mock_context = FakeAuroraCommandContext()
-    mock_scheduler_proxy = Mock()
+    mock_scheduler_proxy = create_autospec(spec=SchedulerThriftApiSpec, instance=True)
     with contextlib.nested(
         patch('threading._Event.wait'),
         patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context),
@@ -303,9 +310,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
       api = mock_context.get_api('west')
       # set up an empty instance list in the getTasksWithoutConfigs response
       status_response = self.create_simple_success_response()
-      schedule_status = Mock(spec=ScheduleStatusResult)
-      status_response.result.scheduleStatusResult = schedule_status
-      schedule_status.tasks = []
+      status_response.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=[[]]))
       mock_context.add_expected_status_query_result(status_response)
       api.kill_job.return_value = self.get_kill_job_response()
       with temporary_file() as fp:
@@ -340,7 +345,7 @@ class TestClientKillCommand(AuroraClientCommandTest):
   def test_killall_job_output(self):
     """Test kill output."""
     mock_context = FakeAuroraCommandContext()
-    mock_scheduler_proxy = Mock()
+    mock_scheduler_proxy = create_autospec(spec=SchedulerThriftApiSpec, instance=True)
     with contextlib.nested(
         patch('threading._Event.wait'),
         patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context),

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_logging.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_logging.py b/src/test/python/apache/aurora/client/cli/test_logging.py
index 10fa015..401d091 100644
--- a/src/test/python/apache/aurora/client/cli/test_logging.py
+++ b/src/test/python/apache/aurora/client/cli/test_logging.py
@@ -15,7 +15,7 @@
 import logging
 from logging import Handler
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.cli.client import AuroraCommandLine
@@ -25,6 +25,7 @@ from .util import AuroraClientCommandTest, FakeAuroraCommandContext
 
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
+    Result,
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
@@ -45,12 +46,12 @@ class TestLogging(AuroraClientCommandTest):
 
   @classmethod
   def create_mock_task(cls, task_id, instance_id, initial_time, status):
-    mock_task = Mock(spec=ScheduledTask)
-    mock_task.assignedTask = Mock(spec=AssignedTask)
+    mock_task = create_autospec(spec=ScheduledTask, instance=True)
+    mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
     mock_task.assignedTask.taskId = task_id
     mock_task.assignedTask.instanceId = instance_id
     mock_task.status = status
-    mock_task_event = Mock(spec=TaskEvent)
+    mock_task_event = create_autospec(spec=TaskEvent, instance=True)
     mock_task_event.timestamp = initial_time
     mock_task.taskEvents = [mock_task_event]
     return mock_task
@@ -58,14 +59,14 @@ class TestLogging(AuroraClientCommandTest):
   @classmethod
   def create_mock_status_query_result(cls, scheduleStatus):
     mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
     if scheduleStatus == ScheduleStatus.INIT:
       # status query result for before job is launched.
-      mock_query_result.result.scheduleStatusResult.tasks = []
+      tasks = []
     else:
       mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
       mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
-      mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]
+      tasks = [mock_task_one, mock_task_two]
+    mock_query_result.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
     return mock_query_result
 
   @classmethod

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_plugins.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_plugins.py b/src/test/python/apache/aurora/client/cli/test_plugins.py
index 0b29346..43765f2 100644
--- a/src/test/python/apache/aurora/client/cli/test_plugins.py
+++ b/src/test/python/apache/aurora/client/cli/test_plugins.py
@@ -14,7 +14,7 @@
 
 import logging
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.cli import ConfigurationPlugin, EXIT_OK
@@ -27,6 +27,7 @@ from .util import AuroraClientCommandTest, FakeAuroraCommandContext
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
     JobKey,
+    Result,
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
@@ -67,12 +68,12 @@ class TestPlugins(AuroraClientCommandTest):
 
   @classmethod
   def create_mock_task(cls, task_id, instance_id, initial_time, status):
-    mock_task = Mock(spec=ScheduledTask)
-    mock_task.assignedTask = Mock(spec=AssignedTask)
+    mock_task = create_autospec(spec=ScheduledTask, instance=True)
+    mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
     mock_task.assignedTask.taskId = task_id
     mock_task.assignedTask.instanceId = instance_id
     mock_task.status = status
-    mock_task_event = Mock(spec=TaskEvent)
+    mock_task_event = create_autospec(spec=TaskEvent, instance=True)
     mock_task_event.timestamp = initial_time
     mock_task.taskEvents = [mock_task_event]
     return mock_task
@@ -80,14 +81,14 @@ class TestPlugins(AuroraClientCommandTest):
   @classmethod
   def create_mock_status_query_result(cls, scheduleStatus):
     mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
     if scheduleStatus == ScheduleStatus.INIT:
       # status query result for before job is launched.
-      mock_query_result.result.scheduleStatusResult.tasks = []
+      tasks = []
     else:
       mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
       mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
-      mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]
+      tasks = [mock_task_one, mock_task_two]
+    mock_query_result.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
     return mock_query_result
 
   @classmethod

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_quota.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_quota.py b/src/test/python/apache/aurora/client/cli/test_quota.py
index 6e38227..202cc45 100644
--- a/src/test/python/apache/aurora/client/cli/test_quota.py
+++ b/src/test/python/apache/aurora/client/cli/test_quota.py
@@ -21,7 +21,7 @@ from apache.aurora.client.cli.client import AuroraCommandLine
 
 from .util import AuroraClientCommandTest, FakeAuroraCommandContext
 
-from gen.apache.aurora.api.ttypes import GetQuotaResult, ResourceAggregate
+from gen.apache.aurora.api.ttypes import GetQuotaResult, ResourceAggregate, Result
 
 
 class TestGetQuotaCommand(AuroraClientCommandTest):
@@ -29,22 +29,22 @@ class TestGetQuotaCommand(AuroraClientCommandTest):
   def setup_mock_quota_call_no_consumption(cls, mock_context):
     api = mock_context.get_api('west')
     response = cls.create_simple_success_response()
-    response.result.getQuotaResult = GetQuotaResult(
-      quota=ResourceAggregate(numCpus=5, ramMb=20480, diskMb=40960),
-      prodConsumption=None,
-      nonProdConsumption=None
-    )
+    response.result = Result(getQuotaResult=GetQuotaResult(
+        quota=ResourceAggregate(numCpus=5, ramMb=20480, diskMb=40960),
+        prodConsumption=None,
+        nonProdConsumption=None
+    ))
     api.get_quota.return_value = response
 
   @classmethod
   def setup_mock_quota_call_with_consumption(cls, mock_context):
     api = mock_context.get_api('west')
     response = cls.create_simple_success_response()
-    response.result.getQuotaResult = GetQuotaResult(
+    response.result = Result(getQuotaResult=GetQuotaResult(
       quota=ResourceAggregate(numCpus=5, ramMb=20480, diskMb=40960),
       prodConsumption=ResourceAggregate(numCpus=1, ramMb=1024, diskMb=2048),
       nonProdConsumption=ResourceAggregate(numCpus=1, ramMb=1024, diskMb=2048),
-    )
+    ))
     api.get_quota.return_value = response
 
   def test_get_quota_no_consumption(self):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_restart.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_restart.py b/src/test/python/apache/aurora/client/cli/test_restart.py
index ff70264..a8180a3 100644
--- a/src/test/python/apache/aurora/client/cli/test_restart.py
+++ b/src/test/python/apache/aurora/client/cli/test_restart.py
@@ -14,7 +14,7 @@
 import contextlib
 import functools
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.api.health_check import Retriable, StatusHealthCheck
@@ -23,7 +23,7 @@ from apache.aurora.client.cli.client import AuroraCommandLine
 
 from .util import AuroraClientCommandTest, IOMock
 
-from gen.apache.aurora.api.ttypes import JobKey, PopulateJobResult, TaskConfig
+from gen.apache.aurora.api.ttypes import JobKey, PopulateJobResult, Result, TaskConfig
 
 
 class TestRestartCommand(AuroraClientCommandTest):
@@ -39,15 +39,15 @@ class TestRestartCommand(AuroraClientCommandTest):
   @classmethod
   def setup_populate_job_config(cls, api):
     populate = cls.create_simple_success_response()
-    populate.result.populateJobResult = Mock(spec=PopulateJobResult)
+    populate.result = Result(populateJobResult=PopulateJobResult(
+        populatedDEPRECATED={TaskConfig()}
+    ))
     api.populateJobConfig.return_value = populate
-    configs = [Mock(spec=TaskConfig) for i in range(20)]
-    populate.result.populateJobResult.populatedDEPRECATED = set(configs)
     return populate
 
   @classmethod
   def setup_health_checks(cls, mock_api):
-    mock_health_check = Mock(spec=StatusHealthCheck)
+    mock_health_check = create_autospec(spec=StatusHealthCheck, instance=True)
     mock_health_check.health.return_value = Retriable.alive()
     return mock_health_check
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_sla.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_sla.py b/src/test/python/apache/aurora/client/cli/test_sla.py
index a7bfd35..3d6d99c 100644
--- a/src/test/python/apache/aurora/client/cli/test_sla.py
+++ b/src/test/python/apache/aurora/client/cli/test_sla.py
@@ -14,8 +14,9 @@
 
 import contextlib
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 
+from apache.aurora.client.api.sla import JobUpTimeSlaVector
 from apache.aurora.client.cli.client import AuroraCommandLine
 
 from .util import AuroraClientCommandTest, FakeAuroraCommandContext
@@ -25,7 +26,7 @@ class TestGetTaskUpCountCommand(AuroraClientCommandTest):
   @classmethod
   def setup_mock_sla_uptime_vector(cls, mock_context, upcount):
     api = mock_context.get_api('west')
-    response = Mock()
+    response = create_autospec(spec=JobUpTimeSlaVector, instance=True)
     response.get_task_up_count.return_value = upcount
     api.sla_get_job_uptime_vector.return_value = response
 
@@ -62,7 +63,7 @@ class TestGetJobUptimeCommand(AuroraClientCommandTest):
   @classmethod
   def setup_mock_sla_uptime_vector(cls, mock_context, uptime):
     api = mock_context.get_api('west')
-    response = Mock()
+    response = create_autospec(spec=JobUpTimeSlaVector, instance=True)
     response.get_job_uptime.return_value = uptime
     api.sla_get_job_uptime_vector.return_value = response
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_status.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_status.py b/src/test/python/apache/aurora/client/cli/test_status.py
index 6b2f18b..e531fa0 100644
--- a/src/test/python/apache/aurora/client/cli/test_status.py
+++ b/src/test/python/apache/aurora/client/cli/test_status.py
@@ -107,15 +107,16 @@ class TestJobStatus(AuroraClientCommandTest):
   @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = ScheduleStatusResult(
-      tasks=set(cls.create_scheduled_tasks()))
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(tasks=set(cls.create_scheduled_tasks())))
     return resp
 
   @classmethod
   def create_status_null_metadata(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = ScheduleStatusResult(
-      tasks=set(cls.create_mock_scheduled_task_no_metadata()))
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(
+            tasks=set(cls.create_mock_scheduled_task_no_metadata())))
     return resp
 
   @classmethod
@@ -127,7 +128,7 @@ class TestJobStatus(AuroraClientCommandTest):
   @classmethod
   def create_empty_status(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = ScheduleStatusResult(tasks=None)
+    resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=None))
     return resp
 
   def get_task_status_json(cls):
@@ -172,14 +173,14 @@ class TestJobStatus(AuroraClientCommandTest):
       create_scheduled_task(0, 123456),
       create_scheduled_task(1, 234567)
     ]
-    resp.result.scheduleStatusResult = scheduleStatus
+    resp.result = Result(scheduleStatusResult=scheduleStatus)
     return resp
 
   @classmethod
   def create_status_with_metadata(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = ScheduleStatusResult(
-      tasks=set(cls.create_mock_scheduled_task_with_metadata()))
+    resp.result = Result(scheduleStatusResult=ScheduleStatusResult(
+        tasks=set(cls.create_mock_scheduled_task_with_metadata())))
     return resp
 
   @classmethod
@@ -189,7 +190,7 @@ class TestJobStatus(AuroraClientCommandTest):
   @classmethod
   def create_nojobs_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = ScheduleStatusResult(tasks=set())
+    resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=set()))
     return resp
 
   def test_successful_status_shallow(self):
@@ -219,8 +220,7 @@ class TestJobStatus(AuroraClientCommandTest):
   def test_successful_status_deep(self):
     """Test the status command more deeply: in a request with a fully specified
     job, it should end up doing a query using getTasksWithoutConfigs."""
-    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
-    mock_scheduler_proxy.query.return_value = self.create_status_response()
+    _, mock_scheduler_proxy = self.create_mock_api()
     mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_status_null_metadata()
     with contextlib.nested(
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
@@ -350,7 +350,6 @@ class TestJobStatus(AuroraClientCommandTest):
 
   def test_successful_status_deep_null_metadata(self):
     (mock_api, mock_scheduler_proxy) = self.create_mock_api()
-    mock_scheduler_proxy.query.return_value = self.create_status_null_metadata()
     mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_status_null_metadata()
     with contextlib.nested(
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_supdate.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_supdate.py b/src/test/python/apache/aurora/client/cli/test_supdate.py
index bf979e2..8943f8c 100644
--- a/src/test/python/apache/aurora/client/cli/test_supdate.py
+++ b/src/test/python/apache/aurora/client/cli/test_supdate.py
@@ -338,7 +338,7 @@ class TestUpdateCommand(AuroraClientCommandTest):
           "  Instance 2 at YYYY-MM-DD HH:MM:SS: INSTANCE_UPDATING",
           "  Instance 1 at YYYY-MM-DD HH:MM:SS: INSTANCE_UPDATED",
           "  Instance 2 at YYYY-MM-DD HH:MM:SS: INSTANCE_UPDATED"]
-      mock_context.get_api("west").query_job_updates.assert_called_with(jobKey=AuroraJobKey(
+      mock_context.get_api("west").query_job_updates.assert_called_with(job_key=AuroraJobKey(
           'west', 'mcc', 'test', 'hello'))
 
   def test_update_status_json(self):
@@ -353,7 +353,7 @@ class TestUpdateCommand(AuroraClientCommandTest):
       cmd = AuroraCommandLine()
       result = cmd.execute(["beta-update", "status", "--write-json", "west/mcc/test/hello"])
       assert result == EXIT_OK
-      mock_context.get_api("west").query_job_updates.assert_called_with(jobKey=AuroraJobKey(
+      mock_context.get_api("west").query_job_updates.assert_called_with(job_key=AuroraJobKey(
           'west', 'mcc', 'test', 'hello'))
       mock_context.get_api("west").get_job_update_details.assert_called_with('hello')
       assert mock_context.get_out_str() == textwrap.dedent("""\

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_task_run.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_task_run.py b/src/test/python/apache/aurora/client/cli/test_task_run.py
index 8458606..8544617 100644
--- a/src/test/python/apache/aurora/client/cli/test_task_run.py
+++ b/src/test/python/apache/aurora/client/cli/test_task_run.py
@@ -24,6 +24,7 @@ from .util import AuroraClientCommandTest
 from gen.apache.aurora.api.ttypes import (
     JobKey,
     ResponseCode,
+    Result,
     ScheduleStatus,
     ScheduleStatusResult,
     TaskQuery
@@ -41,8 +42,8 @@ class TestRunCommand(AuroraClientCommandTest):
   @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    resp.result.scheduleStatusResult.tasks = cls.create_scheduled_tasks()
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(tasks=cls.create_scheduled_tasks()))
     return resp
 
   @classmethod
@@ -116,15 +117,14 @@ class TestSshCommand(AuroraClientCommandTest):
   @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    resp.result.scheduleStatusResult.tasks = cls.create_scheduled_tasks()
+    resp.result = Result(
+        scheduleStatusResult=ScheduleStatusResult(tasks=cls.create_scheduled_tasks()))
     return resp
 
   @classmethod
   def create_nojob_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = ScheduleStatusResult()
-    resp.result.scheduleStatusResult.tasks = []
+    resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=[]))
     return resp
 
   @classmethod

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/test_update.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_update.py b/src/test/python/apache/aurora/client/cli/test_update.py
index 840cde9..a5e59e4 100644
--- a/src/test/python/apache/aurora/client/cli/test_update.py
+++ b/src/test/python/apache/aurora/client/cli/test_update.py
@@ -14,7 +14,7 @@
 import contextlib
 import functools
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.api.health_check import Retriable, StatusHealthCheck
@@ -33,8 +33,10 @@ from gen.apache.aurora.api.ttypes import (
     AddInstancesConfig,
     AssignedTask,
     JobKey,
+    Lock,
     PopulateJobResult,
     ResponseCode,
+    Result,
     ScheduledTask,
     ScheduleStatus,
     ScheduleStatusResult,
@@ -119,23 +121,23 @@ class TestUpdateCommand(AuroraClientCommandTest):
   @classmethod
   def setup_populate_job_config(cls, api, count=20):
     populate = cls.create_simple_success_response()
-    populate.result.populateJobResult = Mock(spec=PopulateJobResult)
-    api.populateJobConfig.return_value = populate
     configs = [TaskConfig(
         numCpus=1.0,
         ramMb=1,
         diskMb=1,
         job=JobKey(role='bozo', environment='test', name='hello')) for i in range(count)]
-    populate.result.populateJobResult.populatedDEPRECATED = set(configs)
+    populate.result = Result(populateJobResult=PopulateJobResult(
+        populatedDEPRECATED=set(configs)
+    ))
+    api.populateJobConfig.return_value = populate
     return populate
 
   @classmethod
   def create_acquire_lock_response(cls, code, msg, token, rolling):
     """Set up the response to a startUpdate API call."""
     start_update_response = cls.create_blank_response(code, msg)
-    start_update_response.result.acquireLockResult = Mock(spec=AcquireLockResult)
-    start_update_response.result.acquireLockResult.lock = "foo"
-    start_update_response.result.acquireLockResult.updateToken = 'token'
+    start_update_response.result = Result(acquireLockResult=AcquireLockResult(
+        lock=Lock(key='foo', token='token')))
     return start_update_response
 
   @classmethod
@@ -150,8 +152,6 @@ class TestUpdateCommand(AuroraClientCommandTest):
     status_response = cls.create_simple_success_response()
     scheduler.getTasksStatus.return_value = status_response
     scheduler.getTasksWithoutConfigs.return_value = status_response
-    schedule_status = Mock(spec=ScheduleStatusResult)
-    status_response.result.scheduleStatusResult = schedule_status
     task_config = TaskConfig(
         numCpus=1.0,
         ramMb=10,
@@ -159,33 +159,34 @@ class TestUpdateCommand(AuroraClientCommandTest):
         job=JobKey(role='bozo', environment='test', name='hello'))
 
     # This should be a list of ScheduledTask's.
-    schedule_status.tasks = []
+    tasks = []
     for i in range(20):
-      task_status = Mock(spec=ScheduledTask)
-      task_status.assignedTask = Mock(spec=AssignedTask)
+      task_status = create_autospec(spec=ScheduledTask, instance=True)
+      task_status.assignedTask = create_autospec(spec=AssignedTask, instance=True)
       task_status.assignedTask.instanceId = i
       task_status.assignedTask.taskId = "Task%s" % i
       task_status.assignedTask.slaveId = "Slave%s" % i
       task_status.slaveHost = "Slave%s" % i
       task_status.assignedTask.task = task_config
-      schedule_status.tasks.append(task_status)
+      tasks.append(task_status)
+    status_response.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
 
   @classmethod
   def setup_health_checks(cls, mock_api):
-    mock_health_check = Mock(spec=StatusHealthCheck)
+    mock_health_check = create_autospec(spec=StatusHealthCheck, instance=True)
     mock_health_check.health.return_value = Retriable.alive()
     return mock_health_check
 
   @classmethod
   def setup_quota_check(cls):
-    mock_quota_check = Mock(spec=QuotaCheck)
+    mock_quota_check = create_autospec(spec=QuotaCheck, instance=True)
     mock_quota_check.validate_quota_from_requested.return_value = (
         cls.create_simple_success_response())
     return mock_quota_check
 
   @classmethod
   def setup_job_monitor(cls):
-    mock_job_monitor = Mock(spec=JobMonitor)
+    mock_job_monitor = create_autospec(spec=JobMonitor, instance=True)
     mock_job_monitor.wait_until.return_value = True
     return mock_job_monitor
 
@@ -396,7 +397,7 @@ class TestUpdateCommand(AuroraClientCommandTest):
             jobKeys=[JobKey(role='bozo', environment='test', name='hello')],
             instanceIds=frozenset([19]),
             statuses=ACTIVE_STATES),
-        'foo')
+        Lock(key='foo', token='token'))
 
   @classmethod
   def assert_correct_status_calls(cls, api):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/cli/util.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/util.py b/src/test/python/apache/aurora/client/cli/util.py
index 796c4f9..154fb3a 100644
--- a/src/test/python/apache/aurora/client/cli/util.py
+++ b/src/test/python/apache/aurora/client/cli/util.py
@@ -15,7 +15,7 @@
 import textwrap
 import unittest
 
-from mock import Mock
+from mock import create_autospec
 
 from apache.aurora.client.cli.context import AuroraCommandContext
 from apache.aurora.client.hooks.hooked_api import HookedAuroraClientAPI
@@ -23,6 +23,8 @@ from apache.aurora.common.aurora_job_key import AuroraJobKey
 from apache.aurora.common.cluster import Cluster
 from apache.aurora.common.clusters import Clusters
 
+from ..api.api_util import SchedulerProxyApiSpec, SchedulerThriftApiSpec
+
 from gen.apache.aurora.api.ttypes import (
     AssignedTask,
     ExecutorConfig,
@@ -30,6 +32,7 @@ from gen.apache.aurora.api.ttypes import (
     JobKey,
     Response,
     ResponseCode,
+    ResponseDetail,
     Result,
     ScheduledTask,
     ScheduleStatus,
@@ -57,16 +60,10 @@ class FakeAuroraCommandContext(AuroraCommandContext):
   def create_mock_api(cls):
     """Builds up a mock API object, with a mock SchedulerProxy.
     Returns the API and the proxy"""
-    # This looks strange, but we set up the same object to use as both
-    # the SchedulerProxy and the SchedulerClient. These tests want to observe
-    # what API calls get made against the scheduler, and both of these objects
-    # delegate calls to the scheduler. It doesn't matter which one is used:
-    # what we care about is that the right API calls get made.
-    mock_api = Mock(spec=HookedAuroraClientAPI)
-    mock_scheduler_proxy = Mock()
+    mock_scheduler_proxy = create_autospec(spec=SchedulerProxyApiSpec, instance=True)
     mock_scheduler_proxy.url = "http://something_or_other"
     mock_scheduler_proxy.scheduler_client.return_value = mock_scheduler_proxy
-    mock_api = Mock(spec=HookedAuroraClientAPI)
+    mock_api = create_autospec(spec=HookedAuroraClientAPI)
     mock_api.scheduler_proxy = mock_scheduler_proxy
     return mock_api
 
@@ -109,14 +106,11 @@ class AuroraClientCommandTest(unittest.TestCase):
 
   @classmethod
   def create_blank_response(cls, code, msg):
-    response = Mock(spec=Response)
-    response.responseCode = code
-    mock_msg = Mock()
-    mock_msg.message = msg
-    response.details = [mock_msg]
-    response.messageDEPRECATED = msg
-    response.result = Mock(spec=Result)
-    return response
+    return Response(
+        responseCode=code,
+        details=[ResponseDetail(message=msg)],
+        messageDEPRECATED=msg
+    )
 
   @classmethod
   def create_simple_success_response(cls):
@@ -129,29 +123,28 @@ class AuroraClientCommandTest(unittest.TestCase):
   @classmethod
   def create_mock_api(cls):
     """Builds up a mock API object, with a mock SchedulerProxy"""
-    mock_scheduler = Mock()
+    mock_scheduler = create_autospec(spec=SchedulerThriftApiSpec, instance=True)
     mock_scheduler.url = "http://something_or_other"
-    mock_scheduler_client = Mock()
-    mock_scheduler_client.scheduler.return_value = mock_scheduler
+    mock_scheduler_client = create_autospec(spec=SchedulerProxyApiSpec, instance=True)
+    #mock_scheduler_client.scheduler.return_value = mock_scheduler
     mock_scheduler_client.url = "http://something_or_other"
-    mock_api = Mock(spec=HookedAuroraClientAPI)
+    mock_api = create_autospec(spec=HookedAuroraClientAPI, instance=True)
     mock_api.scheduler_proxy = mock_scheduler_client
-    return (mock_api, mock_scheduler_client)
+    return mock_api, mock_scheduler_client
 
   @classmethod
   def create_mock_api_factory(cls):
     """Create a collection of mocks for a test that wants to mock out the client API
     by patching the api factory."""
     mock_api, mock_scheduler_client = cls.create_mock_api()
-    mock_api_factory = Mock()
-    mock_api_factory.return_value = mock_api
+    mock_api_factory = lambda: mock_api
     return mock_api_factory, mock_scheduler_client
 
   @classmethod
   def create_status_call_result(cls, mock_task=None):
     status_response = cls.create_simple_success_response()
-    schedule_status = Mock(spec=ScheduleStatusResult)
-    status_response.result.scheduleStatusResult = schedule_status
+    schedule_status = create_autospec(spec=ScheduleStatusResult, instance=True)
+    status_response.result = Result(scheduleStatusResult=schedule_status)
     # This should be a list of ScheduledTask's.
     schedule_status.tasks = []
     if mock_task is None:
@@ -163,15 +156,15 @@ class AuroraClientCommandTest(unittest.TestCase):
 
   @classmethod
   def create_mock_task(cls, instance_id, status=ScheduleStatus.RUNNING):
-    mock_task = Mock(spec=ScheduledTask)
-    mock_task.assignedTask = Mock(spec=AssignedTask)
+    mock_task = create_autospec(spec=ScheduledTask, instance=True)
+    mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
     mock_task.assignedTask.instanceId = instance_id
     mock_task.assignedTask.taskId = "Task%s" % instance_id
     mock_task.assignedTask.slaveId = "Slave%s" % instance_id
-    mock_task.assignedTask.task = Mock(spec=TaskConfig)
+    mock_task.assignedTask.task = create_autospec(spec=TaskConfig, instance=True)
     mock_task.slaveHost = "Slave%s" % instance_id
     mock_task.status = status
-    mock_task_event = Mock(spec=TaskEvent)
+    mock_task_event = create_autospec(spec=TaskEvent, instance=True)
     mock_task_event.timestamp = 1000
     mock_task.taskEvents = [mock_task_event]
     return mock_task
@@ -188,7 +181,7 @@ class AuroraClientCommandTest(unittest.TestCase):
       task.assignedTask.task = TaskConfig()
       task.assignedTask.task.maxTaskFailures = 1
       task.assignedTask.task.executorConfig = ExecutorConfig()
-      task.assignedTask.task.executorConfig.data = Mock()
+      task.assignedTask.task.executorConfig.data = 'fake data'
       task.assignedTask.task.metadata = []
       task.assignedTask.task.job = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
       task.assignedTask.task.owner = Identity(role=cls.TEST_ROLE)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_admin.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_admin.py b/src/test/python/apache/aurora/client/commands/test_admin.py
index cae5395..7dd61cd 100644
--- a/src/test/python/apache/aurora/client/commands/test_admin.py
+++ b/src/test/python/apache/aurora/client/commands/test_admin.py
@@ -14,7 +14,7 @@
 
 import contextlib
 
-from mock import Mock, patch, PropertyMock
+from mock import create_autospec, patch, PropertyMock
 
 from apache.aurora.client.api import AuroraClientAPI
 from apache.aurora.client.api.scheduler_client import SchedulerClient, SchedulerProxy
@@ -52,7 +52,10 @@ class TestQueryCommand(AuroraClientCommandTest):
 
   @classmethod
   def setup_mock_options(cls, force=False, shards=None, states='RUNNING', listformat=None):
-    mock_options = Mock(spec=['force', 'shards', 'states', 'listformat', 'verbosity'])
+    mock_options = create_autospec(
+        spec=['force', 'shards', 'states', 'listformat', 'verbosity'],
+        spec_set=False,
+        instance=True)
     mock_options.force = force
     mock_options.shards = shards
     mock_options.states = states
@@ -133,7 +136,7 @@ class TestIncreaseQuotaCommand(AuroraClientCommandTest):
     with contextlib.nested(
         patch('twitter.common.app.get_options', return_value=mock_options),
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-            new=Mock(spec=AuroraClientAPI)),
+            new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS)
     ) as (_, api, _):
 
@@ -169,7 +172,7 @@ class TestSetQuotaCommand(AuroraClientCommandTest):
     with contextlib.nested(
         patch('twitter.common.app.get_options', return_value=mock_options),
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-              new=Mock(spec=AuroraClientAPI)),
+              new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS)
     ) as (_, api, _):
 
@@ -208,7 +211,7 @@ class TestGetLocksCommand(AuroraClientCommandTest):
     with contextlib.nested(
         patch('twitter.common.app.get_options', return_value=mock_options),
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-              new=Mock(spec=AuroraClientAPI)),
+              new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('apache.aurora.client.commands.admin.print_results'),
     ) as (_, api, _, mock_print_results):
@@ -228,8 +231,8 @@ class TestGetSchedulerCommand(AuroraClientCommandTest):
   def test_get_scheduler(self):
     """Tests successful execution of the get_scheduler command."""
     mock_options = self.setup_mock_options()
-    mock_proxy = Mock(spec=SchedulerProxy)
-    mock_scheduler_client = Mock(spec=SchedulerClient)
+    mock_proxy = create_autospec(spec=SchedulerProxy, instance=True)
+    mock_scheduler_client = create_autospec(spec=SchedulerClient, instance=True)
     mock_raw_url = PropertyMock(return_value="url")
     mock_proxy.scheduler_client.return_value = mock_scheduler_client
     mock_scheduler_client.raw_url = mock_raw_url
@@ -237,7 +240,7 @@ class TestGetSchedulerCommand(AuroraClientCommandTest):
     with contextlib.nested(
         patch('twitter.common.app.get_options', return_value=mock_options),
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-              new=Mock(spec=AuroraClientAPI)),
+              new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
     ) as (_, api, _):
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_admin_sla.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_admin_sla.py b/src/test/python/apache/aurora/client/commands/test_admin_sla.py
index a565318..74fc79c 100644
--- a/src/test/python/apache/aurora/client/commands/test_admin_sla.py
+++ b/src/test/python/apache/aurora/client/commands/test_admin_sla.py
@@ -15,7 +15,7 @@
 import contextlib
 from collections import defaultdict
 
-from mock import Mock, patch
+from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
 from apache.aurora.client.api import AuroraClientAPI
@@ -34,9 +34,9 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
   @classmethod
   def setup_mock_options(cls, exclude=None, include=None, override=None,
                          exclude_list=None, include_list=None, list_jobs=False, grouping=None):
-    mock_options = Mock(spec=['exclude_filename', 'exclude_hosts', 'include_filename',
+    mock_options = create_autospec(spec=['exclude_filename', 'exclude_hosts', 'include_filename',
         'include_hosts', 'override_filename', 'list_jobs', 'verbosity', 'disable_all_hooks',
-        'min_instance_count', 'grouping'])
+        'min_instance_count', 'grouping'], instance=True)
 
     mock_options.exclude_filename = exclude
     mock_options.exclude_hosts = exclude_list
@@ -61,7 +61,7 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
 
   @classmethod
   def create_mock_vector(cls, result):
-    mock_vector = Mock(spec=DomainUpTimeSlaVector)
+    mock_vector = create_autospec(spec=DomainUpTimeSlaVector, instance=True)
     mock_vector.get_safe_hosts.return_value = result
     return mock_vector
 
@@ -71,7 +71,7 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
     mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
     with contextlib.nested(
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-            new=Mock(spec=AuroraClientAPI)),
+            new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.print_results'),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('twitter.common.app.get_options', return_value=mock_options)
@@ -96,7 +96,7 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
       mock_options = self.setup_mock_options(exclude=fp.name)
       with contextlib.nested(
           patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-              new=Mock(spec=AuroraClientAPI)),
+              new=create_autospec(spec=AuroraClientAPI)),
           patch('apache.aurora.client.commands.admin.print_results'),
           patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
           patch('twitter.common.app.get_options', return_value=mock_options)
@@ -119,7 +119,7 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
     mock_options = self.setup_mock_options(exclude_list=','.join(['h0', 'h1']))
     with contextlib.nested(
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-            new=Mock(spec=AuroraClientAPI)),
+            new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.print_results'),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('twitter.common.app.get_options', return_value=mock_options)
@@ -146,7 +146,7 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
       mock_options = self.setup_mock_options(include=fp.name)
       with contextlib.nested(
           patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-              new=Mock(spec=AuroraClientAPI)),
+              new=create_autospec(spec=AuroraClientAPI)),
           patch('apache.aurora.client.commands.admin.print_results'),
           patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
           patch('twitter.common.app.get_options', return_value=mock_options)
@@ -172,7 +172,7 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
     mock_options = self.setup_mock_options(include_list=','.join(hosts))
     with contextlib.nested(
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-            new=Mock(spec=AuroraClientAPI)),
+            new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.print_results'),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('twitter.common.app.get_options', return_value=mock_options)
@@ -200,7 +200,7 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
       mock_options = self.setup_mock_options(override=fp.name)
       with contextlib.nested(
           patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-              new=Mock(spec=AuroraClientAPI)),
+              new=create_autospec(spec=AuroraClientAPI)),
           patch('apache.aurora.client.commands.admin.print_results'),
           patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
           patch('twitter.common.app.get_options', return_value=mock_options)
@@ -225,7 +225,7 @@ class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
     mock_vector = self.create_mock_vector(self.create_hosts(3, 50, 100))
     with contextlib.nested(
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-            new=Mock(spec=AuroraClientAPI)),
+            new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.print_results'),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('twitter.common.app.get_options', return_value=mock_options)
@@ -299,16 +299,20 @@ class TestAdminSlaProbeHostsCommand(AuroraClientCommandTest):
 
   @classmethod
   def setup_mock_options(cls, hosts=None, filename=None, grouping=None):
-    mock_options = Mock(spec=['hosts', 'filename', 'verbosity', 'min_instance_count', 'grouping'])
+    mock_options = create_autospec(
+        spec=['hosts', 'filename', 'verbosity', 'min_instance_count', 'grouping'],
+        spec_set=False,
+        instance=True)
     mock_options.hosts = hosts
     mock_options.filename = filename
     mock_options.verbosity = False
     mock_options.grouping = grouping or DEFAULT_GROUPING
+    mock_options.min_instance_count = 1
     return mock_options
 
   @classmethod
   def create_mock_vector(cls, result):
-    mock_vector = Mock(spec=DomainUpTimeSlaVector)
+    mock_vector = create_autospec(spec=DomainUpTimeSlaVector, instance=True)
     mock_vector.probe_hosts.return_value = result
     return mock_vector
 
@@ -328,7 +332,7 @@ class TestAdminSlaProbeHostsCommand(AuroraClientCommandTest):
     mock_vector = self.create_mock_probe_hosts_vector([self.create_probe_hosts(2, 80, True, 0)])
     with contextlib.nested(
         patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-            new=Mock(spec=AuroraClientAPI)),
+            new=create_autospec(spec=AuroraClientAPI)),
         patch('apache.aurora.client.commands.admin.print_results'),
         patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('twitter.common.app.get_options', return_value=mock_options)
@@ -358,7 +362,7 @@ class TestAdminSlaProbeHostsCommand(AuroraClientCommandTest):
       mock_options = self.setup_mock_options(filename=fp.name)
       with contextlib.nested(
           patch('apache.aurora.client.commands.admin.AuroraClientAPI',
-              new=Mock(spec=AuroraClientAPI)),
+              new=create_autospec(spec=AuroraClientAPI)),
           patch('apache.aurora.client.commands.admin.print_results'),
           patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
           patch('twitter.common.app.get_options', return_value=mock_options)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d01f0c38/src/test/python/apache/aurora/client/commands/test_cancel_update.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_cancel_update.py b/src/test/python/apache/aurora/client/commands/test_cancel_update.py
index 5d2a789..e827b38 100644
--- a/src/test/python/apache/aurora/client/commands/test_cancel_update.py
+++ b/src/test/python/apache/aurora/client/commands/test_cancel_update.py
@@ -22,7 +22,7 @@ from apache.aurora.common.aurora_job_key import AuroraJobKey
 
 from .util import AuroraClientCommandTest
 
-from gen.apache.aurora.api.ttypes import JobKey, ScheduleStatus, ScheduleStatusResult, TaskQuery
+from gen.apache.aurora.api.ttypes import JobKey, TaskQuery
 
 
 class TestClientCancelUpdateCommand(AuroraClientCommandTest):
@@ -41,23 +41,10 @@ class TestClientCancelUpdateCommand(AuroraClientCommandTest):
   @classmethod
   def setup_mock_api_factory(cls):
     mock_api_factory, mock_api = cls.create_mock_api_factory()
-    mock_api_factory.return_value.cancel_update.return_value = cls.get_cancel_update_response()
+    mock_api_factory('fake').cancel_update.return_value = cls.get_cancel_update_response()
     return mock_api_factory
 
   @classmethod
-  def create_mock_status_query_result(cls, scheduleStatus):
-    mock_query_result = cls.create_simple_success_response()
-    mock_query_result.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
-    if scheduleStatus == ScheduleStatus.INIT:
-      # status query result for before job is launched.
-      mock_query_result.result.scheduleStatusResult.tasks = []
-    else:
-      mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
-      mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
-      mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]
-    return mock_query_result
-
-  @classmethod
   def get_cancel_update_response(cls):
     return cls.create_simple_success_response()
 
@@ -66,7 +53,7 @@ class TestClientCancelUpdateCommand(AuroraClientCommandTest):
     # Running cancel update should result in calling the API cancel_update
     # method once, with an AuroraJobKey parameter.
     assert mock_api.cancel_update.call_count == 1
-    assert mock_api.cancel_update.called_with(
+    mock_api.cancel_update.assert_called_with(
         AuroraJobKey(cls.TEST_CLUSTER, cls.TEST_ROLE, cls.TEST_ENV, cls.TEST_JOB),
         config=None)
 
@@ -81,9 +68,8 @@ class TestClientCancelUpdateCommand(AuroraClientCommandTest):
         patch('apache.aurora.client.commands.core.make_client_factory',
             return_value=mock_api_factory),
         patch('twitter.common.app.get_options', return_value=mock_options),
-        patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)) as (
-            mock_make_client_factory, options, mock_get_job_config):
-      mock_api = mock_api_factory.return_value
+        patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
+      mock_api = mock_api_factory('fake')
 
       cancel_update(['west/mchucarroll/test/hello'], mock_options)
       self.assert_cancel_update_called(mock_api)