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 committed May 26, 2023
1 parent 101acd2 commit 0eff4f6
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 @@ -1121,7 +1121,7 @@ def setUp(self):
"existing_annotator1": {
"sentiment": "positive"
},
f"2": {
f"{self.annotators[0].pk}": {
"sentiment": "positive"
}

Expand All @@ -1142,8 +1142,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 @@ -1250,9 +1250,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 @@ -1288,7 +1288,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 @@ -1300,6 +1300,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 @@ -1309,6 +1313,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 @@ -1318,6 +1326,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 @@ -1327,6 +1339,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 0eff4f6

Please sign in to comment.