-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AMI-268] Enable comments field when suggesting ID (#376)
* Add support the comments field when suggesting an ID
- Loading branch information
Showing
10 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ def setUp(self): | |
self.job = Job.objects.create(project=self.project, name="Test job", delay=0) | ||
self.user = User.objects.create_user( # type: ignore | ||
email="[email protected]", | ||
is_staff=True, | ||
) | ||
self.factory = APIRequestFactory() | ||
|
||
|
@@ -99,7 +100,6 @@ def test_run_job(self): | |
jobs_run_url = reverse_with_params("api:job-run", args=[self.job.pk], params={"no_async": True}) | ||
self.client.force_authenticate(user=self.user) | ||
resp = self.client.post(jobs_run_url) | ||
self.client.force_authenticate(user=None) | ||
self.assertEqual(resp.status_code, 200) | ||
data = resp.json() | ||
self.assertEqual(data["id"], self.job.pk) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2.2 on 2024-04-16 18:56 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("main", "0029_alter_deployment_device_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="identification", | ||
name="comment", | ||
field=models.TextField(blank=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
from django.db import connection | ||
from django.test import TestCase | ||
from rest_framework.test import APIRequestFactory, APITestCase | ||
from rich import print | ||
|
||
from ami.main.models import ( | ||
|
@@ -17,6 +18,7 @@ | |
TaxonRank, | ||
group_images_into_events, | ||
) | ||
from ami.users.models import User | ||
|
||
|
||
def setup_test_project(reuse=True) -> tuple[Project, Deployment]: | ||
|
@@ -547,3 +549,51 @@ def test_taxon_detail(self): | |
response = self.client.get(f"/api/v2/taxa/{taxon.pk}/") | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json()["name"], taxon.name) | ||
|
||
|
||
class TestIdentification(APITestCase): | ||
def setUp(self) -> None: | ||
project, deployment = setup_test_project() | ||
create_taxa(project=project) | ||
create_captures(deployment=deployment) | ||
group_images_into_events(deployment=deployment) | ||
create_occurrences(deployment=deployment, num=5) | ||
self.project = project | ||
self.user = User.objects.create_user( # type: ignore | ||
email="[email protected]", | ||
is_staff=True, | ||
) | ||
self.factory = APIRequestFactory() | ||
self.client.force_authenticate(user=self.user) | ||
return super().setUp() | ||
|
||
def test_identification(self): | ||
from ami.main.models import Identification, Taxon | ||
|
||
""" | ||
Post a new identification suggestion and check that it changed the occurrence's determination. | ||
""" | ||
|
||
suggest_id_endpoint = "/api/v2/identifications/" | ||
taxa = Taxon.objects.filter(projects=self.project) | ||
assert taxa.count() > 1 | ||
|
||
occurrence = Occurrence.objects.filter(project=self.project).exclude(determination=None)[0] | ||
original_taxon = occurrence.determination | ||
assert original_taxon is not None | ||
new_taxon = Taxon.objects.exclude(pk=original_taxon.pk)[0] | ||
comment = "Test identification comment" | ||
|
||
response = self.client.post( | ||
suggest_id_endpoint, | ||
{ | ||
"occurrence_id": occurrence.pk, | ||
"taxon_id": new_taxon.pk, | ||
"comment": comment, | ||
}, | ||
) | ||
self.assertEqual(response.status_code, 201) | ||
occurrence.refresh_from_db() | ||
self.assertEqual(occurrence.determination, new_taxon) | ||
identification = Identification.objects.get(pk=response.json()["id"]) | ||
self.assertEqual(identification.comment, comment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters