Exemplo n.º 1
0
def test_create_translation():
    translation = entity_proto.TranslationEntity(id='translation-1', ayah_id='ayah-1', edition_id='edition-1',
                                                 text='translation text')

    res = stub.CreateTranslation(translation)

    assert ProtoConverter.proto_to_dict(res.data.translation) == ProtoConverter.proto_to_dict(translation)
Exemplo n.º 2
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
Exemplo n.º 3
0
    def FindTranslationById(self, request, context):
        find_translation = TranslationFactory.find_translation()
        res = find_translation.by_id(request.id)

        if res is None:
            return translation_proto.TranslationSingleResponse(
                code=404, status='Not Found')

        trans_entity = entity_proto.TranslationEntity(
            **res.translation.to_dict())
        trans_data = translation_proto.TranslationSingleData(
            translation=trans_entity, number_of_results=res.number_of_results)
        return translation_proto.TranslationSingleResponse(code=200,
                                                           status='OK',
                                                           data=trans_data)
Exemplo n.º 4
0
    def FindTranslationByEditionId(self, request, context):
        find_translation = TranslationFactory.find_translation()
        translation_stream = find_translation.by_edition_id(
            request.id, request.limit, request.cursor)
        translations = []
        for translation in translation_stream.translation_list:
            translations.append(
                entity_proto.TranslationEntity(**translation.to_dict()))

        if len(translations) == 0:
            return translation_proto.TranslationMultiResponse(
                code=200, status='Not Found')

        trans_data = translation_proto.TranslationMultiData(
            translation=translations,
            number_of_results=translation_stream.number_of_results,
            cursor=translation_stream.cursor)
        return translation_proto.TranslationMultiResponse(code=200,
                                                          status='OK',
                                                          data=trans_data)