예제 #1
0
    def test_sends_emails_for_live_experiments_past_proposed_enrollment_end_date(
        self,
    ):
        experiment1 = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_APPROVE,
            proposed_enrollment=10,
        )
        experiment2 = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_APPROVE,
            proposed_enrollment=10,
        )
        experiment3 = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_APPROVE,
            proposed_enrollment=10,
        )
        experiment3.changes.filter(
            old_status=NimbusExperiment.Status.DRAFT,
            new_status=NimbusExperiment.Status.LIVE,
        ).update(changed_on=datetime.datetime.now() - datetime.timedelta(days=10))

        tasks.nimbus_send_end_enrollment_email()

        self.assertEqual(experiment1.emails.count(), 0)
        self.assertEqual(experiment2.emails.count(), 0)

        self.assertTrue(
            experiment3.emails.filter(
                type=NimbusExperiment.EmailType.ENROLLMENT_END
            ).exists()
        )
        self.assertEqual(experiment3.emails.count(), 1)
        self.assertEqual(len(mail.outbox), 1)
예제 #2
0
    def test_experiments_by_status(self):
        user_email = "*****@*****.**"
        draft_exp = NimbusExperimentFactory.create_with_status(
            NimbusExperiment.Status.DRAFT)
        NimbusExperimentFactory.create_with_status(
            NimbusExperiment.Status.ACCEPTED)

        response = self.query(
            """
            query {
                experiments(status: Draft) {
                    name
                    slug
                    publicDescription
                }
            }
            """,
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)
        experiments = content["data"]["experiments"]
        self.assertEqual(len(experiments), 1)
        for key in experiments[0]:
            self.assertEqual(experiments[0][key],
                             str(getattr(draft_exp, to_snake_case(key))))
예제 #3
0
    def test_publishes_preview_experiments_and_unpublishes_non_preview_experiments(self):
        should_publish_experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.PREVIEW,
        )
        should_unpublish_experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED,
        )

        self.setup_kinto_get_main_records([should_unpublish_experiment.slug])

        tasks.nimbus_synchronize_preview_experiments_in_kinto()

        data = NimbusExperimentSerializer(should_publish_experiment).data

        self.mock_kinto_client.create_record.assert_called_with(
            data=data,
            collection=settings.KINTO_COLLECTION_NIMBUS_PREVIEW,
            bucket=settings.KINTO_BUCKET_WORKSPACE,
            if_not_exists=True,
        )
        self.mock_kinto_client.delete_record.assert_called_with(
            id=should_unpublish_experiment.slug,
            collection=settings.KINTO_COLLECTION_NIMBUS_PREVIEW,
            bucket=settings.KINTO_BUCKET_WORKSPACE,
        )
예제 #4
0
    def test_experiment_returns_country_and_locale(self):
        user_email = "*****@*****.**"
        NimbusExperimentFactory.create(publish_status=NimbusExperiment.PublishStatus.IDLE)

        response = self.query(
            """
            query {
                experiments {
                    countries {
                        code
                        name
                    }
                    locales {
                        code
                        name
                    }
                }
            }
            """,
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)
        experiment_data = content["data"]["experiments"][0]

        for locale in Locale.objects.all():
            self.assertIn(
                {"code": locale.code, "name": locale.name}, experiment_data["locales"]
            )

        for country in Country.objects.all():
            self.assertIn(
                {"code": country.code, "name": country.name}, experiment_data["countries"]
            )
예제 #5
0
    def test_check_with_no_approved_publish_status_pushes_nothing(self):
        for lifecycle in [
            NimbusExperimentFactory.Lifecycles.CREATED,
            NimbusExperimentFactory.Lifecycles.LAUNCH_REVIEW_REQUESTED,
            NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_WAITING,
            NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_APPROVE,
            NimbusExperimentFactory.Lifecycles.PAUSING_REVIEW_REQUESTED,
            NimbusExperimentFactory.Lifecycles.PAUSING_APPROVE_WAITING,
            NimbusExperimentFactory.Lifecycles.ENDING_REVIEW_REQUESTED,
            NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_WAITING,
        ]:
            NimbusExperimentFactory.create_with_lifecycle(
                lifecycle,
                application=NimbusExperiment.Application.DESKTOP,
            )

        self.setup_kinto_get_main_records([])
        self.setup_kinto_no_pending_review()

        tasks.nimbus_check_kinto_push_queue_by_collection(
            settings.KINTO_COLLECTION_NIMBUS_DESKTOP
        )
        self.mock_kinto_client.patch_collection.assert_not_called()
        self.mock_push_task.assert_not_called()
        self.mock_update_task.assert_not_called()
        self.mock_end_task.assert_not_called()
