Skip to content

Commit

Permalink
ZO-4649: update test to and use article example that actually can get…
Browse files Browse the repository at this point in the history
… a checksum calculate

somalia article has no division element and this element is required to calculate a realistic checksum, after checkin the somalia article gets the element therefore we have another checksum after that even though we not changed the article
  • Loading branch information
stollero committed Feb 7, 2024
1 parent 881e655 commit 34ecd6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
12 changes: 6 additions & 6 deletions core/src/zeit/speech/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
TTS_CREATION_STARTED = {
'event': 'AUDIO_CREATION_STARTED',
'uuid': 'a89ce2e3-4887-466a-a52e-edc6b9802ef9',
'checksum': 'd751713988987e9331980363e24189ce',
'checksum': '54436411ba2288d0db073246c85e0f09',
}

TTS_CREATION_FAILED = {
'event': 'AUDIO_CREATION_FAILED',
'uuid': 'a89ce2e3-4887-466a-a52e-edc6b9802ef9',
'checksum': 'd751713988987e9331980363e24189ce',
'checksum': '54436411ba2288d0db073246c85e0f09',
'reason': 'AudioStream must be a Buffer',
}

Expand All @@ -40,7 +40,7 @@
'articlesAudio': [
{
'type': 'FULL_TTS',
'checksum': 'd751713988987e9331980363e24189ce',
'checksum': '54436411ba2288d0db073246c85e0f09',
'audioEntry': {
'uuid': 'e7fba272-c442-4cde-a5c9-3d75a89e5273',
'url': 'https://zon-speechbert/articles/a89ce2e3-4887-466a-a52e-edc6b9802ef9/full_1fd74183d02f50d5cd0731a5748019e95bbe68bd71f33cbd2c03c4d64c8a1d91a7f25f6725db6b19348bd94af09fc563.mp3',
Expand All @@ -49,7 +49,7 @@
},
{
'type': 'PREVIEW_TTS',
'checksum': 'd751713988987e9331980363e24189ce',
'checksum': '54436411ba2288d0db073246c85e0f09',
'audioEntry': {
'uuid': '58ff08f4-cef5-45eb-a980-064bd78c42df',
'url': 'https://zon-speechbert/articles/a89ce2e3-4887-466a-a52e-edc6b9802ef9/preview_1fd74183d02f50d5cd0731a5748019e95bbe68bd71f33cbd2c03c4d64c8a1d91a7f25f6725db6b19348bd94af09fc563.mp3',
Expand Down Expand Up @@ -83,8 +83,8 @@ def setUp(self):
self.unique_id = (
f'http://xml.zeit.de/tts/{current_date.strftime("%Y-%m")}/{TTS_CREATED["uuid"]}'
)
self.article = ICMSContent('http://xml.zeit.de/online/2007/01/Somalia')
self.article_uid = 'http://xml.zeit.de/online/2007/01/Somalia'
self.article_uid = 'http://xml.zeit.de/online/2022/08/trockenheit'
self.article = ICMSContent(self.article_uid)
IPublishInfo(self.article).urgent = True
IPublish(self.article).publish(background=False)

Expand Down
20 changes: 9 additions & 11 deletions core/src/zeit/speech/tests/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from unittest import mock
import copy

import pytest
import zope.security.management
Expand Down Expand Up @@ -32,28 +31,27 @@ def test_message_audio_created(self):
)
assert IPublishInfo(audio).published, 'Publish you fool!'

def _setup_speech_message(self, field, value):
tts_created = copy.deepcopy(TTS_CREATED)
tts_created['articlesAudio'][0][field] = value
return tts_created

def test_update_existing_tts_audio(self):
audio = self.create_audio(TTS_CREATED)
created_time = ISemanticChange(audio).last_semantic_change
assert ISpeechInfo(audio).checksum == TTS_CREATED['articlesAudio'][0]['checksum']
self.repository.connector.search_result = [(audio.uniqueId)]
tts_msg = self.setup_speech_message('checksum', 'cookiesandcake')
Speech().update(tts_msg)
self.repository.connector.search_result = [(self.article.uniqueId)]
tts_msg = self.setup_speech_message(
'audioEntry', {'url': 'http://example.com/cats.mp3', 'duration': 1000}
)
with mock.patch('zeit.speech.connection.Speech._find', return_value=audio):
Speech().update(tts_msg)
updated_time = ISemanticChange(audio).last_semantic_change
assert updated_time > created_time, 'Semantic time should be updated'
assert ISpeechInfo(audio).checksum == 'cookiesandcake', 'Update your checksum'
audio = ICMSContent(self.unique_id)
assert audio.duration == 1

def test_update_broken_audio_repairs_reference_to_article(self):
self.repository.connector.search_result = [(self.article.uniqueId)]
audio = Speech()._create(TTS_CREATED)
IPublish(audio).publish(background=False)
assert ICMSContent(self.unique_id)
assert not IAudioReferences(ICMSContent(self.article_uid)).items
self.repository.connector.search_result = [(self.article.uniqueId)]
with mock.patch('zeit.speech.connection.Speech._find', return_value=audio):
Speech().update(TTS_CREATED)
assert IAudioReferences(ICMSContent(self.article_uid)).items == (audio,)
Expand Down

0 comments on commit 34ecd6f

Please sign in to comment.