Example #1
0
    def _ayah_response(self, response):
        ayah_response = ayah_proto.AyahResponse(ayah=entity_proto.AyahEntity(
            **response.ayah.to_dict()))

        if response.translation:
            ayah_response.translation.MergeFrom(
                entity_proto.TranslationEntity(
                    **response.translation.to_dict()))
        if response.surah:
            ayah_response.surah.MergeFrom(
                entity_proto.SurahEntity(**response.surah.to_dict()))
        if response.edition:
            ayah_response.edition.MergeFrom(
                entity_proto.EditionEntity(**response.edition.to_dict()))
        if response.arabic_audio:
            ayah_response.arabic_audio.MergeFrom(
                entity_proto.AudioEntity(**response.arabic_audio.to_dict()))
        if response.translation_audio:
            ayah_response.translation_audio.MergeFrom(
                entity_proto.AudioEntity(
                    **response.translation_audio.to_dict()))
        if response.ayah_image:
            ayah_response.image.MergeFrom(
                entity_proto.ImageEntity(**response.ayah_image.to_dict()))

        return ayah_response
Example #2
0
def test_create_audio():
    audio = entity_proto.AudioEntity(id='audio-1',
                                     ayah_id='ayah-1',
                                     edition_id='edition-1',
                                     type='Arabic',
                                     audio='audio link for arabic 1')
    res = stub.CreateAudio(audio)

    assert ProtoConverter.proto_to_dict(
        res.data.audio) == ProtoConverter.proto_to_dict(audio)
Example #3
0
def test_find_translation_audio():
    audio = entity_proto.AudioEntity(id='audio-2',
                                     ayah_id='ayah-1',
                                     edition_id='edition-1',
                                     type='Translation',
                                     audio='audio link for translation 1')
    stub.CreateAudio(audio)

    res = stub.FindTranslationAudio(
        shared_entity.FilterRequest(ayah_id='ayah-1', edition_id='edition-1'))

    assert res.data.audio.ayah_id == 'ayah-1'
    assert res.data.audio.edition_id == 'edition-1'
    assert res.data.audio.type == 'Translation'
Example #4
0
    def FindArabicAudio(self, request, context):
        find_audio = AudioFactory.find_audio()
        res = find_audio.arabic_audio(ayah_id=request.ayah_id,
                                      edition_id=request.edition_id)
        if res is None:
            return audio_proto.AudioSingleResponse(code=404,
                                                   status='Not Found')

        audio_entity = entity_proto.AudioEntity(**res.audio.to_dict())
        audio_data = audio_proto.AudioSingleData(
            audio=audio_entity, number_of_results=res.number_of_results)
        return audio_proto.AudioSingleResponse(code=200,
                                               status='OK',
                                               data=audio_data)
Example #5
0
    def FindAudioByAyahId(self, request, context):
        find_audio = AudioFactory.find_audio()
        audio_entities = []
        res = find_audio.by_ayah_id(request.id, request.limit, request.cursor)
        for audio in res.audio_list:
            audio_entities.append(entity_proto.AudioEntity(**audio.to_dict()))

        if len(audio_entities) == 0:
            return audio_proto.AudioMultiResponse(code=404, status='Not Found')

        audio_data = audio_proto.AudioMultiData(
            audio=audio_entities,
            number_of_results=res.number_of_results,
            cursor=res.cursor)
        return audio_proto.AudioMultiResponse(code=200,
                                              status='OK',
                                              data=audio_data)