예제 #6
0
    def test_only_completes_experiments_with_matching_application_collection(
            self):
        desktop_experiment = NimbusExperimentFactory.create_with_status(
            NimbusExperiment.Status.LIVE,
            application=NimbusExperiment.Application.DESKTOP,
        )
        fenix_experiment = NimbusExperimentFactory.create_with_status(
            NimbusExperiment.Status.LIVE,
            application=NimbusExperiment.Application.FENIX,
        )

        def get_records(bucket, collection):
            if collection == settings.KINTO_COLLECTION_NIMBUS_DESKTOP:
                return [{"id": desktop_experiment.slug}]
            if collection == settings.KINTO_COLLECTION_NIMBUS_MOBILE:
                return [{"id": fenix_experiment.slug}]

        self.mock_kinto_client.get_records.side_effect = get_records
        tasks.nimbus_check_experiments_are_complete()

        self.assertTrue(
            NimbusExperiment.objects.filter(
                id=desktop_experiment.id,
                status=NimbusExperiment.Status.LIVE).exists())
        self.assertTrue(
            NimbusExperiment.objects.filter(
                id=fenix_experiment.id,
                status=NimbusExperiment.Status.LIVE).exists())
예제 #7
0
    def test_experiments_with_no_branches_returns_empty_treatment_values(self):
        user_email = "*****@*****.**"
        NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED, branches=[]
        )

        response = self.query(
            """
            query {
                experiments {
                    treatmentBranches {
                        name
                        slug
                        description
                        ratio
                    }
                }
            }
            """,
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)
        experiment_data = content["data"]["experiments"][0]
        self.assertEqual(
            experiment_data["treatmentBranches"],
            [{"name": "", "slug": "", "description": "", "ratio": 1}],
        )
예제 #8
0
    def test_experiment_updates_when_record_is_in_main(self):
        experiment1 = NimbusExperimentFactory.create_with_status(
            NimbusExperiment.Status.ACCEPTED, )

        experiment2 = NimbusExperimentFactory.create_with_status(
            NimbusExperiment.Status.ACCEPTED, )

        experiment3 = NimbusExperimentFactory.create_with_status(
            NimbusExperiment.Status.DRAFT, )

        self.assertEqual(experiment1.changes.count(), 3)
        self.assertEqual(experiment2.changes.count(), 3)
        self.assertEqual(experiment3.changes.count(), 1)

        self.setup_kinto_get_main_records([experiment1.slug])
        tasks.nimbus_check_experiments_are_live()

        self.assertEqual(experiment3.changes.count(), 1)

        self.assertTrue(
            experiment1.changes.filter(
                changed_by__email=settings.KINTO_DEFAULT_CHANGELOG_USER,
                old_status=NimbusExperiment.Status.ACCEPTED,
                new_status=NimbusExperiment.Status.LIVE,
            ).exists())

        self.assertFalse(
            experiment2.changes.filter(
                changed_by__email=settings.KINTO_DEFAULT_CHANGELOG_USER,
                old_status=NimbusExperiment.Status.ACCEPTED,
                new_status=NimbusExperiment.Status.LIVE,
            ).exists())
예제 #9
0
    def test_ending_experiment_completed_when_record_is_not_in_main(self):
        experiment1 = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_APPROVE,
            application=NimbusExperiment.Application.DESKTOP,
        )
        experiment2 = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_WAITING,
            application=NimbusExperiment.Application.DESKTOP,
        )

        self.setup_kinto_get_main_records([experiment1.slug])
        self.setup_kinto_no_pending_review()

        tasks.nimbus_check_kinto_push_queue_by_collection(
            settings.KINTO_COLLECTION_NIMBUS_DESKTOP)

        self.assertTrue(
            experiment2.changes.filter(
                changed_by__email=settings.KINTO_DEFAULT_CHANGELOG_USER,
                old_status=NimbusExperiment.Status.LIVE,
                old_publish_status=NimbusExperiment.PublishStatus.WAITING,
                new_status=NimbusExperiment.Status.COMPLETE,
                new_publish_status=NimbusExperiment.PublishStatus.IDLE,
                message=NimbusChangeLog.Messages.COMPLETED,
            ).exists())
