def test_cleanup_apps(self): soa_dir = 'not_really_a_dir' expected_apps = [('present', 'away'), ('on-app', 'off')] fake_app_ids = [mock.Mock(id='present.away.gone.wtf'), mock.Mock(id='on-app.off.stop.jrm'), mock.Mock(id='not-here.oh.no.weirdo')] self.fake_marathon_client.list_apps = mock.Mock(return_value=fake_app_ids) with contextlib.nested( mock.patch('cleanup_marathon_jobs.get_services_for_cluster', return_value=expected_apps, autospec=True), mock.patch('paasta_tools.marathon_tools.load_marathon_config', autospec=True, return_value=self.fake_marathon_config), mock.patch('paasta_tools.marathon_tools.get_marathon_client', autospec=True, return_value=self.fake_marathon_client), mock.patch('cleanup_marathon_jobs.delete_app', autospec=True), ) as ( get_services_for_cluster_patch, config_patch, client_patch, delete_patch, ): cleanup_marathon_jobs.cleanup_apps(soa_dir) config_patch.assert_called_once_with() get_services_for_cluster_patch.assert_called_once_with(instance_type='marathon', soa_dir=soa_dir) client_patch.assert_called_once_with(self.fake_marathon_config.get_url(), self.fake_marathon_config.get_username(), self.fake_marathon_config.get_password()) delete_patch.assert_called_once_with('not-here.oh.no.weirdo', self.fake_marathon_client)
def test_cleanup_apps_doesnt_delete_unknown_apps(self): soa_dir = 'not_really_a_dir' expected_apps = [('present', 'away'), ('on-app', 'off')] fake_app_ids = [mock.Mock(id='non_conforming_app')] self.fake_marathon_client.list_apps = mock.Mock(return_value=fake_app_ids) with contextlib.nested( mock.patch('cleanup_marathon_jobs.get_services_for_cluster', return_value=expected_apps, autospec=True), mock.patch('paasta_tools.marathon_tools.load_marathon_config', autospec=True, return_value=self.fake_marathon_config), mock.patch('paasta_tools.marathon_tools.get_marathon_client', autospec=True, return_value=self.fake_marathon_client), mock.patch('cleanup_marathon_jobs.delete_app', autospec=True), ) as ( get_services_for_cluster_patch, config_patch, client_patch, delete_patch, ): cleanup_marathon_jobs.cleanup_apps(soa_dir) assert delete_patch.call_count == 0