def test_delete_app(self):
     app_id = 'example--service.main.git93340779.configddb38a65'
     client = self.fake_marathon_client
     with contextlib.nested(
         mock.patch('cleanup_marathon_jobs.load_system_paasta_config', autospec=True),
         mock.patch('paasta_tools.bounce_lib.bounce_lock_zookeeper', autospec=True),
         mock.patch('paasta_tools.bounce_lib.delete_marathon_app', autospec=True),
         mock.patch('cleanup_marathon_jobs._log', autospec=True),
     ) as (
         mock_load_system_paasta_config,
         mock_bounce_lock_zookeeper,
         mock_delete_marathon_app,
         mock_log,
     ):
         mock_load_system_paasta_config.return_value.get_cluster = mock.Mock(return_value='fake_cluster')
         cleanup_marathon_jobs.delete_app(app_id, client)
         mock_delete_marathon_app.assert_called_once_with(app_id, client)
         mock_load_system_paasta_config.return_value.get_cluster.assert_called_once_with()
         expected_log_line = (
             'Deleted stale marathon job that looks lost: ' +
             app_id
         )
         mock_log.assert_called_once_with(
             instance='main',
             service='example_service',
             level='event',
             component='deploy',
             cluster='fake_cluster',
             line=expected_log_line,
         )
    def test_delete_app_throws_exception(self):
        app_id = 'example--service.main.git93340779.configddb38a65'
        client = self.fake_marathon_client

        with contextlib.nested(
            mock.patch('cleanup_marathon_jobs.load_system_paasta_config', autospec=True),
            mock.patch('paasta_tools.bounce_lib.bounce_lock_zookeeper', autospec=True),
            mock.patch('paasta_tools.bounce_lib.delete_marathon_app', side_effect=ValueError('foo')),
            mock.patch('cleanup_marathon_jobs._log', autospec=True),
        ) as (
            mock_load_system_paasta_config,
            mock_bounce_lock_zookeeper,
            mock_delete_marathon_app,
            mock_log,
        ):
            with raises(ValueError):
                cleanup_marathon_jobs.delete_app(app_id, client)
            assert 'example_service' in mock_log.mock_calls[0][2]["line"]
            assert 'Traceback' in mock_log.mock_calls[1][2]["line"]