예제 #10
0
    def test_update_queue_returns_experiments_that_should_update_by_application(self):
        # Should update, correct application
        experiment_should_update = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.PAUSING_APPROVE,
            application=NimbusExperiment.Application.DESKTOP,
        )

        # Should update, but wrong application
        NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.PAUSING_APPROVE,
            application=NimbusExperiment.Application.FENIX,
        )

        # Shouldn't update, correct application
        NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_APPROVE,
            application=NimbusExperiment.Application.DESKTOP,
        )

        self.assertEqual(
            list(
                NimbusExperiment.objects.update_queue(
                    [NimbusExperiment.Application.DESKTOP]
                )
            ),
            [experiment_should_update],
        )
예제 #11
0
    def test_experiment_updates_when_record_is_not_in_main(self):
        experiment1 = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_APPROVE,
        )
        experiment2 = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_WAITING,
        )
        experiment3 = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED,
        )

        initial_change_count = experiment3.changes.count()

        self.setup_kinto_get_main_records([experiment1.slug])
        tasks.nimbus_check_experiments_are_complete()

        self.assertEqual(experiment3.changes.count(), initial_change_count)

        self.assertTrue(
            NimbusExperiment.objects.filter(
                id=experiment1.id,
                status=NimbusExperiment.Status.LIVE,
                publish_status=NimbusExperiment.PublishStatus.IDLE,
            ).exists()
        )
        self.assertTrue(
            NimbusExperiment.objects.filter(
                id=experiment2.id,
                status=NimbusExperiment.Status.COMPLETE,
                publish_status=NimbusExperiment.PublishStatus.IDLE,
            ).exists()
        )
        self.assertTrue(
            NimbusExperiment.objects.filter(
                id=experiment3.id,
                status=NimbusExperiment.Status.DRAFT,
                publish_status=NimbusExperiment.PublishStatus.IDLE,
            ).exists()
        )

        self.assertFalse(
            experiment1.changes.filter(
                changed_by__email=settings.KINTO_DEFAULT_CHANGELOG_USER,
                old_status=NimbusExperiment.Status.LIVE,
                new_status=NimbusExperiment.Status.COMPLETE,
                message=NimbusChangeLog.Messages.COMPLETED,
            ).exists()
        )

        self.assertTrue(
            experiment2.changes.filter(
                changed_by__email=settings.KINTO_DEFAULT_CHANGELOG_USER,
                old_status=NimbusExperiment.Status.LIVE,
                old_publish_status=NimbusExperiment.PublishStatus.WAITING,
                new_status=NimbusExperiment.Status.COMPLETE,
                new_publish_status=NimbusExperiment.PublishStatus.IDLE,
                message=NimbusChangeLog.Messages.COMPLETED,
            ).exists()
        )
예제 #12
0
    def test_check_experiment_with_no_review_status_pushes_nothing(self):
        for status in [
                NimbusExperiment.Status.DRAFT,
                NimbusExperiment.Status.ACCEPTED,
                NimbusExperiment.Status.LIVE,
                NimbusExperiment.Status.COMPLETE,
        ]:
            NimbusExperimentFactory.create(status=status)

        self.setup_kinto_no_pending_review()
        tasks.nimbus_check_kinto_push_queue()
        self.mock_push_task.assert_not_called()
예제 #13
0
    def test_check_with_pending_review_before_timeout_aborts_early(self, ):
        NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_WAITING,
            application=NimbusExperiment.Application.DESKTOP,
        )

        self.setup_kinto_get_main_records([])
        self.setup_kinto_pending_review()

        tasks.nimbus_check_kinto_push_queue_by_collection(
            settings.KINTO_COLLECTION_NIMBUS_DESKTOP)
        self.mock_kinto_client.patch_collection.assert_not_called()
        self.mock_push_task.assert_not_called()
        self.mock_update_task.assert_not_called()
        self.mock_end_task.assert_not_called()
