-
Notifications
You must be signed in to change notification settings - Fork 224
risk_technical and risk_technical_description invariance fixes #1082 #1103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1081,6 +1081,46 @@ def test_form_saves_risks(self): | |
| self.assertEqual(experiment.test_builds, data["test_builds"]) | ||
| self.assertEqual(experiment.qa_status, data["qa_status"]) | ||
|
|
||
| def test_form_risk_technical_invariance(self): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the word 'invariance' is descriptive here, the issue is that if risk_technical is true then risk_technical_description is required, so maybe something like |
||
| created_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_technical": True, | ||
| "risk_technical_description": "", # Note! | ||
| "risks": "There are some risks", | ||
| "testing": "Always be sure to test!", | ||
| "test_builds": "Latest build", | ||
| "qa_status": "It ain't easy being green", | ||
| } | ||
|
|
||
| form = ExperimentRisksForm( | ||
| request=self.request, data=data, instance=created_experiment | ||
| ) | ||
| self.assertFalse(form.is_valid()) | ||
|
|
||
| # It would be okey if 'risk_technical' was falsy. | ||
| data["risk_technical"] = False | ||
| form = ExperimentRisksForm( | ||
| request=self.request, data=data, instance=created_experiment | ||
| ) | ||
| self.assertTrue(form.is_valid()) | ||
|
|
||
| # And definitely OK if both at truthy. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if both *are truthy |
||
| data["risk_technical"] = True | ||
| data["risk_technical_description"] = "Some text" | ||
| form = ExperimentRisksForm( | ||
| request=self.request, data=data, instance=created_experiment | ||
| ) | ||
| self.assertTrue(form.is_valid()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather have each of these cases tested in separate tests, and also shouldn't we be testing the case where risk_technical is true but risk_technical_description is empty and the form fails to validate? |
||
|
|
||
|
|
||
| class TestExperimentReviewForm( | ||
| MockRequestMixin, MockBugzillaMixin, MockTasksMixin, TestCase | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird to me that these are strings like that. Even after supposed cleaning. I've never seen that before. Is there a better way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that is weird?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is because the base form field is a
ChoiceFieldwhich coerces all values to strings. Since the underlying model for these fields is a boolean we should useTypedChoiceFieldhere and provide a propercoercefunction to make this nicer.