def test_exit_ok(insights_config, insights_client): """ Support collection replaces the normal client run. """ with raises(SystemExit) as exc_info: post_update() assert exc_info.value.code == 0
def test_post_update_payload_off(insights_config, insights_client): """ Registration is processed in normal operation (no payload) """ insights_config.return_value.load_all.return_value.payload = False try: post_update() except SystemExit: pass insights_client.return_value.register.assert_called_once()
def test_post_update_legacy_upload_on(insights_config, insights_client): """ Registration is processed in legacy_upload=True """ insights_config.return_value.load_all.return_value.legacy_upload = True try: post_update() except SystemExit: pass insights_client.return_value.register.assert_called_once()
def test_post_update_payload_on(insights_config, insights_client): """ Registration is not processed when a payload is uploaded """ insights_config.return_value.load_all.return_value.payload = True try: post_update() except SystemExit: pass insights_client.return_value.register.assert_not_called()
def test_post_update_legacy_upload_off(insights_config, insights_client): """ Registration is still called when platform upload """ insights_config.return_value.load_all.return_value.legacy_upload = False try: post_update() except SystemExit: pass insights_client.return_value.register.assert_called_once()
def test_post_update_no_upload(insights_config, insights_client): """ No-upload short circuits this phase """ insights_config.return_value.load_all.return_value.no_upload = True try: post_update() except SystemExit: pass insights_client.return_value.register.assert_not_called() insights_client.return_value.get_machine_id.assert_called_once()
def test_post_update_offline(insights_config, insights_client): """ Offline mode short circuits this phase """ insights_config.return_value.load_all.return_value.offline = True try: post_update() except SystemExit: pass insights_client.return_value.get_machine_id.assert_called_once() insights_client.return_value.get_registration_status.assert_not_called() insights_client.return_value.clear_local_registration.assert_not_called() insights_client.return_value.set_display_name.assert_not_called()
def test_post_update_no_options_err_reg_check(insights_config, insights_client): """ Client run with no options. If registration check fails, exit with 101 exit code """ insights_client.return_value.get_registration_status = MagicMock(return_value=None) with raises(SystemExit) as exc_info: post_update() assert exc_info.value.code == 101 insights_client.return_value.get_machine_id.assert_called_once() insights_client.return_value.get_registration_status.assert_called_once() insights_client.return_value.clear_local_registration.assert_not_called() insights_client.return_value.set_display_name.assert_not_called()
def test_post_update_no_options_registered(insights_config, insights_client): """ Client run with no options. If registered, exit with 0 exit code (don't kill parent) """ insights_client.return_value.get_registration_status = MagicMock(return_value=True) with raises(SystemExit) as exc_info: post_update() assert exc_info.value.code == 0 insights_client.return_value.get_machine_id.assert_called_once() insights_client.return_value.get_registration_status.assert_called_once() insights_client.return_value.clear_local_registration.assert_not_called() insights_client.return_value.set_display_name.assert_not_called()
def test_post_update_check_status_registered(insights_config, insights_client): """ Just check status. If registered, exit with 100 exit code (kill parent) """ insights_config.return_value.load_all.return_value.status = True insights_client.return_value.get_registration_status = MagicMock(return_value=True) with raises(SystemExit) as exc_info: post_update() assert exc_info.value.code == 100 insights_client.return_value.get_machine_id.assert_called_once() insights_client.return_value.get_registration_status.assert_called_once() insights_client.return_value.clear_local_registration.assert_not_called() insights_client.return_value.set_display_name.assert_not_called()
def test_post_update_set_display_name_cli_no_register_reg(insights_config, insights_client, get_scheduler): """ Client is registered, and run with --display-name but not --register Should exit with code 100 after setting display name """ insights_config.return_value.load_all.return_value.display_name = True insights_config.return_value.load_all.return_value._cli_opts = ['display_name'] insights_client.return_value.get_registration_status = MagicMock(return_value=True) with raises(SystemExit) as exc_info: post_update() assert exc_info.value.code == 100 insights_client.return_value.get_machine_id.assert_called_once() insights_client.return_value.get_registration_status.assert_called_once() insights_client.return_value.set_display_name.assert_called_once() get_scheduler.return_value.set_daily.assert_not_called()
def test_post_update_unregister_unregistered(insights_config, insights_client, get_scheduler): """ Client run with --unregister. If unregistered, exit with 101 exit code """ insights_config.return_value.load_all.return_value.unregister = True insights_client.return_value.get_registration_status = MagicMock(return_value=False) with raises(SystemExit) as exc_info: post_update() assert exc_info.value.code == 101 insights_client.return_value.get_machine_id.assert_called_once() insights_client.return_value.get_registration_status.assert_called_once() insights_client.return_value.clear_local_registration.assert_not_called() insights_client.return_value.set_display_name.assert_not_called() get_scheduler.return_value.remove_scheduling.assert_not_called()
def test_post_update_register_registered(insights_config, insights_client, get_scheduler): """ Client run with --register. If registered, exit with 0 exit code (don't kill parent) Also enable scheduling. """ insights_config.return_value.load_all.return_value.register = True insights_client.return_value.get_registration_status = MagicMock(return_value=True) with raises(SystemExit) as exc_info: post_update() assert exc_info.value.code == 0 insights_client.return_value.get_machine_id.assert_called_once() insights_client.return_value.get_registration_status.assert_called_once() insights_client.return_value.clear_local_registration.assert_not_called() insights_client.return_value.set_display_name.assert_not_called() get_scheduler.return_value.set_daily.assert_called_once()
def test_post_update_set_display_name_cli_register(insights_config, insights_client, get_scheduler): """ Client is and run with --display-name and --register Should set schedule and exit with code 0 Display name is not explicitly set here """ insights_config.return_value.load_all.return_value.register = True insights_config.return_value.load_all.return_value.reregister = True insights_client.return_value.get_registration_status = MagicMock(return_value=True) with raises(SystemExit) as exc_info: post_update() assert exc_info.value.code == 0 insights_client.return_value.get_machine_id.assert_called_once() insights_client.return_value.get_registration_status.assert_called_once() insights_client.return_value.clear_local_registration.assert_called_once() insights_client.return_value.set_display_name.assert_not_called() get_scheduler.return_value.set_daily.assert_called_once()