def test_create_edition(): edition = entity_proto.EditionEntity(id='edition-1', language='en', name='edition-name-1', translator='edition-english-name-1', type='Arabic', format='format-1', direction='direction-1') res = stub.CreateEdition(edition) assert res.data.edition.id == edition.id assert res.data.edition.language == edition.language assert res.data.edition.name == edition.name.title() assert res.data.edition.translator == edition.translator.title() assert res.data.edition.type == 'Arabic' assert res.data.edition.format == edition.format.title() assert res.data.edition.direction == edition.direction # Second insert edition = entity_proto.EditionEntity(id='edition-2', language='en', name='edition-name-1', translator='edition-english-name-1', type='Arabic', format='format-2', direction='direction-2') res = stub.CreateEdition(edition) assert res.data.edition.id == edition.id assert res.data.edition.language == edition.language assert res.data.edition.name == edition.name.title() assert res.data.edition.translator == edition.translator.title() assert res.data.edition.type == 'Arabic' assert res.data.edition.format == edition.format.title() assert res.data.edition.direction == edition.direction # Third insert with type Translation edition = entity_proto.EditionEntity(id='edition-3', language='en', name='edition-name-3', translator='edition-english-name-3', type='Translation', format='format-1', direction='direction-1') res = stub.CreateEdition(edition) assert res.data.edition.id == edition.id assert res.data.edition.language == edition.language assert res.data.edition.name == edition.name.title() assert res.data.edition.translator == edition.translator.title() assert res.data.edition.type == 'Translation' assert res.data.edition.format == edition.format.title() assert res.data.edition.direction == edition.direction
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
def FindEditionById(self, request, context): find_edition = EditionFactory.find_edition() res = find_edition.by_id(request.id) if res is None: return edition_proto.EditionSingleResponse(code=404, status='Not Found') edition_entity = entity_proto.EditionEntity(**res.edition.to_dict()) edition_data = edition_proto.EditionSingleData( edition=edition_entity, number_of_results=res.number_of_results) return edition_proto.EditionSingleResponse(code=200, status='OK', data=edition_data)
def GetAll(self, request, context): find_edition = EditionFactory.find_edition() edition_stream = find_edition.get_all(request.limit, request.cursor) editions = [] for edition in edition_stream.edition_list: editions.append(entity_proto.EditionEntity(**edition.to_dict())) if len(editions) == 0: return edition_proto.EditionMultiResponse(code=404, status='Not Found') edition_data = edition_proto.EditionMultiData( edition=editions, number_of_results=edition_stream.number_of_results, cursor=edition_stream.cursor) return edition_proto.EditionMultiResponse(code=200, status='OK', data=edition_data)