def test_bugzilla_url_optional_for_rollout(self): self.data["type"] = Experiment.TYPE_ROLLOUT del self.data["data_science_issue_url"] form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertTrue(form.is_valid())
def test_start_date_must_be_greater_or_equal_to_current_date(self): self.data[ "proposed_start_date" ] = datetime.date.today() - datetime.timedelta(days=1) form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertFalse(form.is_valid())
def test_minimum_required_fields_for_experiment(self): bug_url = "https://jira.example.com/browse/DO-123" data = { "type": Experiment.TYPE_PREF, "owner": self.user.id, "name": "A new experiment!", "short_description": "Let us learn new things", "data_science_issue_url": bug_url, "public_description": "Public Description", } form = ExperimentOverviewForm(request=self.request, data=data) self.assertTrue(form.is_valid()) experiment = form.save() self.assertEqual(experiment.owner, self.user) self.assertEqual(experiment.status, experiment.STATUS_DRAFT) self.assertEqual(experiment.name, data["name"]) self.assertEqual(experiment.slug, "a-new-experiment") self.assertEqual(experiment.short_description, data["short_description"]) self.assertEqual(experiment.public_description, data["public_description"]) self.assertEqual(experiment.changes.count(), 1)
def test_form_creates_experiment(self): form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertTrue(form.is_valid()) experiment = form.save() self.assertEqual(experiment.owner, self.user) self.assertEqual(experiment.engineering_owner, self.data["engineering_owner"]) self.assertEqual(experiment.status, experiment.STATUS_DRAFT) self.assertEqual(experiment.name, self.data["name"]) self.assertEqual(experiment.slug, "a-new-experiment") self.assertEqual(experiment.short_description, self.data["short_description"]) self.assertTrue(self.related_exp in experiment.related_to.all()) self.assertCountEqual(self.data["projects"], experiment.projects.all()) self.assertEqual(experiment.changes.count(), 1) change = experiment.changes.get() self.assertEqual(change.old_status, None) self.assertEqual(change.new_status, experiment.status) self.assertEqual(change.changed_by, self.request.user)
def test_minimum_required_fields_for_rollout(self): data = { "type": Experiment.TYPE_ROLLOUT, "owner": self.user.id, "name": "A new experiment!", "short_description": "Let us learn new things", "public_description": "Let us learn new things in the open", } form = ExperimentOverviewForm(request=self.request, data=data) self.assertTrue(form.is_valid()) experiment = form.save() self.assertEqual(experiment.owner, self.user) self.assertEqual(experiment.status, experiment.STATUS_DRAFT) self.assertEqual(experiment.name, self.data["name"]) self.assertEqual(experiment.slug, "a-new-experiment") self.assertEqual(experiment.short_description, self.data["short_description"]) self.assertEqual(experiment.changes.count(), 1)
def test_message_experiment_sets_default_locales_countries(self): [ LocaleFactory.create(code=l) for l in Experiment.MESSAGE_DEFAULT_LOCALES ] [ CountryFactory.create(code=c) for c in Experiment.MESSAGE_DEFAULT_COUNTRIES ] self.data["type"] = Experiment.TYPE_MESSAGE form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertTrue(form.is_valid()) experiment = form.save() self.assertEqual( set(experiment.locales.values_list("code", flat=True)), set(Experiment.MESSAGE_DEFAULT_LOCALES), ) self.assertEqual( set(experiment.countries.values_list("code", flat=True)), set(Experiment.MESSAGE_DEFAULT_COUNTRIES), )
def test_form_creates_experiment(self): form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertTrue(form.is_valid()) experiment = form.save() self.assertEqual(experiment.owner, self.user) self.assertEqual(experiment.status, experiment.STATUS_DRAFT) self.assertEqual(experiment.name, self.data["name"]) self.assertEqual(experiment.slug, "a-new-experiment") self.assertEqual( experiment.short_description, self.data["short_description"] ) self.assertEqual( experiment.proposed_start_date, self.data["proposed_start_date"] ) self.assertEqual(experiment.proposed_enrollment, 10) self.assertEqual(experiment.proposed_duration, 20) self.assertEqual(experiment.changes.count(), 1) change = experiment.changes.get() self.assertEqual(change.old_status, None) self.assertEqual(change.new_status, experiment.status) self.assertEqual(change.changed_by, self.request.user)
def test_invalid_bugzilla_url(self): self.data["data_science_issue_url"] = "https://example.com/notbugzilla" form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertFalse(form.is_valid())
def test_ds_issue_url_required_for_non_rollout(self): self.data["type"] = Experiment.TYPE_PREF del self.data["data_science_issue_url"] form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertFalse(form.is_valid())
def test_unique_name_with_same_slug_raises_error(self): ExperimentFactory.create(slug="slug") self.data["name"] = "slug#" form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertFalse(form.is_valid())
def test_empty_slug_raises_error(self): self.data["name"] = "#" form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertFalse(form.is_valid())
def test_changelog_values(self): experiment = Experiment() experiment.save() ds_url = "{base}DS-123".format(base=settings.DS_ISSUE_HOST) bug_url = "{base}show_bug.cgi?id=123".format( base=settings.BUGZILLA_HOST) related_exp = ExperimentFactory.create() project = ProjectFactory.create() data = { "type": Experiment.TYPE_PREF, "name": "A new experiment!", "short_description": "Let us learn new things", "data_science_issue_url": ds_url, "owner": self.user.id, "analysis_owner": self.user.id, "engineering_owner": "Lisa the Engineer", "public_description": "Let us learn new public things", "related_to": [related_exp], "feature_bugzilla_url": bug_url, "related_work": "Designs: https://www.example.com/myproject/", "projects": [project], } form = ExperimentOverviewForm(request=self.request, data=data, instance=experiment) self.assertTrue(form.is_valid()) experiment = form.save() latest_changes = experiment.changes.latest() expected_data = { "analysis_owner": { "display_name": "Data Science Owner", "new_value": experiment.analysis_owner.id, "old_value": None, }, "data_science_issue_url": { "display_name": "Data Science Issue URL", "new_value": "https://jira.example.com/browse/DS-123", "old_value": None, }, "engineering_owner": { "display_name": "Engineering Owner", "new_value": "Lisa the Engineer", "old_value": None, }, "feature_bugzilla_url": { "display_name": "Feature Bugzilla URL", "new_value": "https://bugzilla.allizom.org/show_bug.cgi?id=123", "old_value": None, }, "name": { "display_name": "Public Name", "new_value": "A new experiment!", "old_value": None, }, "owner": { "display_name": "Delivery Owner", "new_value": experiment.owner.id, "old_value": None, }, "projects": { "display_name": "Related Projects", "new_value": [{ "slug": project.slug }], "old_value": None, }, "public_description": { "display_name": "Public Description", "new_value": "Let us learn new public things", "old_value": None, }, "related_to": { "display_name": "Related Deliveries", "new_value": [related_exp.id], "old_value": None, }, "related_work": { "display_name": "Related Work URLs", "new_value": "Designs: https://www.example.com/myproject/", "old_value": None, }, "short_description": { "display_name": "Internal Description", "new_value": "Let us learn new things", "old_value": None, }, } self.maxDiff = None self.assertEqual(expected_data, latest_changes.changed_values)
def test_large_enrollment_duration_is_invalid(self): self.data["proposed_enrollment"] = Experiment.MAX_DURATION + 1 form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertFalse(form.is_valid())
def test_enrollment_is_optional(self): del self.data["proposed_enrollment"] form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertTrue(form.is_valid())
def test_enrollment_must_be_less_or_equal_duration(self): self.data["proposed_enrollment"] = 2 self.data["proposed_duration"] = 1 form = ExperimentOverviewForm(request=self.request, data=self.data) self.assertFalse(form.is_valid())