Esempio n. 1
0
  def test_create_with_lock(self):
    command = CreateJobCommand()

    jobkey = AuroraJobKey("cluster", "role", "env", "job")
    mock_options = mock_verb_options(command)
    mock_options.jobspec = jobkey
    mock_options.config_file = "/tmp/whatever"

    fake_context = FakeAuroraCommandContext()
    fake_context.set_options(mock_options)

    mock_config = create_autospec(spec=AuroraConfig, spec_set=True, instance=True)
    mock_job_config = Mock()
    mock_job_config.has_cron_schedule.return_value = False
    mock_config.raw.return_value = mock_job_config
    fake_context.get_job_config = Mock(return_value=mock_config)
    mock_api = fake_context.get_api("test")

    mock_api.create_job.return_value = AuroraClientCommandTest.create_blank_response(
      ResponseCode.LOCK_ERROR, "Error.")

    with pytest.raises(Context.CommandError):
      command.execute(fake_context)

    mock_api.create_job.assert_called_once_with(mock_config)
    self.assert_lock_message(fake_context)
Esempio n. 2
0
    def test_create_with_lock(self):
        command = CreateJobCommand()

        jobkey = AuroraJobKey("cluster", "role", "env", "job")
        mock_options = mock_verb_options(command)
        mock_options.jobspec = jobkey
        mock_options.config_file = "/tmp/whatever"

        fake_context = FakeAuroraCommandContext()
        fake_context.set_options(mock_options)

        mock_config = create_autospec(spec=AuroraConfig,
                                      spec_set=True,
                                      instance=True)
        mock_job_config = Mock()
        mock_job_config.has_cron_schedule.return_value = False
        mock_config.raw.return_value = mock_job_config
        fake_context.get_job_config = Mock(return_value=mock_config)
        mock_api = fake_context.get_api("test")

        mock_api.create_job.return_value = AuroraClientCommandTest.create_blank_response(
            ResponseCode.JOB_UPDATING_ERROR, "Error.")

        with pytest.raises(Context.CommandError):
            command.execute(fake_context)

        mock_api.create_job.assert_called_once_with(mock_config)
        self.assert_lock_message(fake_context)