def test_generate_reportlogs_creates_for_both_types_of_changelogs(self): mock_response_data = [] mock_response = mock.Mock() mock_response.json = mock.Mock() mock_response.json.return_value = mock_response_data mock_response.raise_for_status = mock.Mock() mock_response.raise_for_status.side_effect = None mock_response.status_code = 200 self.mock_normandy_requests_get.return_value = mock_response experiment = ExperimentFactory.create_with_status( target_status=Experiment.STATUS_LIVE) NimbusExperimentFactory.create_with_lifecycle( NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_APPROVE) self.assertEqual(ReportLog.objects.count(), 0) generate_reportlogs() self.assertEqual( ReportLog.objects.filter( experiment_type__startswith="Normandy").count(), 5) self.assertEqual( ReportLog.objects.filter( experiment_type__startswith="Nimbus").count(), 3) self.assertEqual(ReportLog.objects.count(), 8) ExperimentChangeLogFactory.create( changed_on=timezone.now(), experiment=experiment, old_status=Experiment.STATUS_LIVE, new_status=Experiment.STATUS_COMPLETE, ) self.assertEqual(ExperimentChangeLog.objects.count(), 6) generate_reportlogs() self.assertEqual(ReportLog.objects.count(), 9)
def test_reject_end_enrollment(self): user_email = "*****@*****.**" experiment = NimbusExperimentFactory.create_with_lifecycle( NimbusExperimentFactory.Lifecycles.PAUSING_REVIEW_REQUESTED ) self.assertEqual(experiment.is_paused, True) response = self.query( UPDATE_EXPERIMENT_MUTATION, variables={ "input": { "id": experiment.id, "status": NimbusExperiment.Status.LIVE.name, "statusNext": None, "publishStatus": NimbusExperiment.PublishStatus.IDLE.name, "isEnrollmentPaused": False, "changelogMessage": "test changelog message", } }, headers={settings.OPENIDC_EMAIL_HEADER: user_email}, ) self.assertEqual(response.status_code, 200, response.content) content = json.loads(response.content) result = content["data"]["updateExperiment"] self.assertEqual(result["message"], "success") experiment = NimbusExperiment.objects.get(id=experiment.id) self.assertEqual(experiment.is_paused, False)
def test_reject_ending_experiment(self): user_email = "*****@*****.**" experiment = NimbusExperimentFactory.create_with_lifecycle( NimbusExperimentFactory.Lifecycles.ENDING_REVIEW_REQUESTED ) response = self.query( UPDATE_EXPERIMENT_MUTATION, variables={ "input": { "id": experiment.id, "publishStatus": NimbusExperiment.PublishStatus.IDLE.name, "statusNext": NimbusExperiment.Status.COMPLETE.name, "changelogMessage": "This is not good", } }, headers={settings.OPENIDC_EMAIL_HEADER: user_email}, ) self.assertEqual(response.status_code, 200, response.content) content = json.loads(response.content) result = content["data"]["updateExperiment"] self.assertEqual(result["message"], "success") experiment = NimbusExperiment.objects.get(id=experiment.id) self.assertEqual(experiment.publish_status, NimbusExperiment.PublishStatus.IDLE) self.assertEqual(experiment.status_next, NimbusExperiment.Status.COMPLETE) rejection = experiment.changes.latest_rejection() self.assertEqual(rejection.changed_by.email, user_email) self.assertEqual(rejection.message, "This is not good")
def test_does_not_clear_feature_config_when_other_fields_specified(self): user_email = "*****@*****.**" experiment = NimbusExperimentFactory.create_with_lifecycle( NimbusExperimentFactory.Lifecycles.CREATED ) expected_feature_config = experiment.feature_config response = self.query( UPDATE_EXPERIMENT_MUTATION, variables={ "input": { "id": experiment.id, "name": "new name", "hypothesis": "new hypothesis", "publicDescription": "new public description", "changelogMessage": "test changelog message", } }, headers={settings.OPENIDC_EMAIL_HEADER: user_email}, ) self.assertEqual(response.status_code, 200, response.content) content = json.loads(response.content) result = content["data"]["updateExperiment"] self.assertEqual(result["message"], "success") experiment = NimbusExperiment.objects.first() self.assertEqual(experiment.feature_config, expected_feature_config)
def test_reject_draft_experiment(self): user_email = "*****@*****.**" experiment = NimbusExperimentFactory.create_with_lifecycle( NimbusExperimentFactory.Lifecycles.LAUNCH_REVIEW_REQUESTED ) response = self.query( UPDATE_EXPERIMENT_MUTATION, variables={ "input": { "id": experiment.id, "publishStatus": NimbusExperiment.PublishStatus.IDLE.name, "changelogMessage": "This is not good", } }, headers={settings.OPENIDC_EMAIL_HEADER: user_email}, ) self.assertEqual(response.status_code, 200) experiment = NimbusExperiment.objects.get(id=experiment.id) self.assertEqual(experiment.publish_status, NimbusExperiment.PublishStatus.IDLE) rejection = experiment.changes.latest_rejection() self.assertEqual(rejection.changed_by.email, user_email) self.assertEqual(rejection.message, "This is not good")