Пример #1
0
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
Пример #2
0
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
Пример #3
0
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"
Пример #4
0
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")
Пример #5
0
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"
Пример #6
0
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")
Пример #7
0
 def post(self, request, *args, **kwargs):
     opt = request.POST.get("opt")
     if opt:
         telemetry.set_opt_out(opt == "out")
     return HttpResponseRedirect(request.path)
Пример #8
0
 def post(self, request, *args, **kwargs):
     opt = request.POST.get("opt")
     if opt:
         telemetry.set_opt_out(opt == "out")
     return HttpResponseRedirect(request.path)