예제 #14
0
 def test_waiting_returns_any_waiting_experiments(self):
     NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.CREATED,
         application=NimbusExperiment.Application.IOS,
     )
     desktop_live_waiting = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_WAITING,
         application=NimbusExperiment.Application.DESKTOP,
     )
     self.assertEqual(
         list(
             NimbusExperiment.objects.waiting([NimbusExperiment.Application.DESKTOP])
         ),
         [desktop_live_waiting],
     )
    def test_generate_nimbus_changelog_without_prior_change(self):
        experiment = NimbusExperimentFactory.create()

        self.assertEqual(experiment.changes.count(), 0)

        generate_nimbus_changelog(experiment, self.user, "test message")

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

        change = experiment.changes.get()

        self.assertEqual(change.experiment, experiment)
        self.assertEqual(change.message, "test message")
        self.assertEqual(change.changed_by, self.user)
        self.assertEqual(change.old_status, None)
        self.assertEqual(change.old_status_next, None)
        self.assertEqual(change.old_publish_status, None)
        self.assertEqual(change.new_status, NimbusExperiment.Status.DRAFT)
        self.assertEqual(change.new_status_next, None)
        self.assertEqual(change.new_publish_status,
                         NimbusExperiment.PublishStatus.IDLE)
        self.assertEqual(
            change.experiment_data,
            dict(NimbusExperimentChangeLogSerializer(experiment).data),
        )
예제 #16
0
 def test_experiment_with_timeout_returns_changelog(self):
     user_email = "*****@*****.**"
     experiment = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_TIMEOUT
     )
     response = self.query(
         """
         query experimentBySlug($slug: String!) {
             experimentBySlug(slug: $slug) {
                 timeout {
                     changedBy {
                         email
                     }
                 }
             }
         }
         """,
         variables={"slug": experiment.slug},
         headers={settings.OPENIDC_EMAIL_HEADER: user_email},
     )
     content = json.loads(response.content)
     self.assertEqual(response.status_code, 200)
     experiment_data = content["data"]["experimentBySlug"]
     self.assertEqual(
         experiment_data["timeout"]["changedBy"]["email"], experiment.owner.email
     )
예제 #17
0
 def test_recipe_json_returns_serialized_data(self):
     user_email = "*****@*****.**"
     experiment = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.CREATED
     )
     response = self.query(
         """
         query experimentBySlug($slug: String!) {
             experimentBySlug(slug: $slug) {
                 recipeJson
             }
         }
         """,
         variables={"slug": experiment.slug},
         headers={settings.OPENIDC_EMAIL_HEADER: user_email},
     )
     content = json.loads(response.content)
     self.assertEqual(response.status_code, 200)
     experiment_data = content["data"]["experimentBySlug"]
     self.assertEqual(
         experiment_data["recipeJson"],
         json.dumps(
             NimbusExperimentSerializer(experiment).data, indent=2, sort_keys=True
         ),
     )
예제 #18
0
 def test_experiment_with_review_request(self):
     user_email = "*****@*****.**"
     experiment = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.LAUNCH_REVIEW_REQUESTED
     )
     response = self.query(
         """
         query experimentBySlug($slug: String!) {
             experimentBySlug(slug: $slug) {
                 reviewRequest {
                     changedBy {
                         email
                     }
                 }
             }
         }
         """,
         variables={"slug": experiment.slug},
         headers={settings.OPENIDC_EMAIL_HEADER: user_email},
     )
     self.assertEqual(response.status_code, 200, response.content)
     content = json.loads(response.content)
     experiment_data = content["data"]["experimentBySlug"]
     self.assertEqual(
         experiment_data["reviewRequest"]["changedBy"]["email"], experiment.owner.email
     )
예제 #19
0
    def test_push_experiment_to_kinto_sends_fenix_experiment_data(self):
        experiment = NimbusExperimentFactory.create_with_status(
            NimbusExperiment.Status.DRAFT,
            application=NimbusExperiment.Application.FENIX,
            population_percent=Decimal("50.0"),
        )

        tasks.nimbus_push_experiment_to_kinto(experiment.id)

        self.assertEqual(experiment.bucket_range.start, 0)
        self.assertEqual(experiment.bucket_range.count, 5000)

        data = NimbusExperimentSerializer(experiment).data

        self.mock_kinto_client.create_record.assert_called_with(
            data=data,
            collection=settings.KINTO_COLLECTION_NIMBUS_MOBILE,
            bucket=settings.KINTO_BUCKET,
            if_not_exists=True,
        )

        self.assertTrue(
            NimbusChangeLog.objects.filter(
                experiment=experiment,
                changed_by__email=settings.KINTO_DEFAULT_CHANGELOG_USER,
                old_status=NimbusExperiment.Status.DRAFT,
                new_status=NimbusExperiment.Status.ACCEPTED,
            ).exists())
