Beispiel #1
0
def test_create_surah():
    surah = entity_proto.SurahEntity(
        id='surah-1',
        number=1,
        name='surah-name-1',
        english_name='english-name-1',
        english_name_translation='english-translation-name-1',
        number_of_ayahs=7,
        revelation_type='type-1')
    res = stub.CreateSurah(surah)
    assert res.data.surah.id == surah.id
    assert res.data.surah.number == surah.number
    assert res.data.surah.english_name_translation == surah.english_name_translation.title(
    )
    assert res.data.surah.name == surah.name.title()

    surah = entity_proto.SurahEntity(
        id='surah-2',
        number=2,
        name='surah-name-2',
        english_name='english-name-2',
        english_name_translation='english-translation-name-2',
        number_of_ayahs=144,
        revelation_type='type-2')
    res = stub.CreateSurah(surah)
    assert res.data.surah.id == surah.id
    assert res.data.surah.number == surah.number
    assert res.data.surah.english_name_translation == surah.english_name_translation.title(
    )
    assert res.data.surah.name == surah.name.title()
Beispiel #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
Beispiel #3
0
    def FindSurahByEnglishNameTranslation(self, request, context):
        find_surah = SurahFactory.find_surah()
        res = find_surah.by_english_name_translation(request.name)

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

        surah_entity = entity_proto.SurahEntity(**res.surah.to_dict())
        surah_data = surah_proto.SurahSingleData(surah=surah_entity,
                                                 number_of_results=1)
        return surah_proto.SurahSingleResponse(code=200,
                                               status='OK',
                                               data=surah_data)
Beispiel #4
0
    def FindSurahByNumber(self, request, context):
        find_surah = SurahFactory.find_surah()
        res = find_surah.by_number(request.number)

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

        surah_entity = entity_proto.SurahEntity(**res.surah.to_dict())
        surah_data = surah_proto.SurahSingleData(
            surah=surah_entity, number_of_results=res.number_of_results)
        return surah_proto.SurahSingleResponse(code=200,
                                               status='OK',
                                               data=surah_data)
Beispiel #5
0
    def GetAll(self, request, context):
        find_surah = SurahFactory.find_surah()
        surah_stream = find_surah.get_all(request.limit, request.cursor)
        surah_list = []
        for surah in surah_stream.surah_list:
            surah_list.append(entity_proto.SurahEntity(**surah.to_dict()))

        if len(surah_list) == 0:
            return surah_proto.SurahMultiResponse(code=404, status='Not Found')

        surah_data = surah_proto.SurahMultiData(
            surah=surah_list,
            number_of_results=surah_stream.number_of_results,
            cursor=surah_stream.cursor)
        return surah_proto.SurahMultiResponse(code=200,
                                              status='OK',
                                              data=surah_data)