Skip to content
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
357ec1b
[test] Add attachment path test helpers
rijulpoudel Oct 28, 2026
57bc1e2
[test] Match Taxon by full name
rijulpoudel Oct 28, 2026
3b06c57
[test] Match Storage by full name
rijulpoudel Oct 28, 2026
ee0b398
[test] Match Collecting Event by GUID
rijulpoudel Oct 28, 2026
8c8f926
[test] Match Collecting Event by field number
rijulpoudel Oct 28, 2026
f923567
[test] Match Loan by loan number
rijulpoudel Oct 28, 2026
6dd6dc5
[test] Match Accession by accession number
rijulpoudel Oct 28, 2026
44d0c9c
[test] Match Gift by gift number
rijulpoudel Oct 28, 2026
569b903
[test] Match Preparation by barcode
rijulpoudel Oct 28, 2026
19de9c5
[test] Match Preparation by GUID
rijulpoudel Oct 28, 2026
bb650e1
[test] Match Treatment Event by field number
rijulpoudel Oct 28, 2026
8ac3d87
[test] Match Exchange In by exchange in number
rijulpoudel Oct 28, 2026
b3dc799
[test] Match Exchange Out by exchange out number
rijulpoudel Oct 28, 2026
a85e84f
[test] Match Reference Work by title
rijulpoudel Oct 28, 2026
29b450a
[test] Match Reference Work by GUID
rijulpoudel Oct 28, 2026
6294b0c
[test] Match Locality by unique identifier
rijulpoudel Oct 28, 2026
547732c
[test] Match Locality by GUID
rijulpoudel Oct 28, 2026
7c69966
[test] Match Permit by permit number
rijulpoudel Oct 28, 2026
67d5849
[test] Match Agent by GUID
rijulpoudel Oct 28, 2026
878e9e9
[test] Match Collecting Trip by name
rijulpoudel Oct 28, 2026
98ea8e0
[test] Match Deaccession by number
rijulpoudel Oct 28, 2026
df2fd0e
Merge branch 'main' into issue-8727
rijulpoudel Oct 29, 2026
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import unittest
from unittest.mock import patch

from django.test import Client
Expand Down Expand Up @@ -123,4 +124,286 @@ def test_match_borrow_by_invoice_number(self, session_context):
{"results": [[borrow.id, invoicenumber]]},
)

def _assert_path(self, table_name, field_name, value, record_id):
model = getattr(models, table_name.capitalize())
client = Client()
client.force_login(self.specifyuser)

query = get_simple_query(self.specifyuser)
query["contexttableid"] = model.specify_model.tableId
query["contextname"] = table_name
query["fields"][0].update(
{
"tablelist": str(model.specify_model.tableId),
"stringid": (
f"{model.specify_model.tableId}."
f"{table_name.lower()}.{field_name}"
),
"fieldname": field_name,
"operstart": 10,
"startvalue": value,
}
)

response = client.post(
"/stored_query/ephemeral/",
query,
content_type="application/json",
)

self.assertEqual(response.status_code, 200, response.content.decode())
self.assertEqual(
json.loads(response.content.decode()),
{"results": [[record_id, value]]},
)

def _fresh_session_context(self):
return type(self).test_session_context()

def _create_taxon(self):
item = models.Taxontreedefitem.objects.create(
treedef=self.taxontreedef, name="Species", rankid=1
)
return models.Taxon.objects.create(
name="Taxon A",
fullname="Taxon A",
rankid=1,
definition=self.taxontreedef,
definitionitem=item,
)

def _create_storage(self):
treedef = models.Storagetreedef.objects.create(name="Test storage")
item = models.Storagetreedefitem.objects.create(
treedef=treedef, name="Room", rankid=1
)
return models.Storage.objects.create(
name="Storage A",
fullname="Storage A",
rankid=1,
definition=treedef,
definitionitem=item,
)

def _create_preparation(self, barcode, guid):
preptype, _ = models.Preptype.objects.get_or_create(
name="Test PrepType", collection=self.collection
)
return models.Preparation.objects.create(
collectionmemberid=self.collection.id,
collectionobject=self.collectionobjects[2],
preptype=preptype,
barcode=barcode,
guid=guid,
)

def _create_exchange_in(self):
return models.Exchangein.objects.create(
division=self.division,
agentcatalogedby=self.agent,
agentreceivedfrom=self.agent,
exchangeinnumber="EXIN-1",
)

def _create_exchange_out(self):
return models.Exchangeout.objects.create(
division=self.division,
agentcatalogedby=self.agent,
agentsentto=self.agent,
exchangeoutnumber="EXOUT-1",
)

def _create_reference(self, title, guid):
return models.Referencework.objects.create(
institution=self.institution,
referenceworktype=0,
title=title,
guid=guid,
)