예제 #20
0
    def test_experiment_no_rejection_data(self):
        user_email = "*****@*****.**"
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED
        )

        response = self.query(
            """
            query experimentBySlug($slug: String!) {
                experimentBySlug(slug: $slug) {
                    rejection {
                        changedBy {
                            email
                        }
                    }
                }
            }
            """,
            variables={"slug": experiment.slug},
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200, response.content)
        content = json.loads(response.content)
        experiment_data = content["data"]["experimentBySlug"]
        self.assertIsNone(experiment_data["rejection"])
예제 #21
0
 def test_experiment_no_jexl_targeting_expression(self):
     user_email = "*****@*****.**"
     experiment = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.CREATED,
         targeting_config_slug="",
         application=NimbusExperiment.Application.FENIX,
     )
     response = self.query(
         """
         query experimentBySlug($slug: String!) {
             experimentBySlug(slug: $slug) {
                 jexlTargetingExpression
             }
         }
         """,
         variables={"slug": experiment.slug},
         headers={settings.OPENIDC_EMAIL_HEADER: user_email},
     )
     self.assertEqual(response.status_code, 200, response.content)
     content = json.loads(response.content)
     experiment_data = content["data"]["experimentBySlug"]
     self.assertEqual(
         experiment_data["jexlTargetingExpression"],
         "true",
     )
예제 #22
0
    def test_experiment_by_slug_not_ready_for_review(self):
        user_email = "*****@*****.**"
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED,
            hypothesis=NimbusExperiment.HYPOTHESIS_DEFAULT,
        )

        response = self.query(
            """
            query experimentBySlug($slug: String!) {
                experimentBySlug(slug: $slug) {
                    readyForReview {
                        message
                        ready
                    }
                }
            }
            """,
            variables={"slug": experiment.slug},
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200, response.content)
        content = json.loads(response.content)
        experiment_data = content["data"]["experimentBySlug"]
        self.assertEqual(
            experiment_data["readyForReview"],
            {
                "message": {"hypothesis": ["Hypothesis cannot be the default value."]},
                "ready": False,
            },
        )
예제 #23
0
    def test_paused_experiment_returns_date(self):
        user_email = "*****@*****.**"
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.LIVE_PAUSED,
            proposed_enrollment=7,
        )
        live_change = experiment.changes.get(
            old_status=NimbusExperiment.Status.DRAFT,
            new_status=NimbusExperiment.Status.LIVE,
        )
        live_change.changed_on = datetime.datetime(2021, 1, 1)
        live_change.save()

        response = self.query(
            """
            query experimentBySlug($slug: String!) {
                experimentBySlug(slug: $slug) {
                    isEnrollmentPaused
                    enrollmentEndDate
                }
            }
            """,
            variables={"slug": experiment.slug},
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200, response.content)
        content = json.loads(response.content)
        experiment_data = content["data"]["experimentBySlug"]
        self.assertEqual(experiment_data["isEnrollmentPaused"], True)
        self.assertEqual(experiment_data["enrollmentEndDate"], "2021-01-08")
예제 #24
0
    def test_signoff_recommendations(self):
        user_email = "*****@*****.**"
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED,
            risk_brand=True,
            risk_revenue=True,
            risk_partner_related=True,
        )

        response = self.query(
            """
            query experimentBySlug($slug: String!) {
                experimentBySlug(slug: $slug) {
                    signoffRecommendations {
                        qaSignoff
                        vpSignoff
                        legalSignoff
                    }
                }
            }
            """,
            variables={"slug": experiment.slug},
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200, response.content)
        content = json.loads(response.content)
        experiment_data = content["data"]["experimentBySlug"]
        self.assertEqual(experiment_data["signoffRecommendations"]["qaSignoff"], True)
        self.assertEqual(experiment_data["signoffRecommendations"]["vpSignoff"], True)
        self.assertEqual(experiment_data["signoffRecommendations"]["legalSignoff"], True)
예제 #25
0
    def test_experiments_with_branches_returns_branch_data(self):
        user_email = "*****@*****.**"
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED
        )

        response = self.query(
            """
            query {
                experiments {
                    referenceBranch {
                        slug
                    }
                    treatmentBranches {
                        slug
                    }
                }
            }
            """,
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)
        experiment_data = content["data"]["experiments"][0]
        self.assertEqual(
            experiment_data["referenceBranch"],
            {"slug": experiment.reference_branch.slug},
        )
        self.assertEqual(
            {b["slug"] for b in experiment_data["treatmentBranches"]},
            {b.slug for b in experiment.treatment_branches},
        )
