def setUp(self): self._command = AddCommand() self._mock_options = mock_verb_options(self._command) self._mock_options.task_instance = TaskInstanceKey(self.TEST_JOBKEY, 1) self._mock_options.instance_count = 3 self._fake_context = FakeAuroraCommandContext() self._fake_context.set_options(self._mock_options) self._mock_api = self._fake_context.get_api('test')
def setUp(self): self._command = AddCommand() self._mock_options = mock_verb_options(self._command) self._mock_options.task_instance = TaskInstanceKey(self.TEST_JOBKEY, 1) self._mock_options.instance_count = 3 self._fake_context = FakeAuroraCommandContext() self._fake_context.set_options(self._mock_options) self._mock_api = self._fake_context.get_api('test')
class TestAddCommand(AuroraClientCommandTest): def setUp(self): self._command = AddCommand() self._mock_options = mock_verb_options(self._command) self._mock_options.task_instance = TaskInstanceKey(self.TEST_JOBKEY, 1) self._mock_options.instance_count = 3 self._fake_context = FakeAuroraCommandContext() self._fake_context.set_options(self._mock_options) self._mock_api = self._fake_context.get_api('test') def test_add_instances(self): self._mock_options.open_browser = True self._fake_context.add_expected_query_result(self.create_query_call_result( self.create_scheduled_task(1, ScheduleStatus.RUNNING))) self._mock_api.add_instances.return_value = self.create_simple_success_response() with patch('webbrowser.open_new_tab') as mock_webbrowser: self._command.execute(self._fake_context) assert self._mock_api.add_instances.mock_calls == [call( self.TEST_JOBKEY, self._mock_options.task_instance.instance, 3)] assert mock_webbrowser.mock_calls == [ call("http://something_or_other/scheduler/bozo/test/hello") ] def test_wait_added_instances(self): self._mock_options.wait_until = 'RUNNING' self._fake_context.add_expected_query_result(self.create_query_call_result( self.create_scheduled_task(1, ScheduleStatus.PENDING))) self._mock_api.add_instances.return_value = self.create_simple_success_response() with patch('apache.aurora.client.cli.jobs.wait_until') as mock_wait: self._command.execute(self._fake_context) assert self._mock_api.add_instances.mock_calls == [call( self.TEST_JOBKEY, self._mock_options.task_instance.instance, 3)] assert mock_wait.mock_calls == [call( self._mock_options.wait_until, self.TEST_JOBKEY, self._mock_api, [2, 3, 4])] def test_no_active_instance(self): self._fake_context.add_expected_query_result(self.create_empty_task_result()) with pytest.raises(Context.CommandError): self._command.execute(self._fake_context) def test_add_instances_raises(self): self._fake_context.add_expected_query_result(self.create_query_call_result( self.create_scheduled_task(1, ScheduleStatus.PENDING))) self._mock_api.add_instances.return_value = self.create_error_response() with pytest.raises(Context.CommandError): self._command.execute(self._fake_context)
class TestAddCommand(AuroraClientCommandTest): def setUp(self): self._command = AddCommand() self._mock_options = mock_verb_options(self._command) self._mock_options.task_instance = TaskInstanceKey(self.TEST_JOBKEY, 1) self._mock_options.instance_count = 3 self._fake_context = FakeAuroraCommandContext() self._fake_context.set_options(self._mock_options) self._mock_api = self._fake_context.get_api('test') def test_add_instances(self): self._mock_options.open_browser = True self._fake_context.add_expected_query_result( self.create_query_call_result( self.create_scheduled_task(1, ScheduleStatus.RUNNING))) self._mock_api.add_instances.return_value = self.create_simple_success_response( ) with patch('webbrowser.open_new_tab') as mock_webbrowser: self._command.execute(self._fake_context) assert self._mock_api.add_instances.mock_calls == [ call(self.TEST_JOBKEY, self._mock_options.task_instance.instance, 3) ] assert mock_webbrowser.mock_calls == [ call("http://something_or_other/scheduler/bozo/test/hello") ] def test_wait_added_instances(self): self._mock_options.wait_until = 'RUNNING' self._fake_context.add_expected_query_result( self.create_query_call_result( self.create_scheduled_task(1, ScheduleStatus.PENDING))) self._mock_api.add_instances.return_value = self.create_simple_success_response( ) with patch('apache.aurora.client.cli.jobs.wait_until') as mock_wait: self._command.execute(self._fake_context) assert self._mock_api.add_instances.mock_calls == [ call(self.TEST_JOBKEY, self._mock_options.task_instance.instance, 3) ] assert mock_wait.mock_calls == [ call(self._mock_options.wait_until, self.TEST_JOBKEY, self._mock_api, [2, 3, 4]) ] def test_no_active_instance(self): self._fake_context.add_expected_query_result( self.create_empty_task_result()) with pytest.raises(Context.CommandError): self._command.execute(self._fake_context) def test_add_instances_raises(self): self._fake_context.add_expected_query_result( self.create_query_call_result( self.create_scheduled_task(1, ScheduleStatus.PENDING))) self._mock_api.add_instances.return_value = self.create_error_response( ) with pytest.raises(Context.CommandError): self._command.execute(self._fake_context)