Example #1
0
 def setUp(self):
   self._command = ListUpdates()
   self._job_key = AuroraJobKey.from_thrift("cluster", UPDATE_KEY.job)
   self._mock_options = mock_verb_options(self._command)
   self._mock_options.filter = UpdateFilter(
     cluster=self.TEST_CLUSTER, role=None, env=None, job=None)
   self._fake_context = FakeAuroraCommandContext()
   self._fake_context.set_options(self._mock_options)
   self._mock_api = self._fake_context.get_api('UNUSED')
Example #2
0
 def setUp(self):
     self._command = ListUpdates()
     self._job_key = AuroraJobKey.from_thrift("cluster", UPDATE_KEY.job)
     self._mock_options = mock_verb_options(self._command)
     self._mock_options.filter = UpdateFilter(cluster=self.TEST_CLUSTER, role=None, env=None, job=None)
     self._fake_context = FakeAuroraCommandContext()
     self._fake_context.set_options(self._mock_options)
     self._mock_api = self._fake_context.get_api("UNUSED")
Example #3
0
class TestListUpdates(AuroraClientCommandTest):

  def setUp(self):
    self._command = ListUpdates()
    self._job_key = AuroraJobKey.from_thrift("cluster", UPDATE_KEY.job)
    self._mock_options = mock_verb_options(self._command)
    self._mock_options.filter = UpdateFilter(
      cluster=self.TEST_CLUSTER, role=None, env=None, job=None)
    self._fake_context = FakeAuroraCommandContext()
    self._fake_context.set_options(self._mock_options)
    self._mock_api = self._fake_context.get_api('UNUSED')

  def test_list_updates_command(self):
    self._mock_api.query_job_updates.return_value = get_status_query_response(count=3)
    self._mock_options.user = '******'

    assert self._command.execute(self._fake_context) == EXIT_OK
    assert self._mock_api.query_job_updates.mock_calls == [
        call(role=None, user="******", job_key=None, update_statuses=None)
    ]

    # Ideally we would use a resource file for this, but i was unable to find a way to make that
    # work in both pants and pycharm.
    assert self._fake_context.get_out_str() == "\
JOB                                             UPDATE ID                            STATUS        \
  CREATED BY  STARTED             LAST MODIFIED      " + """
west/bozo/test/hello                            update_id                            ROLLED_FORWARD\
  me          1970-01-17T08:03:24 1970-06-13T08:34:16
west/bozo/test/hello                            update_id                            ROLLED_FORWARD\
  me          1970-01-17T08:03:24 1970-06-13T08:34:16
west/bozo/test/hello                            update_id                            ROLLED_FORWARD\
  me          1970-01-17T08:03:24 1970-06-13T08:34:16"""

  def test_list_updates_by_status(self):
    self._mock_options.status = ListUpdates.STATUS_GROUPS.keys()
    self._mock_api.query_job_updates.return_value = get_status_query_response(count=3)
    assert self._command.execute(self._fake_context) == EXIT_OK
    assert self._mock_api.query_job_updates.mock_calls == [
        call(
            role=None,
            user=None,
            job_key=None,
            update_statuses=set(JobUpdateStatus._VALUES_TO_NAMES.keys()))
    ]

  def test_list_updates_by_env(self):
    self._mock_options.filter = UpdateFilter(
      cluster=self.TEST_CLUSTER, role='role', env='noenv', job=None)
    self._mock_api.query_job_updates.return_value = get_status_query_response(count=3)
    assert self._command.execute(self._fake_context) == EXIT_OK
    assert self._mock_api.query_job_updates.mock_calls == [
        call(role="role", user=None, job_key=None, update_statuses=None)
    ]
    # None of the returned values matched the env filter, so there is no output.
    assert self._fake_context.get_out_str() == ''

  def test_list_updates_command_json(self):
    self._mock_options.user = '******'
    self._mock_options.write_json = True
    self._mock_api.query_job_updates.return_value = get_status_query_response(count=3)
    assert self._command.execute(self._fake_context) == EXIT_OK
    assert json.loads(self._fake_context.get_out_str()) == [
        {
            "status": "ROLLED_FORWARD",
            "started": "1970-01-17T08:03:24",
            "last_modified": "1970-06-13T08:34:16",
            "user": "******",
            "job": "west/bozo/test/hello",
            "id": "update_id"
        },
        {
            "status": "ROLLED_FORWARD",
            "started": "1970-01-17T08:03:24",
            "last_modified": "1970-06-13T08:34:16",
            "user": "******",
            "job": "west/bozo/test/hello",
            "id": "update_id"
        },
        {
            "status": "ROLLED_FORWARD",
            "started": "1970-01-17T08:03:24",
            "last_modified": "1970-06-13T08:34:16",
            "user": "******",
            "job": "west/bozo/test/hello",
            "id": "update_id"
        }
    ]
