Skip to content
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

feat(forms): add c2rmf_id normalization (upper) and update tests #1151

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lab/objects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,15 @@ def clean(self) -> dict[str, Any]:
{"c2rmf_id": _("This ID was not found in Eros.")}
)
data = {
**self.cleaned_data,
**eros_data,
"object_count": 1,
}
return data

def clean_c2rmf_id(self):
return self.cleaned_data["c2rmf_id"].upper()


class ObjectGroupImportC2RMFReadonlyForm(forms.ModelForm):
class Meta:
Expand Down
15 changes: 14 additions & 1 deletion lab/objects/tests/forms/test_object_group_import_c2rmf_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_form_conf():
@mock.patch("lab.objects.forms.fetch_partial_objectgroup_from_eros")
def test_clean_fetch_data(mock_fetch: mock.MagicMock):
mock_fetch.return_value = {
"c2rmf_id": "C2RMF00000",
"worknbr": "C2RMF00000",
"label": "Test",
}
form = ObjectGroupImportC2RMFForm()
Expand Down Expand Up @@ -64,3 +64,16 @@ def test_clean_set_form_if_obj_exists():

assert form.instance
assert form.instance.id == objectgroup.id


@pytest.mark.django_db
@mock.patch("lab.objects.forms.fetch_partial_objectgroup_from_eros")
def test_clean_c2rmf_id_upper(mock_fetch: mock.MagicMock):
mock_fetch.return_value = {
"worknbr": "C2RMF00000",
"label": "Test",
}
form = ObjectGroupImportC2RMFForm(data={"c2rmf_id": "c2rmf00000"})
form.full_clean()

assert form.cleaned_data["c2rmf_id"] == "C2RMF00000"
Loading