From 3b10653555394df9b09ca27f20ac6502b379ffcd Mon Sep 17 00:00:00 2001
From: mlbonhomme <bonhomme@teklia.com>
Date: Thu, 4 Nov 2021 11:51:59 +0000
Subject: [PATCH] Support text orientation in (partial) update transcription

---
 .../tests/test_edit_transcriptions.py         | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/arkindex/documents/tests/test_edit_transcriptions.py b/arkindex/documents/tests/test_edit_transcriptions.py
index ec1bc298d5..f153c36577 100644
--- a/arkindex/documents/tests/test_edit_transcriptions.py
+++ b/arkindex/documents/tests/test_edit_transcriptions.py
@@ -149,6 +149,88 @@ class TestEditTranscription(FixtureAPITestCase):
             'worker_version_id': None,
         })
 
+    def test_transcription_patch_orientation(self):
+        """
+        Assert it is possible to edit only the text orientation
+        """
+        self.client.force_login(self.user)
+        manual_tr_id = self.manual_transcription.id
+        response = self.client.patch(
+            reverse('api:transcription-edit', kwargs={'pk': manual_tr_id}),
+            format='json',
+            data={
+                'orientation': 'vertical-rl'
+            }
+        )
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        self.manual_transcription.refresh_from_db()
+        self.assertDictEqual(response.json(), {
+            'id': str(manual_tr_id),
+            'confidence': None,
+            'score': None,
+            'text': 'A manual transcription',
+            'orientation': 'vertical-rl',
+            'worker_version_id': None,
+        })
+
+    def test_transcription_patch_invalid_orientation(self):
+        """
+        An invalid text orientation value causes an error
+        """
+        self.client.force_login(self.user)
+        manual_tr_id = self.manual_transcription.id
+        response = self.client.patch(
+            reverse('api:transcription-edit', kwargs={'pk': manual_tr_id}),
+            format='json',
+            data={
+                'orientation': 'wobbly'
+            }
+        )
+        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+        self.assertEqual(response.json(), {'orientation': ['Value is not of type TextOrientation']})
+
+    def test_transcription_edit_orientation(self):
+        """
+        Assert it is possible to edit the text orientation with UpdateTranscription
+        """
+        self.client.force_login(self.user)
+        manual_tr_id = self.manual_transcription.id
+        response = self.client.put(
+            reverse('api:transcription-edit', kwargs={'pk': manual_tr_id}),
+            format='json',
+            data={
+                'text': 'a knight was living lonely',
+                'orientation': 'vertical-rl',
+            }
+        )
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        self.manual_transcription.refresh_from_db()
+        self.assertDictEqual(response.json(), {
+            'id': str(manual_tr_id),
+            'confidence': None,
+            'score': None,
+            'text': 'a knight was living lonely',
+            'orientation': 'vertical-rl',
+            'worker_version_id': None,
+        })
+
+    def test_transcription_edit_invalid_orientation(self):
+        """
+        An invalid text orientation value causes an error
+        """
+        self.client.force_login(self.user)
+        manual_tr_id = self.manual_transcription.id
+        response = self.client.put(
+            reverse('api:transcription-edit', kwargs={'pk': manual_tr_id}),
+            format='json',
+            data={
+                'text': 'a knight was living lonely',
+                'orientation': 'wobbly',
+            }
+        )
+        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+        self.assertEqual(response.json(), {'orientation': ['Value is not of type TextOrientation']})
+
     def test_transcription_patch_write_right(self):
         """
         A write right is required to patch a manual transcription
-- 
GitLab