django.conf.settings.OPENIDC_EMAIL_HEADER - python examples

Here are the examples of the python api django.conf.settings.OPENIDC_EMAIL_HEADER taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

50 Examples 7

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_redirects_on_failure(self):
        user_email = "[email protected]"
        original_status = Experiment.STATUS_DRAFT
        experiment = ExperimentFactory.create_with_status(original_status)

        response = self.client.post(
            reverse("experiments-status-update", kwargs={"slug": experiment.slug}),
            {"status": Experiment.STATUS_COMPLETE},
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertRedirects(
            response,
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            fetch_redirect_response=False,
        )
        updated_experiment = Experiment.objects.get(slug=experiment.slug)
        self.astertEqual(updated_experiment.status, original_status)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_valid_recipe_id_updates_experiment_status(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_SHIP)
        normandy_id = 123

        response = self.client.post(
            reverse("experiments-normandy-update", kwargs={"slug": experiment.slug}),
            {"normandy_id": normandy_id},
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertRedirects(
            response,
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            fetch_redirect_response=False,
        )

        experiment = Experiment.objects.get(id=experiment.id)
        self.astertEqual(experiment.normandy_id, normandy_id)
        self.astertEqual(experiment.status, Experiment.STATUS_ACCEPTED)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_redirects_to_detail_page_when_form_is_invalid(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT)

        section = "invalid section"
        text = ""

        response = self.client.post(
            reverse("experiments-comment-create", kwargs={"slug": experiment.slug}),
            {"experiment": experiment.id, "section": section, "text": text},
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertRedirects(
            response,
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            fetch_redirect_response=False,
        )

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_flips_archive_bool_and_redirects(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create(archived=False)

        response = self.client.post(
            reverse("experiments-archive-update", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertRedirects(
            response,
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            fetch_redirect_response=False,
        )

        experiment = Experiment.objects.get(id=experiment.id)

        self.astertTrue(self.mock_tasks_update_bug_resolution.delay.astert_called_once)
        self.astertTrue(experiment.archived)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_renders_correctly(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT)

        response = self.client.get(
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)
        self.astertTemplateUsed(response, "experiments/detail_draft.html")
        self.astertTemplateUsed(response, "experiments/detail_base.html")

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_includes_normandy_id_form_in_context(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_SHIP)
        response = self.client.get(
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertTrue(
            isinstance(response.context[0]["normandy_id_form"], NormandyIdForm)
        )

3 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_get_experiment_returns_experiment_info(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_variants()

        response = self.client.get(
            reverse("experiments-api-detail", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)
        json_data = json.loads(response.content)
        serialized_experiment = ExperimentSerializer(experiment).data
        self.astertEqual(serialized_experiment, json_data)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_includes_bound_normandy_id_form_if_GET_param_set(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_SHIP)
        bad_normandy_id = "abc"
        detail_url = reverse("experiments-detail", kwargs={"slug": experiment.slug})
        response = self.client.get(
            f"{detail_url}?normandy_id={bad_normandy_id}",
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        normandy_form = response.context[0]["normandy_id_form"]
        self.astertTrue(isinstance(normandy_form, NormandyIdForm))
        self.astertEqual(normandy_form.data["normandy_id"], bad_normandy_id)
        self.astertFalse(normandy_form.is_valid())

3 View Complete Implementation : test_middleware.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_user_created_with_correct_email_from_header(self):
        user_email = "[email protected]"

        request = mock.Mock()
        request.META = {settings.OPENIDC_EMAIL_HEADER: user_email}

        User = get_user_model()

        self.astertEqual(User.objects.all().count(), 0)

        with self.settings(OPENIDC_AUTH_WHITELIST=[]):
            response = self.middleware(request)

        self.astertEqual(response, self.response)
        self.astertEqual(User.objects.all().count(), 1)

        self.astertEqual(request.user.email, user_email)
        self.astertFalse(request.user.is_staff)

3 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_get_experiment_recipe_returns_recipe_info(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_variants(
            normandy_slug="a-normandy-slug"
        )

        response = self.client.get(
            reverse("experiments-api-recipe", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)
        json_data = json.loads(response.content)
        serialized_experiment = ExperimentRecipeSerializer(experiment).data
        self.astertEqual(serialized_experiment, json_data)

3 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_patch_to_view_returns_clone_name_and_url(self):
        experiment = ExperimentFactory.create(
            name="great experiment", slug="great-experiment"
        )
        user_email = "[email protected]"

        data = json.dumps({"name": "best experiment"})

        response = self.client.patch(
            reverse("experiments-api-clone", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)
        self.astertEqual(response.json()["name"], "best experiment")
        self.astertEqual(response.json()["clone_url"], "/experiments/best-experiment/")

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_renders_locales_correctly(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT)
        experiment.locales.add(LocaleFactory(code="yy", name="Why"))
        experiment.locales.add(LocaleFactory(code="xx", name="Xess"))
        response = self.client.get(
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertEqual(response.status_code, 200)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_page_loads(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create()
        response = self.client.get(
            reverse("experiments-design-update", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertEqual(response.status_code, 200)

3 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_get_design_pref_returns_design_info(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_variants(type="pref")

        response = self.client.get(
            reverse("experiments-design-pref", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)
        json_data = json.loads(response.content)
        serialized_experiment = ExperimentDesignPrefSerializer(experiment).data
        self.astertEqual(serialized_experiment, json_data)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_google_yyyytics_omitted_if_setting_false(self):
        with self.settings(USE_GOOGLE_yyyYTICS=False):
            headers = {settings.OPENIDC_EMAIL_HEADER: "[email protected]"}
            response = self.client.get(reverse("home"), **headers)
            self.astertEqual(response.status_code, 200)
            html = response.content.decode("utf-8")
            # Note the 'not'!
            self.astertNotIn("www.googletagmanager.com", html)

3 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_get_design_multi_pref_returns_design_info(self):

        response = self.client.get(
            reverse(
                "experiments-design-multi-pref", kwargs={"slug": self.experiment.slug}
            ),
            **{settings.OPENIDC_EMAIL_HEADER: self.user_email},
        )

        self.astertEqual(response.status_code, 200)
        json_data = json.loads(response.content)
        serialized_experiment = ExperimentDesignMultiPrefSerializer(self.experiment).data
        self.astertEqual(serialized_experiment, json_data)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_updates_status_and_redirects(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT)

        new_status = experiment.STATUS_REVIEW

        response = self.client.post(
            reverse("experiments-status-update", kwargs={"slug": experiment.slug}),
            {"status": new_status},
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertRedirects(
            response,
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            fetch_redirect_response=False,
        )
        updated_experiment = Experiment.objects.get(slug=experiment.slug)
        self.astertEqual(updated_experiment.status, new_status)

3 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_get_design_addon_returns_design_info(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_variants(
            type=ExperimentConstants.TYPE_ADDON
        )

        response = self.client.get(
            reverse("experiments-design-addon", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)
        json_data = json.loads(response.content)

        serialized_experiment = ExperimentDesignAddonSerializer(experiment).data
        self.astertEqual(serialized_experiment, json_data)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_google_yyyytics_included_if_setting_true(self):
        with self.settings(USE_GOOGLE_yyyYTICS=True):
            headers = {settings.OPENIDC_EMAIL_HEADER: "[email protected]"}
            response = self.client.get(reverse("home"), **headers)
            self.astertEqual(response.status_code, 200)
            html = response.content.decode("utf-8")
            self.astertIn("www.googletagmanager.com", html)

3 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_get_design_addon_returns_design_info(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_variants(
            type=ExperimentConstants.TYPE_GENERIC
        )

        response = self.client.get(
            reverse("experiments-design-generic", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)
        json_data = json.loads(response.content)

        serialized_experiment = ExperimentDesignGenericSerializer(experiment).data
        self.astertEqual(serialized_experiment, json_data)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_flips_subscribed_bool_and_redirects(self):
        user = UserFactory()
        experiment = ExperimentFactory.create()
        self.astertFalse(user in experiment.subscribers.all())

        response = self.client.post(
            reverse("experiments-subscribed-update", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user.email},
        )

        self.astertRedirects(
            response,
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            fetch_redirect_response=False,
        )

        experiment = Experiment.objects.get(id=experiment.id)
        self.astertTrue(user in experiment.subscribers.all())

3 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_raises_409_if_email_already_sent(self):
        experiment = ExperimentFactory.create_with_variants(
            review_intent_to_ship=True, status=Experiment.STATUS_REVIEW
        )

        response = self.client.put(
            reverse(
                "experiments-api-send-intent-to-ship-email",
                kwargs={"slug": experiment.slug},
            ),
            **{settings.OPENIDC_EMAIL_HEADER: "[email protected]"},
        )

        self.astertEqual(response.status_code, 409)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_invalid_recipe_id_redirects_to_detail(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_SHIP)
        normandy_id = "abc"

        response = self.client.post(
            reverse("experiments-normandy-update", kwargs={"slug": experiment.slug}),
            {"normandy_id": normandy_id},
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        detail_url = reverse("experiments-detail", kwargs={"slug": experiment.slug})
        self.astertRedirects(
            response,
            f"{detail_url}?normandy_id={normandy_id}",
            fetch_redirect_response=False,
        )

3 View Complete Implementation : test_admin.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_returns_200(self):
        user = UserFactory()
        user.is_staff = True
        user.is_superuser = True
        user.save()

        experiment = ExperimentFactory.create_with_status(ExperimentFactory.STATUS_DRAFT)
        response = self.client.get(
            reverse(
                "admin:experiments_experiment_change", kwargs={"object_id": experiment.id}
            ),
            **{settings.OPENIDC_EMAIL_HEADER: user.email},
        )
        self.astertEqual(response.status_code, 200)

3 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_renders_countries_correctly(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT)
        experiment.countries.add(CountryFactory(code="YY", name="Wazoo"))
        experiment.countries.add(CountryFactory(code="XX", name="Xanadu"))
        response = self.client.get(
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertEqual(response.status_code, 200)

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_saves_design_info(self):
        experiment = ExperimentFactory.create(
            name="great experiment",
            slug="great-experiment",
            type=ExperimentConstants.TYPE_GENERIC,
        )
        user_email = "[email protected]"

        variant_1 = {
            "name": "Terrific branch",
            "ratio": 50,
            "description": "Very terrific branch.",
            "is_control": True,
        }
        variant_2 = {
            "name": "Great branch",
            "ratio": 50,
            "description": "Very great branch.",
            "is_control": False,
        }

        data = json.dumps(
            {
                "type": ExperimentConstants.TYPE_GENERIC,
                "design": "design 1",
                "variants": [variant_1, variant_2],
            }
        )

        response = self.client.put(
            reverse("experiments-design-generic", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_returns_400_on_missing_required_field(self):
        experiment = ExperimentFactory.create(
            name="great experiment",
            slug="great-experiment",
            type=ExperimentConstants.TYPE_ADDON,
        )
        user_email = "[email protected]"

        variant_1 = {
            "name": "Terrific branch",
            "ratio": 50,
            "description": "Very terrific branch.",
            "is_control": True,
        }
        variant_2 = {
            "name": "Great branch",
            "ratio": 50,
            "description": "Very great branch.",
            "is_control": False,
        }

        data = json.dumps(
            {
                "type": ExperimentConstants.TYPE_ADDON,
                "addon_experiment_id": "1234",
                "variants": [variant_1, variant_2],
            }
        )

        response = self.client.put(
            reverse("experiments-design-addon", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 400)
        self.astertEqual(
            response.json()["addon_release_url"], ["This field is required."]
        )

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_design_is_optional(self):
        experiment = ExperimentFactory.create(
            name="great experiment",
            slug="great-experiment",
            type=ExperimentConstants.TYPE_GENERIC,
        )
        user_email = "[email protected]"

        variant_1 = {
            "name": "Terrific branch",
            "ratio": 50,
            "description": "Very terrific branch.",
            "is_control": True,
        }
        variant_2 = {
            "name": "Great branch",
            "ratio": 50,
            "description": "Very great branch.",
            "is_control": False,
        }

        data = json.dumps(
            {"type": ExperimentConstants.TYPE_GENERIC, "variants": [variant_1, variant_2]}
        )

        response = self.client.put(
            reverse("experiments-design-generic", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)

0 View Complete Implementation : test_filtersets.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_list_filters_by_search_text(self):
        user_email = "[email protected]"

        exp_1 = ExperimentFactory.create_with_status(
            random.choice(Experiment.STATUS_CHOICES)[0],
            name="Experiment One Cat",
            short_description="",
            slug="exp-1",
            related_work="",
            addon_experiment_id="1",
            pref_key="",
            public_name="",
            public_description="",
            objectives="",
            yyyysis="",
            engineering_owner="",
            bugzilla_id="4",
            normandy_slug="",
        )

        exp_2 = ExperimentFactory.create_with_status(
            random.choice(Experiment.STATUS_CHOICES)[0],
            name="Experiment Two Cat",
            short_description="",
            slug="exp-2",
            related_work="",
            addon_experiment_id="2",
            pref_key="",
            public_name="",
            public_description="",
            objectives="",
            yyyysis="",
            engineering_owner="",
            bugzilla_id="5",
            normandy_slug="",
        )

        exp_3 = ExperimentFactory.create_with_status(
            random.choice(Experiment.STATUS_CHOICES)[0],
            name="Experiment Three Dog",
            short_description="",
            slug="exp-3",
            related_work="",
            addon_experiment_id="3",
            pref_key="",
            public_name="",
            public_description="",
            objectives="",
            yyyysis="",
            engineering_owner="",
            bugzilla_id="6",
            normandy_slug="",
        )

        first_response_context = self.client.get(
            "{url}?{params}".format(
                url=reverse("home"), params=urlencode({"search": "Cat"})
            ),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        ).context[0]

        second_response_context = self.client.get(
            "{url}?{params}".format(
                url=reverse("home"), params=urlencode({"search": "Dog"})
            ),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        ).context[0]

        self.astertEqual(set(first_response_context["experiments"]), set([exp_1, exp_2]))
        self.astertEqual(set(second_response_context["experiments"]), set([exp_3]))

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_list_view_shows_all_including_archived(self):
        user_email = "[email protected]"

        # Archived experiment is included
        ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT, archived=True)

        for i in range(3):
            ExperimentFactory.create_with_status(
                random.choice(Experiment.STATUS_CHOICES)[0]
            )

        experiments = Experiment.objects.all()

        response = self.client.get(
            "{url}?{params}".format(
                url=reverse("home"), params=urlencode({"archived": True})
            ),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        context = response.context[0]
        self.astertEqual(response.status_code, 200)
        self.astertEqual(set(context["experiments"]), set(experiments))

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_list_view_filters_and_orders_experiments(self):
        user_email = "[email protected]"

        ordering = "latest_change"
        filtered_channel = Experiment.CHANNEL_CHOICES[1][0]
        filtered_owner = UserFactory.create()
        filtered_status = Experiment.STATUS_DRAFT
        filtered_types = (Experiment.TYPE_PREF, Experiment.TYPE_GENERIC)
        filtered_version = Experiment.VERSION_CHOICES[1][0]

        for i in range(3):
            for filtered_type in filtered_types:
                ExperimentFactory.create_with_status(
                    firefox_channel=filtered_channel,
                    firefox_min_version=filtered_version,
                    owner=filtered_owner,
                    target_status=filtered_status,
                    type=filtered_type,
                )

        for i in range(3):
            ExperimentFactory.create_with_status(
                random.choice(Experiment.STATUS_CHOICES)[0]
            )

        filtered_ordered_experiments = Experiment.objects.filter(
            firefox_channel=filtered_channel,
            firefox_min_version=filtered_version,
            owner=filtered_owner,
            status=filtered_status,
            type__in=filtered_types,
        ).order_by(ordering)

        response = self.client.get(
            "{url}?{params}".format(
                url=reverse("home"),
                params=urlencode(
                    {
                        "firefox_channel": filtered_channel,
                        "firefox_version": filtered_version,
                        "ordering": ordering,
                        "owner": filtered_owner.id,
                        "status": filtered_status,
                        "type": filtered_types,
                    },
                    True,
                ),
            ),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        context = response.context[0]
        self.astertEqual(response.status_code, 200)
        self.astertEqual(list(context["experiments"]), list(filtered_ordered_experiments))

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_list_view_orders_experiments_firefox_channel_sort(self):
        user_email = "[email protected]"
        ordering = "firefox_channel_sort"
        channels = [
            Experiment.CHANNEL_RELEASE,
            Experiment.CHANNEL_NIGHTLY,
            Experiment.CHANNEL_BETA,
            "",
        ]
        for channel in channels:
            ExperimentFactory.create(firefox_channel=channel)

        response = self.client.get(
            "{url}?{params}".format(
                url=reverse("home"), params=urlencode({"ordering": ordering})
            ),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        context = response.context[0]
        self.astertEqual(
            list(exp.firefox_channel for exp in context["experiments"]),
            [
                "",
                Experiment.CHANNEL_NIGHTLY,
                Experiment.CHANNEL_BETA,
                Experiment.CHANNEL_RELEASE,
            ],
        )

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_list_view_lists_experiments_with_default_order_no_archived(self):
        user_email = "[email protected]"

        # Archived experiment is ommitted
        ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT, archived=True)

        for i in range(3):
            ExperimentFactory.create_with_status(
                random.choice(Experiment.STATUS_CHOICES)[0]
            )

        experiments = (
            Experiment.objects.all()
            .filter(archived=False)
            .order_by(ExperimentOrderingForm.ORDERING_CHOICES[0][0])
        )

        response = self.client.get(
            reverse("home"), **{settings.OPENIDC_EMAIL_HEADER: user_email}
        )

        context = response.context[0]
        self.astertEqual(response.status_code, 200)
        self.astertEqual(list(context["experiments"]), list(experiments))

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_saves_experiment(self):
        user = UserFactory.create()
        user_email = user.email
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_DRAFT, proposed_enrollment=1, proposed_duration=2
        )

        bug_url = "https://bugzilla.mozilla.org/show_bug.cgi?id=123"
        data = {
            "action": "continue",
            "type": Experiment.TYPE_PREF,
            "name": "A new name!",
            "short_description": "A new description!",
            "public_name": "Public Name",
            "public_description": "Public Description",
            "data_science_bugzilla_url": bug_url,
            "feature_bugzilla_url": bug_url,
            "related_work": "Designs: https://www.example.com/myproject/",
            "owner": user.id,
            "yyyysis_owner": user.id,
        }

        response = self.client.post(
            reverse("experiments-overview-update", kwargs={"slug": experiment.slug}),
            data,
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertEqual(response.status_code, 302)

        experiment = Experiment.objects.get()
        self.astertEqual(experiment.name, data["name"])
        self.astertEqual(experiment.short_description, data["short_description"])
        self.astertEqual(experiment.yyyysis_owner, user)

        self.astertEqual(experiment.changes.count(), 2)

        change = experiment.changes.latest()

        self.astertEqual(change.changed_by, user)
        self.astertEqual(change.old_status, experiment.STATUS_DRAFT)
        self.astertEqual(change.new_status, experiment.STATUS_DRAFT)

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_creates_experiment(self):
        user = UserFactory.create()
        user_email = user.email

        bug_url = "https://bugzilla.mozilla.org/show_bug.cgi?id=123"
        data = {
            "action": "continue",
            "type": Experiment.TYPE_PREF,
            "name": "A new experiment!",
            "short_description": "Let us learn new things",
            "public_name": "Public Name",
            "public_description": "Public Description",
            "data_science_bugzilla_url": bug_url,
            "feature_bugzilla_url": bug_url,
            "related_work": "Designs: https://www.example.com/myproject/",
            "owner": user.id,
            "yyyysis_owner": user.id,
        }

        with self.settings(BUGZILLA_HOST="https://bugzilla.mozilla.org"):
            response = self.client.post(
                reverse("experiments-create"),
                data,
                **{settings.OPENIDC_EMAIL_HEADER: user_email},
            )

        self.astertEqual(response.status_code, 302)

        experiment = Experiment.objects.get()
        self.astertEqual(experiment.status, experiment.STATUS_DRAFT)
        self.astertEqual(experiment.name, data["name"])

        self.astertEqual(experiment.changes.count(), 1)

        change = experiment.changes.get()

        self.astertEqual(change.changed_by, user)
        self.astertEqual(change.old_status, None)
        self.astertEqual(change.new_status, experiment.STATUS_DRAFT)

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_saves_experiment(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_DRAFT, proposed_enrollment=1, proposed_duration=2
        )
        locale = LocaleFactory()
        country = CountryFactory()

        new_start_date = timezone.now().date() + datetime.timedelta(
            days=random.randint(1, 100)
        )
        new_enrollment = experiment.proposed_enrollment + 1
        new_duration = experiment.proposed_duration + 1

        data = {
            "action": "continue",
            "proposed_start_date": new_start_date,
            "proposed_enrollment": new_enrollment,
            "proposed_duration": new_duration,
            "population_percent": "11",
            "firefox_min_version": Experiment.VERSION_CHOICES[-2][0],
            "firefox_max_version": Experiment.VERSION_CHOICES[-1][0],
            "firefox_channel": Experiment.CHANNEL_NIGHTLY,
            "client_matching": "New matching!",
            "platform": Experiment.PLATFORM_WINDOWS,
            "locales": [locale.code],
            "countries": [country.code],
        }

        response = self.client.post(
            reverse("experiments-timeline-pop-update", kwargs={"slug": experiment.slug}),
            data,
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertEqual(response.status_code, 302)

        experiment = Experiment.objects.get()

        self.astertEqual(experiment.proposed_start_date, new_start_date)
        self.astertEqual(experiment.proposed_enrollment, new_enrollment)
        self.astertEqual(experiment.proposed_duration, new_duration)
        self.astertEqual(
            experiment.population_percent, decimal.Decimal(data["population_percent"])
        )
        self.astertEqual(experiment.firefox_min_version, data["firefox_min_version"])
        self.astertEqual(experiment.firefox_max_version, data["firefox_max_version"])

        self.astertEqual(experiment.firefox_channel, data["firefox_channel"])
        self.astertEqual(experiment.platform, data["platform"])

        self.astertTrue(locale in experiment.locales.all())

        self.astertTrue(country in experiment.countries.all())

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_saves_experiment(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT)

        data = {
            "action": "continue",
            "objectives": "Some new objectives!",
            "yyyysis": "Some new yyyysis!",
            "survey_required": False,
        }

        response = self.client.post(
            reverse("experiments-objectives-update", kwargs={"slug": experiment.slug}),
            data,
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertEqual(response.status_code, 302)

        experiment = Experiment.objects.get()
        self.astertEqual(experiment.objectives, data["objectives"])
        self.astertEqual(experiment.yyyysis, data["yyyysis"])
        self.astertFalse(experiment.survey_required, data["survey_required"])

        self.astertEqual(experiment.changes.count(), 2)

        change = experiment.changes.latest()

        self.astertEqual(change.changed_by.email, user_email)
        self.astertEqual(change.old_status, experiment.STATUS_DRAFT)
        self.astertEqual(change.new_status, experiment.STATUS_DRAFT)

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_saves_experiment(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT)

        data = {
            "risk_internal_only": True,
            "risk_partner_related": True,
            "risk_brand": True,
            "risk_fast_shipped": True,
            "risk_confidential": True,
            "risk_release_population": True,
            "risk_revenue": True,
            "risk_data_category": True,
            "risk_external_team_impact": True,
            "risk_telemetry_data": True,
            "risk_ux": True,
            "risk_security": True,
            "risk_revision": True,
            "risk_technical": True,
            "risk_technical_description": "It's complicated",
            "risks": "There are some risks",
            "testing": "Always be sure to test!",
            "test_builds": "Latest Build",
            "qa_status": "Green",
        }

        response = self.client.post(
            reverse("experiments-risks-update", kwargs={"slug": experiment.slug}),
            data,
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertEqual(response.status_code, 302)

        experiment = Experiment.objects.get()

        self.astertTrue(experiment.risk_internal_only)
        self.astertTrue(experiment.risk_partner_related)
        self.astertTrue(experiment.risk_brand)
        self.astertTrue(experiment.risk_fast_shipped)
        self.astertTrue(experiment.risk_confidential)
        self.astertTrue(experiment.risk_release_population)
        self.astertTrue(experiment.risk_technical)
        self.astertEqual(
            experiment.risk_technical_description, data["risk_technical_description"]
        )
        self.astertEqual(experiment.risks, data["risks"])
        self.astertEqual(experiment.testing, data["testing"])
        self.astertEqual(experiment.test_builds, data["test_builds"])
        self.astertEqual(experiment.qa_status, data["qa_status"])

        self.astertEqual(experiment.changes.count(), 2)

        change = experiment.changes.latest()

        self.astertEqual(change.changed_by.email, user_email)
        self.astertEqual(change.old_status, experiment.STATUS_DRAFT)
        self.astertEqual(change.new_status, experiment.STATUS_DRAFT)

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_saves_experiment(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_COMPLETE)

        data = {
            "results_url": "https://example.com",
            "results_lessons_learned": "Many lessons were learned.",
        }

        response = self.client.post(
            reverse("experiments-results-update", kwargs={"slug": experiment.slug}),
            data,
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertEqual(response.status_code, 302)

        experiment = Experiment.objects.get()

        self.astertEqual(experiment.results_url, "https://example.com")
        self.astertEqual(experiment.results_lessons_learned, "Many lessons were learned.")

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_updates_reviews_and_redirects(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_REVIEW)

        data = {
            "review_science": True,
            "review_engineering": True,
            "review_qa_requested": True,
            "review_intent_to_ship": True,
            "review_bugzilla": True,
            "review_advisory": True,
            "review_legal": True,
            "review_ux": True,
            "review_security": True,
            "review_vp": True,
            "review_data_steward": True,
            "review_comms": True,
            "review_impacted_teams": True,
        }

        response = self.client.post(
            reverse("experiments-review-update", kwargs={"slug": experiment.slug}),
            data,
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.astertRedirects(
            response,
            reverse("experiments-detail", kwargs={"slug": experiment.slug}),
            fetch_redirect_response=False,
        )

        experiment = Experiment.objects.get()

        self.astertTrue(experiment.review_science)
        self.astertTrue(experiment.review_legal)
        self.astertTrue(experiment.review_ux)
        self.astertTrue(experiment.review_security)

        change = experiment.changes.latest()

        self.astertEqual(change.changed_by.email, user_email)
        self.astertEqual(change.old_status, experiment.STATUS_REVIEW)
        self.astertEqual(change.new_status, experiment.STATUS_REVIEW)

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_view_creates_comment_redirects_to_detail_page(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT)

        section = experiment.SECTION_OBJECTIVES
        text = "Hello!"

        response = self.client.post(
            reverse("experiments-comment-create", kwargs={"slug": experiment.slug}),
            {"experiment": experiment.id, "section": section, "text": text},
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertRedirects(
            response,
            "{url}#{section}-comments".format(
                url=reverse("experiments-detail", kwargs={"slug": experiment.slug}),
                section=section,
            ),
            fetch_redirect_response=False,
        )
        comment = experiment.comments.sections[section][0]
        self.astertEqual(comment.text, text)
        self.astertEqual(comment.created_by.email, user_email)

0 View Complete Implementation : test_middleware.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_dev_user_is_super_staff_user_when_debug_true(self):
        dev_email = "[email protected]"

        request = mock.Mock()
        request.META = {settings.OPENIDC_EMAIL_HEADER: dev_email}

        User = get_user_model()

        self.astertEqual(User.objects.all().count(), 0)

        with self.settings(
            OPENIDC_AUTH_WHITELIST=[], DEBUG=True, DEV_USER_EMAIL="[email protected]"
        ):
            response = self.middleware(request)

        self.astertEqual(response, self.response)
        self.astertEqual(User.objects.all().count(), 1)

        self.astertEqual(request.user.email, dev_email)
        self.astertTrue(request.user.is_staff)
        self.astertTrue(request.user.is_superuser)

0 View Complete Implementation : test_middleware.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_dev_user_is_not_super_staff_user_when_debug_false(self):
        dev_email = "[email protected]"

        request = mock.Mock()
        request.META = {settings.OPENIDC_EMAIL_HEADER: dev_email}

        User = get_user_model()

        self.astertEqual(User.objects.all().count(), 0)

        with self.settings(
            OPENIDC_AUTH_WHITELIST=[], DEBUG=False, DEV_USER_EMAIL="[email protected]"
        ):
            response = self.middleware(request)

        self.astertEqual(response, self.response)
        self.astertEqual(User.objects.all().count(), 1)

        self.astertEqual(request.user.email, dev_email)
        self.astertFalse(request.user.is_staff)
        self.astertFalse(request.user.is_superuser)

0 View Complete Implementation : test_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_invalid_other_recipe_ids_redirects_to_detail(self):
        user_email = "[email protected]"
        experiment = ExperimentFactory.create_with_status(Experiment.STATUS_SHIP)
        normandy_id = "432"
        other_normandy_ids = "abc"

        response = self.client.post(
            reverse("experiments-normandy-update", kwargs={"slug": experiment.slug}),
            {"normandy_id": normandy_id, "other_normandy_ids": other_normandy_ids},
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        detail_url = reverse("experiments-detail", kwargs={"slug": experiment.slug})

        self.astertRedirects(
            response,
            f"{detail_url}?normandy_id={normandy_id}"
            f"&other_normandy_ids={other_normandy_ids}",
            fetch_redirect_response=False,
        )

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_sends_email(self):
        user_email = "[email protected]"

        experiment = ExperimentFactory.create_with_variants(
            review_intent_to_ship=False, status=Experiment.STATUS_REVIEW
        )
        old_outbox_len = len(mail.outbox)

        response = self.client.put(
            reverse(
                "experiments-api-send-intent-to-ship-email",
                kwargs={"slug": experiment.slug},
            ),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)

        experiment = Experiment.objects.get(pk=experiment.pk)
        self.astertEqual(experiment.review_intent_to_ship, True)
        self.astertEqual(len(mail.outbox), old_outbox_len + 1)

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_saves_design_info(self):
        experiment = ExperimentFactory.create(
            name="great experiment", slug="great-experiment"
        )
        user_email = "[email protected]"

        variant_1 = {
            "name": "Terrific branch",
            "ratio": 50,
            "description": "Very terrific branch.",
            "is_control": True,
            "value": "value 1",
        }
        variant_2 = {
            "name": "Great branch",
            "ratio": 50,
            "description": "Very great branch.",
            "is_control": False,
            "value": "value 2",
        }

        data = json.dumps(
            {
                "type": "pref",
                "is_multi_pref": False,
                "pref_key": "pref 1",
                "pref_branch": "default",
                "pref_type": "string",
                "variants": [variant_1, variant_2],
            }
        )

        response = self.client.put(
            reverse("experiments-design-pref", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_returns_400_on_missing_required_field(self):
        experiment = ExperimentFactory.create(
            name="great experiment", slug="great-experiment"
        )
        user_email = "[email protected]"

        variant_1 = {
            "name": "Terrific branch",
            "ratio": 50,
            "description": "Very terrific branch.",
            "is_control": True,
            "value": "value 1",
        }
        variant_2 = {
            "name": "Great branch",
            "ratio": 50,
            "description": "Very great branch.",
            "is_control": False,
            "value": "value 2",
        }

        data = json.dumps(
            {
                "type": "pref",
                "pref_branch": "default",
                "pref_type": "string",
                "variants": [variant_1, variant_2],
            }
        )

        response = self.client.put(
            reverse("experiments-design-pref", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 400)
        self.astertEqual(response.json()["pref_key"], ["This field is required."])

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_save_design_info(self):
        experiment = ExperimentFactory.create(
            name="an experiment", slug="an-experiment", type="pref"
        )
        variant = {
            "name": "variant1",
            "ratio": 100,
            "description": "variant1 description",
            "is_control": True,
            "preferences": [
                {
                    "pref_name": "the name is pref name",
                    "pref_value": "it's a string value",
                    "pref_type": "string",
                    "pref_branch": "default",
                }
            ],
        }
        data = json.dumps(
            {"type": Experiment.TYPE_PREF, "is_multi_pref": True, "variants": [variant]}
        )

        response = self.client.put(
            reverse("experiments-design-multi-pref", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: self.user_email},
        )

        self.astertEqual(response.status_code, 200)

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_returns_400_for_dup_pref_name(self):
        experiment = ExperimentFactory.create(
            name="an experiment", slug="an-experiment", type="pref"
        )
        variant = {
            "name": "variant1",
            "ratio": 100,
            "description": "variant1 description",
            "is_control": True,
            "preferences": [
                {
                    "pref_name": "the name is pref name",
                    "pref_value": "it's a string value",
                    "pref_type": "string",
                    "pref_branch": "default",
                },
                {
                    "pref_name": "the name is pref name",
                    "pref_value": "it's another string value",
                    "pref_type": "string",
                    "pref_branch": "default",
                },
            ],
        }
        data = json.dumps({"variants": [variant]})

        response = self.client.put(
            reverse("experiments-design-multi-pref", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: self.user_email},
        )

        self.astertEqual(response.status_code, 400)

0 View Complete Implementation : test_api_views.py
Copyright Mozilla Public License 2.0
Author : mozilla
    def test_put_to_view_saves_design_info(self):
        experiment = ExperimentFactory.create(
            name="great experiment",
            slug="great-experiment",
            type=ExperimentConstants.TYPE_ADDON,
        )
        user_email = "[email protected]"

        variant_1 = {
            "name": "Terrific branch",
            "ratio": 50,
            "description": "Very terrific branch.",
            "is_control": True,
        }
        variant_2 = {
            "name": "Great branch",
            "ratio": 50,
            "description": "Very great branch.",
            "is_control": False,
        }

        data = json.dumps(
            {
                "type": ExperimentConstants.TYPE_ADDON,
                "addon_experiment_id": "1234",
                "is_branched_addon": False,
                "addon_release_url": "http://www.example.com",
                "variants": [variant_1, variant_2],
            }
        )

        response = self.client.put(
            reverse("experiments-design-addon", kwargs={"slug": experiment.slug}),
            data,
            content_type="application/json",
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.astertEqual(response.status_code, 200)