Skip to content

Commit

Permalink
Add unit test for admin person-doc type merge (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Jan 21, 2025
1 parent e5d44da commit 8edbbac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions geniza/entities/tests/test_entities_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
NameInlineFormSet,
PersonAdmin,
PersonDocumentInline,
PersonDocumentRelationTypeAdmin,
PersonPersonInline,
PersonPersonRelationTypeChoiceField,
PersonPersonReverseInline,
Expand All @@ -21,6 +22,7 @@
Name,
Person,
PersonDocumentRelation,
PersonDocumentRelationType,
PersonPersonRelation,
PersonPersonRelationType,
PersonPlaceRelation,
Expand Down Expand Up @@ -415,3 +417,29 @@ def test_export_relations_to_csv(self, person):
# - some content
assert str(person) in content
assert "Home base" in content


class TestPersonDocumentRelationTypeAdmin:
def test_merge_person_document_relation_types(self):
pdr_admin = PersonDocumentRelationTypeAdmin(
model=PersonDocumentRelationType, admin_site=admin.site
)
mockrequest = Mock()
test_ids = ["1", "2", "3"]
mockrequest.POST.getlist.return_value = test_ids
resp = pdr_admin.merge_person_document_relation_types(mockrequest, Mock())
assert isinstance(resp, HttpResponseRedirect)
assert resp.status_code == 303
assert resp["location"].startswith(
reverse("admin:person-document-relation-type-merge")
)
assert resp["location"].endswith("?ids=%s" % ",".join(test_ids))

test_ids = ["1"]
mockrequest.POST.getlist.return_value = test_ids
resp = pdr_admin.merge_person_document_relation_types(mockrequest, Mock())
assert isinstance(resp, HttpResponseRedirect)
assert resp.status_code == 302
assert resp["location"] == reverse(
"admin:entities_persondocumentrelationtype_changelist"
)
2 changes: 1 addition & 1 deletion geniza/entities/tests/test_entities_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_get_form_kwargs(self):
form_kwargs = merge_view.get_form_kwargs()
assert form_kwargs["ids"] == merge_view.ids

def test_person_merge(self, admin_client, client):
def test_person_document_relation_type_merge(self, admin_client, client):
# Ensure that the merge view is not visible to public
response = client.get(reverse("admin:person-document-relation-type-merge"))
assert response.status_code == 302
Expand Down

0 comments on commit 8edbbac

Please sign in to comment.