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 get_notifications(self, request): if is_telemetry_enabled() and is_in_grace_period() and not is_opt_out(): yield Notification( _("Statistics will be periodically sent to Shoop.io after 24 hours. Click here for more information."), title=_("Telemetry"), kind="info", url="shoop_admin:telemetry" )
def get_notifications(self, request): if is_telemetry_enabled() and is_in_grace_period( ) and not is_opt_out(): yield Notification(_( "Statistics will be periodically sent to Shoop.io after 24 hours. Click here for more information." ), title=_("Telemetry"), kind="info", url="shoop_admin:telemetry")
def get_context_data(self, **kwargs): context = super(TelemetryView, self).get_context_data(**kwargs) context.update({ "opt_in": not telemetry.is_opt_out(), "is_grace": telemetry.is_in_grace_period(), "last_submission_time": telemetry.get_last_submission_time(), "submission_data": telemetry.get_telemetry_data(request=self.request, indent=2), "title": _("Telemetry") }) return context