Skip to content
Snippets Groups Projects
Verified Commit 7a18fc98 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Fix tests

parent 5c8227c2
No related branches found
No related tags found
No related merge requests found
......@@ -131,7 +131,7 @@ class TranscriptionEdit(RetrieveUpdateDestroyAPIView):
errors = defaultdict(list)
if Right.Write not in rights:
errors['__all__'].append('A write access to transcription element corpus is required.')
if Right.Admin not in rights and not transcription.worker_version_id:
if Right.Admin not in rights and transcription.worker_version_id:
errors['__all__'].append('Only admins can edit non-manual transcription.')
if (errors):
raise PermissionDenied(errors)
......
......@@ -240,7 +240,7 @@ class TestClasses(FixtureAPITestCase):
for elt in data['results']:
self.assertCountEqual(
list(map(lambda c: (c['worker_version'], c['confidence']), elt['best_classes'])),
[(str(self.version2.id), .99), ('test', .99)]
[(str(self.version1.id), .99), (str(self.version2.id), .99)]
)
def test_list_elements_best_classes_false(self):
......@@ -390,7 +390,6 @@ class TestClasses(FixtureAPITestCase):
self.populate_classified_elements()
element = Element.objects.filter(type=self.classified.id).first()
element.classifications.create(
worker_version=self.version1,
ml_class=self.text,
confidence=.1337,
high_confidence=True,
......
......@@ -591,10 +591,11 @@ class TestEntitiesAPI(FixtureAPITestCase):
md = self.element.metadatas.create(name='some_metadata', type=MetaType.Location, value='something')
md.entity = self.entity_bis
md.save()
with self.assertNumQueries(9):
with self.assertNumQueries(6):
response = self.client.get(reverse('api:element-entities', kwargs={'pk': str(self.element.id)}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
self.maxDiff = None
self.assertDictEqual(
data,
{
......@@ -609,7 +610,7 @@ class TestEntitiesAPI(FixtureAPITestCase):
'metas': None,
'validated': t.entity.validated,
'dates': [],
'worker_version_id': str(self.worker_version_1.id),
'worker_version_id': str(self.worker_version_2.id),
},
'offset': t.offset,
'length': t.length
......@@ -622,7 +623,7 @@ class TestEntitiesAPI(FixtureAPITestCase):
'metas': None,
'validated': m.entity.validated,
'dates': [],
'worker_version_id': str(self.worker_version_1.id),
'worker_version_id': str(m.entity.worker_version_id),
},
'id': str(m.id),
'type': m.type.value,
......
......@@ -261,7 +261,10 @@ class TestClasses(FixtureAPITestCase):
self.assertEqual(classification.moderator, self.user)
def test_classification_validate_without_permissions(self):
classification = self._create_classification_from_source()
classification = self.element.classifications.create(
ml_class=self.text,
confidence=.5,
)
with self.assertNumQueries(0):
response = self.client.put(reverse('api:classification-validate', kwargs={'pk': classification.id}))
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
......@@ -274,7 +277,7 @@ class TestClasses(FixtureAPITestCase):
confidence=.1,
)
with self.assertNumQueries(6):
with self.assertNumQueries(5):
response = self.client.put(reverse('api:classification-reject', kwargs={'pk': classification.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
......@@ -316,13 +319,16 @@ class TestClasses(FixtureAPITestCase):
def test_classification_can_still_be_moderated(self):
self.client.force_login(self.user)
classification = self._create_classification_from_source()
classification.moderator = self.user
classification.state = ClassificationState.Validated.value
classification.save()
classification = self.element.classifications.create(
ml_class=self.text,
confidence=.5,
moderator=self.user,
state=ClassificationState.Validated,
worker_version=self.worker_version_2,
)
# First try to reject
with self.assertNumQueries(6):
with self.assertNumQueries(5):
response = self.client.put(reverse('api:classification-reject', kwargs={'pk': classification.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
......@@ -335,11 +341,11 @@ class TestClasses(FixtureAPITestCase):
'state': ClassificationState.Rejected.value,
'confidence': classification.confidence,
'high_confidence': False,
'worker_version': None
'worker_version': str(self.worker_version_2.id),
})
# Then try to validate
with self.assertNumQueries(6):
with self.assertNumQueries(5):
response = self.client.put(reverse('api:classification-validate', kwargs={'pk': classification.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
......@@ -352,7 +358,7 @@ class TestClasses(FixtureAPITestCase):
'state': ClassificationState.Validated.value,
'confidence': classification.confidence,
'high_confidence': False,
'worker_version': None
'worker_version': str(self.worker_version_2.id)
})
def test_classification_selection_requires_login(self):
......@@ -457,7 +463,7 @@ class TestClasses(FixtureAPITestCase):
[str(self.element.id), str(self.folder.id), str(act_x.id), str(act_y.id)],
)
with self.assertNumQueries(14):
with self.assertNumQueries(10):
response = self.client.post(
reverse('api:classification-selection'),
data={'corpus_id': self.corpus.id, 'ml_class': self.text.id, 'mode': 'create'}
......
......@@ -24,7 +24,8 @@ class TestTranscriptions(FixtureAPITestCase):
cls.private_read_user = User.objects.create_user('a@bc.de', 'a')
cls.private_read_user.verified_email = True
cls.private_read_user.save()
cls.worker_version = WorkerVersion.objects.get(worker__slug='reco')
cls.worker_version_1 = WorkerVersion.objects.get(worker__slug='reco')
cls.worker_version_2 = WorkerVersion.objects.get(worker__slug='dla')
def test_list_transcriptions_read_right(self):
# A read right on the element corpus is required to access transcriptions
......@@ -37,7 +38,7 @@ class TestTranscriptions(FixtureAPITestCase):
tr1 = self.page.transcriptions.get()
tr2 = self.page.transcriptions.create(
text='something',
worker_version=self.worker_version,
worker_version=self.worker_version_2,
score=0.369,
)
self.client.force_login(self.user)
......@@ -51,14 +52,14 @@ class TestTranscriptions(FixtureAPITestCase):
'id': str(tr1.id),
'text': 'Lorem ipsum dolor sit amet',
'score': 1.0,
'worker_version_id': None,
'worker_version_id': str(self.worker_version_1.id),
'element': None,
},
{
'id': str(tr2.id),
'text': 'something',
'score': 0.369,
'worker_version_id': str(self.worker_version.id),
'worker_version_id': str(self.worker_version_2.id),
'element': None,
}
])
......@@ -88,7 +89,7 @@ class TestTranscriptions(FixtureAPITestCase):
def test_list_worker_version_transcriptions(self):
worker_transcription = self.page.transcriptions.create(
text='something',
worker_version=self.worker_version,
worker_version=self.worker_version_2,
score=0.369,
)
......@@ -97,7 +98,7 @@ class TestTranscriptions(FixtureAPITestCase):
with self.assertNumQueries(12):
response = self.client.get(
reverse('api:element-transcriptions', kwargs={'pk': str(self.page.id)}),
data={'recursive': 'true', 'worker_version': str(self.worker_version.id)}
data={'recursive': 'true', 'worker_version': str(self.worker_version_2.id)}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
......@@ -106,7 +107,7 @@ class TestTranscriptions(FixtureAPITestCase):
'id': str(worker_transcription.id),
'text': 'something',
'score': 0.369,
'worker_version_id': str(self.worker_version.id),
'worker_version_id': str(self.worker_version_2.id),
'element': {
'id': str(self.page.id),
'name': 'Volume 1, page 1r',
......
......@@ -60,7 +60,7 @@ class TestESDocuments(FixtureAPITestCase):
surface.add_parent(page)
surface.transcriptions.create(
text='invisible transcription',
source=WorkerVersion.objects.get(worker__slug='reco'),
worker_version=WorkerVersion.objects.get(worker__slug='reco'),
)
texts = [tr['text'] for tr in ESElement.from_model(page).to_dict()['transcriptions']]
self.assertNotIn('invisible transcription', texts)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment