Example #1
0
def test_optin_optout(rf, admin_user):
    with override_settings(SHUUP_TELEMETRY_ENABLED=True, DEBUG=True):
        with patch.object(requests, "post", return_value=MockResponse("test")) as requestor:
            _clear_telemetry_submission()
            assert not set_opt_out(False)  # Not opted out
            assert not is_opt_out()
            try_send_telemetry()
            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()
            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
Example #2
0
def test_optin_optout(rf, admin_user):
    with override_settings(SHUUP_TELEMETRY_ENABLED=True, DEBUG=True):
        with patch.object(requests, "post",
                          return_value=MockResponse("test")) as requestor:
            _clear_telemetry_submission()
            assert not set_opt_out(False)  # Not opted out
            assert not is_opt_out()
            try_send_telemetry()
            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()
            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
Example #3
0
def test_telemetry_wizard_pane(rf, admin_user):
    with override_settings(SHUUP_SETUP_WIZARD_PANE_SPEC=[
            "shuup.admin.modules.system.views.TelemetryWizardPane"
    ]):
        shop = get_default_shop()
        request = apply_request_middleware(rf.get("/"),
                                           user=admin_user,
                                           shop=shop)
        response = WizardView.as_view()(request)
        assert response.status_code == 200

        assert not is_opt_out()
        soup = BeautifulSoup(response.render().content)
        h2_elements = soup.find_all("h2")
        expected_h2_element_titles = [
            "Telemetry", "About Shuup Telemetry", "Telemetry Data",
            "Opt-in / opt-out", "Last Telemetry"
        ]
        assert len(h2_elements) == len(expected_h2_element_titles)
        for h2_element in h2_elements:
            assert h2_element.text.strip() in expected_h2_element_titles

        # By default installation should be opted in
        assert "Thank you for your valuable contribution." in soup.text

        # Opt out
        fields = _extract_fields(rf, admin_user)
        fields["telemetry-opt_in_telemetry"] = False

        request = apply_request_middleware(rf.post("/", data=fields),
                                           user=admin_user)
        response = WizardView.as_view()(request)
        assert response.status_code == 200  # Post seems to cause JSON response

        assert is_opt_out()

        # So let's re-get the telemetry page
        request = apply_request_middleware(rf.get("/"),
                                           user=admin_user,
                                           shop=shop)
        response = WizardView.as_view()(request)
        assert response.status_code == 200
        soup = BeautifulSoup(response.render().content)

        # Installation should be now opted out
        assert "Thank you for your valuable contribution." not in soup.text
        assert "You are currently opted out of Shuup telemetry." in soup.text
Example #4
0
 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 Shuup.com after 24 hours. Click here for more information."),
             title=_("Telemetry"),
             kind="info",
             url="shuup_admin:telemetry"
         )
Example #5
0
    def __init__(self, **kwargs):
        self.shop = kwargs.pop("shop")
        super(TelemetryWizardForm, self).__init__(**kwargs)

        self.fields["opt_in_telemetry"] = forms.BooleanField(
            label=_("Opt-in for telemetry"),
            required=False,
            initial=not telemetry.is_opt_out(),
            widget=forms.CheckboxInput())
Example #6
0
    def __init__(self, **kwargs):
        self.shop = kwargs.pop("shop")
        super(TelemetryWizardForm, self).__init__(**kwargs)

        self.fields["opt_in_telemetry"] = forms.BooleanField(
            label=_("Opt-in for telemetry"),
            required=False,
            initial=not telemetry.is_opt_out(),
            widget=forms.CheckboxInput()
        )
Example #7
0
 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
Example #8
0
 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
Example #9
0
def test_telemetry_wizard_pane(rf, admin_user):
    with override_settings(SHUUP_SETUP_WIZARD_PANE_SPEC=["shuup.admin.modules.system.views.TelemetryWizardPane"]):
        shop = get_default_shop()
        request = apply_request_middleware(rf.get("/"), user=admin_user, shop=shop)
        response = WizardView.as_view()(request)
        assert response.status_code == 200

        assert not is_opt_out()
        soup = BeautifulSoup(response.render().content)
        h2_elements = soup.find_all("h2")
        expected_h2_element_titles = [
            "Telemetry",
            "About Shuup Telemetry",
            "Telemetry Data",
            "Opt-in / opt-out",
            "Last Telemetry"
        ]
        assert len(h2_elements) == len(expected_h2_element_titles)
        for h2_element in h2_elements:
            assert h2_element.text.strip() in expected_h2_element_titles

        # By default installation should be opted in
        assert "Thank you for your valuable contribution." in soup.text

        # Opt out
        fields = _extract_fields(rf, admin_user)
        fields["telemetry-opt_in_telemetry"] = False

        request = apply_request_middleware(rf.post("/", data=fields), user=admin_user)
        response = WizardView.as_view()(request)
        assert response.status_code == 200  # Post seems to cause JSON response

        assert is_opt_out()

        # So let's re-get the telemetry page
        request = apply_request_middleware(rf.get("/"), user=admin_user, shop=shop)
        response = WizardView.as_view()(request)
        assert response.status_code == 200
        soup = BeautifulSoup(response.render().content)

        # Installation should be now opted out
        assert "Thank you for your valuable contribution." not in soup.text
        assert "You are currently opted out of Shuup telemetry." in soup.text
Example #10
0
    def get_form_defs(self):
        form_defs = []

        context = {
            "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")
        }
        form_defs.append(
            TemplatedWizardFormDef(
                name=self.identifier,
                template_name="shuup/admin/system/telemetry_wizard.jinja",
                form_class=TelemetryWizardForm,
                context=context,
                kwargs={"shop": self.object}
            )
        )
        return form_defs
Example #11
0
    def get_form_defs(self):
        form_defs = []

        context = {
            "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")
        }
        form_defs.append(
            TemplatedWizardFormDef(
                name=self.identifier,
                template_name="shuup/admin/system/telemetry_wizard.jinja",
                form_class=TelemetryWizardForm,
                context=context,
                kwargs={"shop": self.object}
            )
        )
        return form_defs