def _create_locality(self, uniqueidentifier, guid):
return models.Locality.objects.create(
discipline=self.discipline,
localityname="Locality A",
srclatlongunit=0,
uniqueidentifier=uniqueidentifier,
guid=guid,
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_taxon_by_full_name(self, session_context):
session_context.side_effect = self._fresh_session_context
taxon = self._create_taxon()
self._assert_path("Taxon", "fullName", "Taxon A", taxon.id)

@unittest.skip("Storage.fullName currently produces an empty SQL query")
@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_storage_by_full_name(self, session_context):
session_context.side_effect = self._fresh_session_context
storage = self._create_storage()
self._assert_path("Storage", "fullName", "Storage A", storage.id)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_collecting_event_by_guid(self, session_context):
session_context.side_effect = self._fresh_session_context
collectingevent = self.collectingevent
collectingevent.guid = "CE-GUID"
collectingevent.save()
self._assert_path(
"CollectingEvent", "guid", "CE-GUID", collectingevent.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_collecting_event_by_field_number(self, session_context):
session_context.side_effect = self._fresh_session_context
collectingevent = self.collectingevent
collectingevent.stationfieldnumber = "CE-FIELD"
collectingevent.save()
self._assert_path(
"CollectingEvent",
"stationFieldNumber",
"CE-FIELD",
collectingevent.id,
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_loan_by_loan_number(self, session_context):
session_context.side_effect = self._fresh_session_context
loan = models.Loan.objects.create(
discipline=self.discipline, loannumber="LOAN-1"
)
self._assert_path("Loan", "loanNumber", "LOAN-1", loan.id)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_accession_by_accession_number(self, session_context):
session_context.side_effect = self._fresh_session_context
accession = models.Accession.objects.create(
division=self.division, accessionnumber="ACC-1"
)
self._assert_path(
"Accession", "accessionNumber", "ACC-1", accession.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_gift_by_gift_number(self, session_context):
session_context.side_effect = self._fresh_session_context
gift = models.Gift.objects.create(
discipline=self.discipline, giftnumber="GIFT-1"
)
self._assert_path("Gift", "giftNumber", "GIFT-1", gift.id)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_preparation_by_barcode(self, session_context):
session_context.side_effect = self._fresh_session_context
preparation = self._create_preparation(
"PREP-BARCODE", "PREP-GUID-1"
)
self._assert_path(
"Preparation", "barCode", "PREP-BARCODE", preparation.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_preparation_by_guid(self, session_context):
session_context.side_effect = self._fresh_session_context
preparation = self._create_preparation(
"PREP-BARCODE-2", "PREP-GUID"
)
self._assert_path(
"Preparation", "guid", "PREP-GUID", preparation.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_treatment_event_by_field_number(self, session_context):
session_context.side_effect = self._fresh_session_context
treatment = models.Treatmentevent.objects.create(
fieldnumber="TREAT-1"
)
self._assert_path(
"TreatmentEvent", "fieldNumber", "TREAT-1", treatment.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_exchange_in_by_exchange_in_number(self, session_context):
session_context.side_effect = self._fresh_session_context
exchange = self._create_exchange_in()
self._assert_path(
"ExchangeIn", "exchangeInNumber", "EXIN-1", exchange.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_exchange_out_by_exchange_out_number(self, session_context):
session_context.side_effect = self._fresh_session_context
exchange = self._create_exchange_out()
self._assert_path(
"ExchangeOut", "exchangeOutNumber", "EXOUT-1", exchange.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_reference_work_by_title(self, session_context):
session_context.side_effect = self._fresh_session_context
reference = self._create_reference("Ref Title", "REF-GUID-1")
self._assert_path(
"ReferenceWork", "title", "Ref Title", reference.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_reference_work_by_guid(self, session_context):
session_context.side_effect = self._fresh_session_context
reference = self._create_reference("Ref Title 2", "REF-GUID-2")
self._assert_path(
"ReferenceWork", "guid", "REF-GUID-2", reference.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_locality_by_unique_identifier(self, session_context):
session_context.side_effect = self._fresh_session_context
locality = self._create_locality("LOC-1", "LOC-GUID-1")
self._assert_path(
"Locality", "uniqueIdentifier", "LOC-1", locality.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_locality_by_guid(self, session_context):
session_context.side_effect = self._fresh_session_context
locality = self._create_locality("LOC-2", "LOC-GUID-2")
self._assert_path(
"Locality", "guid", "LOC-GUID-2", locality.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_permit_by_permit_number(self, session_context):
session_context.side_effect = self._fresh_session_context
permit = models.Permit.objects.create(
institution=self.institution, permitnumber="PERMIT-1"
)
self._assert_path(
"Permit", "permitNumber", "PERMIT-1", permit.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_agent_by_guid(self, session_context):
session_context.side_effect = self._fresh_session_context
agent = self.agent
agent.guid = "AGENT-GUID"
agent.save()
self._assert_path("Agent", "guid", "AGENT-GUID", agent.id)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_collecting_trip_by_name(self, session_context):
session_context.side_effect = self._fresh_session_context
trip = models.Collectingtrip.objects.create(
discipline=self.discipline, collectingtripname="TRIP-1"
)
self._assert_path(
"CollectingTrip", "collectingTripName", "TRIP-1", trip.id
)

@patch("specifyweb.backend.stored_queries.execution.models.session_context")
def test_match_deaccession_by_deaccession_number(self, session_context):
session_context.side_effect = self._fresh_session_context
deaccession = models.Deaccession.objects.create(
deaccessionnumber="DEACC-1"
)
self._assert_path(
"Deaccession", "deaccessionNumber", "DEACC-1", deaccession.id
)
Loading