|
|
@ -682,7 +682,9 @@ class TestUploader(APITestCase): |
|
|
|
users=[super_user], project_type=SEQUENCE_LABELING) |
|
|
|
cls.seq2seq_project = mommy.make('server.Seq2seqProject', users=[super_user], project_type=SEQ2SEQ) |
|
|
|
cls.classification_url = reverse(viewname='doc_uploader', args=[cls.classification_project.id]) |
|
|
|
cls.classification_labels_url = reverse(viewname='label_list', args=[cls.classification_project.id]) |
|
|
|
cls.labeling_url = reverse(viewname='doc_uploader', args=[cls.labeling_project.id]) |
|
|
|
cls.labeling_labels_url = reverse(viewname='label_list', args=[cls.labeling_project.id]) |
|
|
|
cls.seq2seq_url = reverse(viewname='doc_uploader', args=[cls.seq2seq_project.id]) |
|
|
|
|
|
|
|
def setUp(self): |
|
|
@ -694,6 +696,14 @@ class TestUploader(APITestCase): |
|
|
|
response = self.client.post(url, data={'file': f, 'format': format}) |
|
|
|
self.assertEqual(response.status_code, expected_status) |
|
|
|
|
|
|
|
def label_test_helper(self, url, expected_labels): |
|
|
|
expected_keys = {key for label in expected_labels for key in label} |
|
|
|
|
|
|
|
actual_labels = [{key: value for (key, value) in label.items() if key in expected_keys} |
|
|
|
for label in self.client.get(url).json()] |
|
|
|
|
|
|
|
self.assertCountEqual(actual_labels, expected_labels) |
|
|
|
|
|
|
|
def test_can_upload_conll_format_file(self): |
|
|
|
self.upload_test_helper(url=self.labeling_url, |
|
|
|
filename='labeling.conll', |
|
|
@ -736,12 +746,23 @@ class TestUploader(APITestCase): |
|
|
|
format='json', |
|
|
|
expected_status=status.HTTP_201_CREATED) |
|
|
|
|
|
|
|
self.label_test_helper(self.classification_labels_url, expected_labels=[ |
|
|
|
{'text': 'positive'}, |
|
|
|
{'text': 'negative'}, |
|
|
|
]) |
|
|
|
|
|
|
|
def test_can_upload_labeling_jsonl(self): |
|
|
|
self.upload_test_helper(url=self.labeling_url, |
|
|
|
filename='labeling.jsonl', |
|
|
|
format='json', |
|
|
|
expected_status=status.HTTP_201_CREATED) |
|
|
|
|
|
|
|
self.label_test_helper(self.labeling_labels_url, expected_labels=[ |
|
|
|
{'text': 'LOC'}, |
|
|
|
{'text': 'ORG'}, |
|
|
|
{'text': 'PER'}, |
|
|
|
]) |
|
|
|
|
|
|
|
def test_can_upload_seq2seq_jsonl(self): |
|
|
|
self.upload_test_helper(url=self.seq2seq_url, |
|
|
|
filename='seq2seq.jsonl', |
|
|
|