Example #4
0
class TestListUpdates(AuroraClientCommandTest):
    def setUp(self):
        self._command = ListUpdates()
        self._job_key = AuroraJobKey.from_thrift("cluster", UPDATE_KEY.job)
        self._mock_options = mock_verb_options(self._command)
        self._mock_options.filter = UpdateFilter(cluster=self.TEST_CLUSTER,
                                                 role=None,
                                                 env=None,
                                                 job=None)
        self._fake_context = FakeAuroraCommandContext()
        self._fake_context.set_options(self._mock_options)
        self._mock_api = self._fake_context.get_api('UNUSED')

    def test_list_updates_command(self):
        self._mock_api.query_job_updates.return_value = get_status_query_response(
            count=3)
        self._mock_options.user = '******'

        assert self._command.execute(self._fake_context) == EXIT_OK
        assert self._mock_api.query_job_updates.mock_calls == [
            call(role=None, user="******", job_key=None, update_statuses=None)
        ]

        # Ideally we would use a resource file for this, but i was unable to find a way to make that
        # work in both pants and pycharm.
        assert self._fake_context.get_out_str() == "\
JOB                                             UPDATE ID                            STATUS        \
  CREATED BY  STARTED             LAST MODIFIED      " + """
west/bozo/test/hello                            update_id                            ROLLED_FORWARD\
  me          1970-01-17T08:03:24 1970-06-13T08:34:16
west/bozo/test/hello                            update_id                            ROLLED_FORWARD\
  me          1970-01-17T08:03:24 1970-06-13T08:34:16
west/bozo/test/hello                            update_id                            ROLLED_FORWARD\
  me          1970-01-17T08:03:24 1970-06-13T08:34:16"""

    def test_list_updates_by_status(self):
        self._mock_options.status = ListUpdates.STATUS_GROUPS.keys()
        self._mock_api.query_job_updates.return_value = get_status_query_response(
            count=3)
        assert self._command.execute(self._fake_context) == EXIT_OK
        assert self._mock_api.query_job_updates.mock_calls == [
            call(role=None,
                 user=None,
                 job_key=None,
                 update_statuses=set(JobUpdateStatus._VALUES_TO_NAMES.keys()))
        ]

    def test_list_updates_by_env(self):
        self._mock_options.filter = UpdateFilter(cluster=self.TEST_CLUSTER,
                                                 role='role',
                                                 env='noenv',
                                                 job=None)
        self._mock_api.query_job_updates.return_value = get_status_query_response(
            count=3)
        assert self._command.execute(self._fake_context) == EXIT_OK
        assert self._mock_api.query_job_updates.mock_calls == [
            call(role="role", user=None, job_key=None, update_statuses=None)
        ]
        # None of the returned values matched the env filter, so there is no output.
        assert self._fake_context.get_out_str() == ''

    def test_list_updates_command_json(self):
        self._mock_options.user = '******'
        self._mock_options.write_json = True
        self._mock_api.query_job_updates.return_value = get_status_query_response(
            count=3)
        assert self._command.execute(self._fake_context) == EXIT_OK
        assert json.loads(self._fake_context.get_out_str()) == [{
            "status":
            "ROLLED_FORWARD",
            "started":
            "1970-01-17T08:03:24",
            "last_modified":
            "1970-06-13T08:34:16",
            "user":
            "******",
            "job":
            "west/bozo/test/hello",
            "id":
            "update_id"
        }, {
            "status":
            "ROLLED_FORWARD",
            "started":
            "1970-01-17T08:03:24",
            "last_modified":
            "1970-06-13T08:34:16",
            "user":
            "******",
            "job":
            "west/bozo/test/hello",
            "id":
            "update_id"
        }, {
            "status":
            "ROLLED_FORWARD",
            "started":
            "1970-01-17T08:03:24",
            "last_modified":
            "1970-06-13T08:34:16",
            "user":
            "******",
            "job":
            "west/bozo/test/hello",
            "id":
            "update_id"
        }]