Skip to content

Commit

Permalink
Merge pull request #863 from betagouv/fix/change-run-missing-label
Browse files Browse the repository at this point in the history
bugfix: members cannot edit run (missing label)
  • Loading branch information
wiwski authored Mar 29, 2024
2 parents 603bcd4 + a445a8a commit bdffebb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 0 additions & 1 deletion lab/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def _clean_methods(self, cleaned_data, errors):
class RunDetailsForm(BaseRunDetailsForm):
class Meta(BaseRunDetailsForm.Meta):
fields = (
"label",
"beamline",
*[f.name for f in models.Run.get_method_fields()],
*[f.name for f in models.Run.get_detector_fields()],
Expand Down
4 changes: 4 additions & 0 deletions lab/static/css/admin/run.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ body {
padding: 0;
}

.change-form .field-energy_in_keV input {
margin-top: .5rem !important;
}

.form-row {
max-width: 500px;
}
Expand Down
37 changes: 37 additions & 0 deletions lab/tests/admin/test_run_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,43 @@ def test_add_redirect_when_no_project_membership(self):

assert response.status_code == 302

@patch("django.middleware.csrf.CsrfViewMiddleware._check_token", lambda *args: None)
def test_changing_run(self):
run = factories.RunFactory(label="Run 1", project=self.project)
data = {
"particle_type": "Proton",
"energy_in_keV_Proton": "1000",
"energy_in_keV_Alpha+particle": "",
"energy_in_keV_Deuton": "",
"beamline": "Microbeam",
"method_PIXE": "on",
"detector_LE0": "on",
"filters_for_detector_LE0": "Helium",
"filters_for_detector_HE1": "",
"filters_for_detector_HE2": "",
"filters_for_detector_HE3": "",
"filters_for_detector_HE4": "",
"detector_IBIL_other": "",
"detector_FORS_other": "",
"detector_ERDA": "",
"detector_NRA": "",
}

self.client.force_login(self.project_leader_user)
self.client.post(
reverse("admin:lab_run_change", args=[run.id]),
data=data,
)

run = Run.objects.get(pk=run.id)
assert run.particle_type == "Proton"
assert run.energy_in_keV == 1000
assert run.beamline == "Microbeam"
assert run.method_PIXE
assert run.detector_LE0
assert run.filters_for_detector_LE0 == "Helium"
assert not run.filters_for_detector_HE1


class TestRunAdminViewAsAdmin(TestCase):
def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions lab/tests/test_controlled_datalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_form_fails_gracefully_with_incoherent_controller_input():
def test_form_doesnt_raise_for_energy_when_other_errors():
form = RunDetailsForm(
data={
"beamline": "Microbeam",
"beamline": "WRONG",
"energy_in_keV_Proton": 1,
"energy_in_keV_Alpha particle": 2,
"energy_in_keV_Deuton": "",
Expand All @@ -103,5 +103,5 @@ def test_form_doesnt_raise_for_energy_when_other_errors():
)
with patch.object(QuerySet, "exists", return_value=False):
assert not form.is_valid()
assert form.has_error("label")
assert form.has_error("beamline")
assert not form.has_error("energy_in_keV")

0 comments on commit bdffebb

Please sign in to comment.