def test_optin_optout(rf): with override_settings(SHOOP_TELEMETRY_ENABLED=True): with patch.object(requests, "post", return_value=Response()) as requestor: _clear_telemetry_submission() assert not set_opt_out(False) # Not opted out assert not is_opt_out() with pytest.raises(TelemetryNotSent) as ei: try_send_telemetry(raise_on_error=True) # Still gracey assert ei.value.code == "grace" _backdate_installation_key() try_send_telemetry(max_age_hours=72) try_send_telemetry( max_age_hours=None) # Forcibly re-send for the hell of it with pytest.raises(TelemetryNotSent) as ei: try_send_telemetry( raise_on_error=True ) # Don't ignore last-send; shouldn't send anyway assert ei.value.code == "age" assert len(requestor.mock_calls) == 2 assert set_opt_out(True) assert is_opt_out() _clear_telemetry_submission() with pytest.raises(TelemetryNotSent) as ei: try_send_telemetry(max_age_hours=0, raise_on_error=True) assert ei.value.code == "optout" assert len(requestor.mock_calls) == 2
def test_optin_optout(rf): with override_settings(SHOOP_TELEMETRY_ENABLED=True): with patch.object(requests, "post", return_value=Response()) as requestor: _clear_telemetry_submission() assert not set_opt_out(False) # Not opted out assert not is_opt_out() with pytest.raises(TelemetryNotSent) as ei: try_send_telemetry(raise_on_error=True) # Still gracey assert ei.value.code == "grace" _backdate_installation_key() try_send_telemetry(max_age_hours=72) try_send_telemetry(max_age_hours=None) # Forcibly re-send for the hell of it with pytest.raises(TelemetryNotSent) as ei: try_send_telemetry(raise_on_error=True) # Don't ignore last-send; shouldn't send anyway assert ei.value.code == "age" assert len(requestor.mock_calls) == 2 assert set_opt_out(True) assert is_opt_out() _clear_telemetry_submission() with pytest.raises(TelemetryNotSent) as ei: try_send_telemetry(max_age_hours=0, raise_on_error=True) assert ei.value.code == "optout" assert len(requestor.mock_calls) == 2
def test_disable(rf): with override_settings(SHOOP_TELEMETRY_ENABLED=False): _clear_telemetry_submission() _backdate_installation_key() set_opt_out(False) with pytest.raises(TelemetryNotSent) as ei: try_send_telemetry(raise_on_error=True, max_age_hours=None) # Should re-send (if we weren't disabled) assert ei.value.code == "disabled"
def test_disable(rf): with override_settings(SHOOP_TELEMETRY_ENABLED=False): _clear_telemetry_submission() _backdate_installation_key() set_opt_out(False) with pytest.raises(TelemetryNotSent) as ei: try_send_telemetry( raise_on_error=True, max_age_hours=None) # Should re-send (if we weren't disabled) assert ei.value.code == "disabled"
def test_graceful_error(): def thrower(*args, **kwargs): raise ValueError("aaaagh") with override_settings(SHOOP_TELEMETRY_ENABLED=True): with patch.object(requests, "post", thrower) as requestor: _clear_telemetry_submission() _backdate_installation_key() set_opt_out(False) assert try_send_telemetry(raise_on_error=True).get("error")
def get(self, request, *args, **kwargs): try_send_telemetry(request) return super(DashboardView, self).get(request, *args, **kwargs)