예제 #26
0
    def test_experiments_with_documentation_links_return_link_data(self):
        user_email = "*****@*****.**"
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED
        )
        documentation_links = experiment.documentation_links.all()
        self.assert_(len(documentation_links) > 0)

        response = self.query(
            """
            query {
                experiments {
                    documentationLinks {
                        title
                        link
                    }
                }
            }
            """,
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)
        experiment_data = content["data"]["experiments"][0]
        for key in (
            "title",
            "link",
        ):
            self.assertEqual(
                {b[key] for b in experiment_data["documentationLinks"]},
                {getattr(b, key) for b in documentation_links},
            )
예제 #27
0
 def test_form_saves_outcomes(self):
     experiment = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.CREATED,
         primary_outcomes=[],
         secondary_outcomes=[],
     )
     form = NimbusExperimentAdminForm(
         instance=experiment,
         data={
             "owner": experiment.owner,
             "status": experiment.status,
             "publish_status": experiment.publish_status,
             "name": experiment.name,
             "slug": experiment.slug,
             "proposed_duration": experiment.proposed_duration,
             "proposed_enrollment": experiment.proposed_enrollment,
             "population_percent": experiment.population_percent,
             "total_enrolled_clients": experiment.total_enrolled_clients,
             "application": experiment.application,
             "hypothesis": experiment.hypothesis,
             "primary_outcomes": "outcome1, outcome2",
             "secondary_outcomes": "outcome3, outcome4",
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     experiment = form.save()
     self.assertEqual(experiment.primary_outcomes, ["outcome1", "outcome2"])
     self.assertEqual(experiment.secondary_outcomes,
                      ["outcome3", "outcome4"])
예제 #28
0
    def test_experiment_by_slug_ready_for_review(self):
        user_email = "*****@*****.**"
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED
        )

        response = self.query(
            """
            query experimentBySlug($slug: String!) {
                experimentBySlug(slug: $slug) {
                    name
                    slug
                    publicDescription
                    readyForReview {
                        message
                        ready
                    }
                }
            }
            """,
            variables={"slug": experiment.slug},
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200, response.content)
        content = json.loads(response.content)
        experiment_data = content["data"]["experimentBySlug"]
        self.assertEqual(experiment_data["name"], experiment.name)
        self.assertEqual(experiment_data["slug"], experiment.slug)
        self.assertEqual(
            experiment_data["publicDescription"], experiment.public_description
        )
        self.assertEqual(
            experiment_data["readyForReview"], {"message": {}, "ready": True}
        )
    def test_generate_nimbus_changelog_with_prior_change(self):
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED)

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

        experiment.status = NimbusExperiment.Status.DRAFT
        experiment.status_next = NimbusExperiment.Status.LIVE
        experiment.publish_status = NimbusExperiment.PublishStatus.REVIEW
        experiment.save()

        generate_nimbus_changelog(experiment, self.user, "test message")

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

        change = experiment.changes.latest_change()

        self.assertEqual(change.experiment, experiment)
        self.assertEqual(change.message, "test message")
        self.assertEqual(change.changed_by, self.user)
        self.assertEqual(change.old_status, NimbusExperiment.Status.DRAFT)
        self.assertEqual(change.old_status_next, None)
        self.assertEqual(change.old_publish_status,
                         NimbusExperiment.PublishStatus.IDLE)
        self.assertEqual(change.new_status, NimbusExperiment.Status.DRAFT)
        self.assertEqual(change.new_status_next, NimbusExperiment.Status.LIVE)
        self.assertEqual(change.new_publish_status,
                         NimbusExperiment.PublishStatus.REVIEW)
        self.assertEqual(
            change.experiment_data,
            dict(NimbusExperimentChangeLogSerializer(experiment).data),
        )
예제 #30
0
    def test_experiments(self):
        user_email = "*****@*****.**"
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.CREATED
        )

        response = self.query(
            """
            query {
                experiments {
                    name
                    slug
                    publicDescription
                    riskMitigationLink
                }
            }
            """,
            headers={settings.OPENIDC_EMAIL_HEADER: user_email},
        )
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)
        experiments = content["data"]["experiments"]
        self.assertEqual(len(experiments), 1)
        for key in experiments[0]:
            self.assertEqual(
                experiments[0][key], str(getattr(experiment, to_snake_case(key)))
            )