-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Sync API tests for CaptionFile ViewSet
- Loading branch information
Showing
8 changed files
with
403 additions
and
64 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
contentcuration/contentcuration/constants/transcription_languages.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# This file contains a list of transcription languages. | ||
# The list is in the format of (language code, language name). | ||
# For example, the first element in the list is ('en', 'english'). | ||
|
||
|
||
CAPTIONS_LANGUAGES = [ | ||
("en", "english"), | ||
("zh", "chinese"), | ||
("de", "german"), | ||
("es", "spanish"), | ||
("ru", "russian"), | ||
("ko", "korean"), | ||
("fr", "french"), | ||
("ja", "japanese"), | ||
("pt", "portuguese"), | ||
("tr", "turkish"), | ||
("pl", "polish"), | ||
("ca", "catalan"), | ||
("nl", "dutch"), | ||
("ar", "arabic"), | ||
("sv", "swedish"), | ||
("it", "italian"), | ||
("id", "indonesian"), | ||
("hi", "hindi"), | ||
("fi", "finnish"), | ||
("vi", "vietnamese"), | ||
("he", "hebrew"), | ||
("uk", "ukrainian"), | ||
("el", "greek"), | ||
("ms", "malay"), | ||
("cs", "czech"), | ||
("ro", "romanian"), | ||
("da", "danish"), | ||
("hu", "hungarian"), | ||
("ta", "tamil"), | ||
("no", "norwegian"), | ||
("th", "thai"), | ||
("ur", "urdu"), | ||
("hr", "croatian"), | ||
("bg", "bulgarian"), | ||
("lt", "lithuanian"), | ||
("la", "latin"), | ||
("mi", "maori"), | ||
("ml", "malayalam"), | ||
("cy", "welsh"), | ||
("sk", "slovak"), | ||
("te", "telugu"), | ||
("fa", "persian"), | ||
("lv", "latvian"), | ||
("bn", "bengali"), | ||
("sr", "serbian"), | ||
("az", "azerbaijani"), | ||
("sl", "slovenian"), | ||
("kn", "kannada"), | ||
("et", "estonian"), | ||
("mk", "macedonian"), | ||
("br", "breton"), | ||
("eu", "basque"), | ||
("is", "icelandic"), | ||
("hy", "armenian"), | ||
("ne", "nepali"), | ||
("mn", "mongolian"), | ||
("bs", "bosnian"), | ||
("kk", "kazakh"), | ||
("sq", "albanian"), | ||
("sw", "swahili"), | ||
("gl", "galician"), | ||
("mr", "marathi"), | ||
("pa", "punjabi"), | ||
("si", "sinhala"), | ||
("km", "khmer"), | ||
("sn", "shona"), | ||
("yo", "yoruba"), | ||
("so", "somali"), | ||
("af", "afrikaans"), | ||
("oc", "occitan"), | ||
("ka", "georgian"), | ||
("be", "belarusian"), | ||
("tg", "tajik"), | ||
("sd", "sindhi"), | ||
("gu", "gujarati"), | ||
("am", "amharic"), | ||
("yi", "yiddish"), | ||
("lo", "lao"), | ||
("uz", "uzbek"), | ||
("fo", "faroese"), | ||
("ht", "haitian creole"), | ||
("ps", "pashto"), | ||
("tk", "turkmen"), | ||
("nn", "nynorsk"), | ||
("mt", "maltese"), | ||
("sa", "sanskrit"), | ||
("lb", "luxembourgish"), | ||
("my", "myanmar"), | ||
("bo", "tibetan"), | ||
("tl", "tagalog"), | ||
("mg", "malagasy"), | ||
("as", "assamese"), | ||
("tt", "tatar"), | ||
("haw", "hawaiian"), | ||
("ln", "lingala"), | ||
("ha", "hausa"), | ||
("ba", "bashkir"), | ||
("jw", "javanese"), | ||
("su", "sundanese"), | ||
] |
23 changes: 0 additions & 23 deletions
23
contentcuration/contentcuration/migrations/0143_caption.py
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
contentcuration/contentcuration/migrations/0143_captioncue_captionfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 3.2.14 on 2023-06-26 17:33 | ||
|
||
import contentcuration.models | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contentcuration', '0142_add_task_signature'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CaptionFile', | ||
fields=[ | ||
('id', contentcuration.models.UUIDField(default=uuid.uuid4, max_length=32, primary_key=True, serialize=False)), | ||
('file_id', contentcuration.models.UUIDField(default=uuid.uuid4, max_length=32)), | ||
('language', models.CharField(choices=[('en', 'english'), ('zh', 'chinese'), ('de', 'german'), ('es', 'spanish'), ('ru', 'russian'), ('ko', 'korean'), ('fr', 'french'), ('ja', 'japanese'), ('pt', 'portuguese'), ('tr', 'turkish'), ('pl', 'polish'), ('ca', 'catalan'), ('nl', 'dutch'), ('ar', 'arabic'), ('sv', 'swedish'), ('it', 'italian'), ('id', 'indonesian'), ('hi', 'hindi'), ('fi', 'finnish'), ('vi', 'vietnamese'), ('he', 'hebrew'), ('uk', 'ukrainian'), ('el', 'greek'), ('ms', 'malay'), ('cs', 'czech'), ('ro', 'romanian'), ('da', 'danish'), ('hu', 'hungarian'), ('ta', 'tamil'), ('no', 'norwegian'), ('th', 'thai'), ('ur', 'urdu'), ('hr', 'croatian'), ('bg', 'bulgarian'), ('lt', 'lithuanian'), ('la', 'latin'), ('mi', 'maori'), ('ml', 'malayalam'), ('cy', 'welsh'), ('sk', 'slovak'), ('te', 'telugu'), ('fa', 'persian'), ('lv', 'latvian'), ('bn', 'bengali'), ('sr', 'serbian'), ('az', 'azerbaijani'), ('sl', 'slovenian'), ('kn', 'kannada'), ('et', 'estonian'), ('mk', 'macedonian'), ('br', 'breton'), ('eu', 'basque'), ('is', 'icelandic'), ('hy', 'armenian'), ('ne', 'nepali'), ('mn', 'mongolian'), ('bs', 'bosnian'), ('kk', 'kazakh'), ('sq', 'albanian'), ('sw', 'swahili'), ('gl', 'galician'), ('mr', 'marathi'), ('pa', 'punjabi'), ('si', 'sinhala'), ('km', 'khmer'), ('sn', 'shona'), ('yo', 'yoruba'), ('so', 'somali'), ('af', 'afrikaans'), ('oc', 'occitan'), ('ka', 'georgian'), ('be', 'belarusian'), ('tg', 'tajik'), ('sd', 'sindhi'), ('gu', 'gujarati'), ('am', 'amharic'), ('yi', 'yiddish'), ('lo', 'lao'), ('uz', 'uzbek'), ('fo', 'faroese'), ('ht', 'haitian creole'), ('ps', 'pashto'), ('tk', 'turkmen'), ('nn', 'nynorsk'), ('mt', 'maltese'), ('sa', 'sanskrit'), ('lb', 'luxembourgish'), ('my', 'myanmar'), ('bo', 'tibetan'), ('tl', 'tagalog'), ('mg', 'malagasy'), ('as', 'assamese'), ('tt', 'tatar'), ('haw', 'hawaiian'), ('ln', 'lingala'), ('ha', 'hausa'), ('ba', 'bashkir'), ('jw', 'javanese'), ('su', 'sundanese')], max_length=3)), | ||
], | ||
options={ | ||
'unique_together': {('file_id', 'language')}, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='CaptionCue', | ||
fields=[ | ||
('id', contentcuration.models.UUIDField(default=uuid.uuid4, max_length=32, primary_key=True, serialize=False)), | ||
('text', models.TextField()), | ||
('starttime', models.FloatField()), | ||
('endtime', models.FloatField()), | ||
('caption_file', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='caption_cue', to='contentcuration.captionfile')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
contentcuration/contentcuration/tests/viewsets/test_caption.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
from __future__ import absolute_import | ||
|
||
import uuid | ||
|
||
from django.urls import reverse | ||
|
||
from contentcuration.models import CaptionCue, CaptionFile | ||
from contentcuration.tests.base import StudioAPITestCase | ||
from contentcuration.tests import testdata | ||
from contentcuration.tests.viewsets.base import SyncTestMixin | ||
from contentcuration.tests.viewsets.base import generate_create_event | ||
from contentcuration.tests.viewsets.base import generate_update_event | ||
from contentcuration.tests.viewsets.base import generate_delete_event | ||
from contentcuration.viewsets.sync.constants import CAPTION_FILE | ||
|
||
# class CRUDTestCase(StudioAPITestCase): | ||
|
||
class SyncTestCase(SyncTestMixin, StudioAPITestCase): | ||
|
||
@property | ||
def caption_file_metadata(self): | ||
return { | ||
"file_id": uuid.uuid4().hex, | ||
"language": "en", | ||
} | ||
|
||
@property | ||
def same_file_different_language_metadata(self): | ||
id = uuid.uuid4().hex | ||
return [ | ||
{ | ||
"file_id": id, | ||
"language": "en", | ||
}, | ||
{ | ||
"file_id": id, | ||
"language": "ru", | ||
} | ||
] | ||
|
||
@property | ||
def caption_file_db_metadata(self): | ||
return { | ||
"file_id": uuid.uuid4().hex, | ||
"language": "en", | ||
} | ||
|
||
|
||
def setUp(self): | ||
super(SyncTestCase, self).setUp() | ||
self.channel = testdata.channel() | ||
self.user = testdata.user() | ||
self.channel.editors.add(self.user) | ||
|
||
|
||
def test_create_caption(self): | ||
self.client.force_authenticate(user=self.user) | ||
caption_file = self.caption_file_metadata | ||
|
||
response = self.sync_changes( | ||
[ | ||
generate_create_event( | ||
uuid.uuid4().hex, | ||
CAPTION_FILE, | ||
caption_file, | ||
channel_id=self.channel.id, | ||
) | ||
], | ||
) | ||
self.assertEqual(response.status_code, 200, response.content) | ||
|
||
try: | ||
caption_file_db = CaptionFile.objects.get( | ||
file_id=caption_file["file_id"], | ||
language=caption_file["language"], | ||
) | ||
except CaptionFile.DoesNotExist: | ||
self.fail("caption file was not created") | ||
|
||
# Check the values of the object in the PostgreSQL | ||
self.assertEqual(caption_file_db.file_id, caption_file["file_id"]) | ||
self.assertEqual(caption_file_db.language, caption_file["language"]) | ||
|
||
def test_delete_caption_file(self): | ||
self.client.force_authenticate(user=self.user) | ||
caption_file = self.caption_file_metadata | ||
pk = uuid.uuid4().hex | ||
response = self.sync_changes( | ||
[ | ||
generate_create_event( | ||
pk, | ||
CAPTION_FILE, | ||
caption_file, | ||
channel_id=self.channel.id | ||
) | ||
] | ||
) | ||
self.assertEqual(response.status_code, 200, response.content) | ||
|
||
# Delete the caption file | ||
response = self.sync_changes( | ||
[ | ||
generate_delete_event( | ||
pk, | ||
CAPTION_FILE, | ||
channel_id=self.channel.id | ||
) | ||
] | ||
) | ||
|
||
self.assertEqual(response.status_code, 200, response.content) | ||
|
||
with self.assertRaises(CaptionFile.DoesNotExist): | ||
caption_file_db = CaptionFile.objects.get( | ||
file_id=caption_file['file_id'], | ||
language=caption_file['language'] | ||
) | ||
|
||
|
||
def test_delete_file_with_same_file_id_different_language(self): | ||
self.client.force_authenticate(user=self.user) | ||
obj = self.same_file_different_language_metadata | ||
|
||
caption_file_1 = CaptionFile.objects.create( | ||
**obj[0] | ||
) | ||
caption_file_2 = CaptionFile.objects.create( | ||
**obj[1] | ||
) | ||
|
||
response = self.sync_changes( | ||
[ | ||
generate_delete_event( | ||
caption_file_2.pk, | ||
CAPTION_FILE, | ||
channel_id=self.channel.id, | ||
) | ||
] | ||
) | ||
|
||
self.assertEqual(response.status_code, 200, response.content) | ||
|
||
with self.assertRaises(CaptionFile.DoesNotExist): | ||
caption_file_db = CaptionFile.objects.get( | ||
file_id=caption_file_2.file_id, | ||
language=caption_file_2.language | ||
) |
Oops, something went wrong.