Skip to content

Commit

Permalink
Fixed implementation of export tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twinkarma authored and ianroberts committed Feb 26, 2024
1 parent b94e22d commit 3350bd8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions backend/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ def setUp(self):
"existing_annotator1": {
"sentiment": "positive"
},
f"2": {
f"{self.annotators[0].pk}": {
"sentiment": "positive"
}

Expand All @@ -1144,8 +1144,8 @@ def setUp(self):
],
"next_annid": 1
},
f"{settings.ANONYMIZATION_PREFIX}2": {
"name": f"{settings.ANONYMIZATION_PREFIX}1",
f"{settings.ANONYMIZATION_PREFIX}{self.annotators[0].pk}": {
"name": f"{settings.ANONYMIZATION_PREFIX}{self.annotators[0].pk}",
"annotations": [
{
"type": "Document",
Expand Down Expand Up @@ -1254,9 +1254,9 @@ def test_export_gate_with_no_offset_type(self):
self.assertEqual(doc_dict["offset_type"], "p", "offset_type should default to p")


def check_raw_gate_annotation_formatting(self, doc_dict):
def check_raw_gate_annotation_formatting(self, doc_dict: dict):
self.assertTrue("annotation_sets" in doc_dict)
self.assertEqual(len(doc_dict["annotation_sets"]), 4)
self.assertEqual(len(doc_dict["annotation_sets"]), 4, doc_dict)

# Test annotation formatting
for aset_key, aset_data in doc_dict["annotation_sets"].items():
Expand Down Expand Up @@ -1304,7 +1304,7 @@ def test_export_csv(self):
self.assertTrue("feature2" in doc_dict)
self.assertTrue("feature3" in doc_dict)
self.assertTrue("annotations" in doc_dict)
self.assertEqual(len(doc_dict["annotations"]), 4)
self.assertEqual(len(doc_dict["annotations"]), 4, doc_dict)
anno_set_dict = doc_dict["annotations"]
for set_key in anno_set_dict:
if set_key != "existing_annotator1":
Expand All @@ -1318,6 +1318,10 @@ def test_export_csv(self):
def test_export_raw_anonymized(self):

for document in self.project.documents.all():
# Mask any existing annotations that came with the document upload
document.data.pop("annotation_sets")
document.save()

doc_dict = document.get_doc_annotation_dict("raw", anonymize=True)

for aset_key, aset_data in doc_dict["annotation_sets"].items():
Expand All @@ -1329,6 +1333,10 @@ def test_export_raw_anonymized(self):
def test_export_raw_deanonymized(self):

for document in self.project.documents.all():
# Mask any existing annotations that came with the document upload
document.data.pop("annotation_sets")
document.save()

doc_dict = document.get_doc_annotation_dict("raw", anonymize=False)

for aset_key, aset_data in doc_dict["annotation_sets"].items():
Expand All @@ -1342,6 +1350,10 @@ def test_export_raw_deanonymized(self):
def test_export_gate_anonymized(self):

for document in self.project.documents.all():
# Mask any existing annotations that came with the document upload
document.data.pop("annotation_sets")
document.save()

doc_dict = document.get_doc_annotation_dict("gate", anonymize=True)

for aset_key, aset_data in doc_dict["annotation_sets"].items():
Expand All @@ -1353,6 +1365,10 @@ def test_export_gate_anonymized(self):
def test_export_gate_deanonymized(self):

for document in self.project.documents.all():
# Mask any existing annotations that came with the document upload
document.data.pop("annotation_sets")
document.save()

doc_dict = document.get_doc_annotation_dict("gate", anonymize=False)

for aset_key, aset_data in doc_dict["annotation_sets"].items():
Expand Down

0 comments on commit 3350bd8

Please sign in to comment.