Пример #1
0
 def get(self):
     book = self.request.get('book')
     chapter = self.request.get('chapter')
     verses = self.request.get_all('verses')
     translation = self.request.get('translation', default_value='kjv')
     passage = bible_service.get_passage(book, chapter, verses, translation)
     self.write_response(passage)
Пример #2
0
 def test_get_passage_single_verse(self, mock_fetch):
     mock_resp = mock.Mock()
     mock_resp.status_code = 200
     mock_resp.content = json.dumps({
         "reader_chapter": "3",
         "reader_version": "KJV",
         "reader_html": "   For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.",
         "to_path": "/bible/1/jhn.3.16.kjv",
         "reader_book": "John 3:",
         "human": "John 3:16"
     })
     mock_fetch.return_value = mock_resp
     resp = bible_service.get_passage('john', 3, [16])
     mock_fetch.assert_called_once_with('https://www.bible.com/bible/1/jhn.3.16.json')
     self.assertEquals({'chapter': 3,
                        'verses': [
                            {'content': 'For God so loved the world, that he gave his only begotten Son, '
                                        'that whosoever believeth in him should not perish, '
                                        'but have everlasting life.',
                             'verse': 16
                             }
                        ],
                        'book': 'John',
                        'version': 'KJV',
                        'title': 'John 3:16'}, resp)
Пример #3
0
 def test_get_passage_mixed(self, mock_fetch):
     self.maxDiff = None
     mock_resp = mock.Mock()
     mock_resp.status_code = 200
     mock_resp.content = json.dumps({
       "reader_chapter": "3",
       "reader_version": "KJV",
       "reader_html": "There was a man of the Pharisees, named Nicodemus, a ruler of the Jews:",
       "to_path": "/bible/1/jhn.3.1.kjv",
       "reader_book": "John 3",
       "human": "John 3:1"
     })
     mock_resp_2 = mock.Mock()
     mock_resp_2.status_code = 200
     mock_resp_2.content = json.dumps({
       "reader_chapter": "3",
       "reader_version": "KJV",
       "reader_html": "The same came to Jesus by night, and said unto him, Rabbi, we know that thou art a teacher "
                      "come from God: for no man can do these miracles that thou doest, except God be with him.",
       "to_path": "/bible/1/jhn.3.2.kjv",
       "reader_book": "John 3",
       "human": "John 3:2"
     })
     mock_resp_3 = mock.Mock()
     mock_resp_3.status_code = 200
     mock_resp_3.content = json.dumps({
         "reader_chapter": "3",
         "reader_version": "KJV",
         "reader_html": "   For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.",
         "to_path": "/bible/1/jhn.3.16.kjv",
         "reader_book": "John 3:",
         "human": "John 3:16"
     })
     mock_fetch.side_effect = [mock_resp_3, mock_resp, mock_resp_2]
     resp = bible_service.get_passage('john', 3, ['1-2', 16])
     #print resp
     calls = [mock.call('https://www.bible.com/bible/1/jhn.3.1.json'),
              mock.call('https://www.bible.com/bible/1/jhn.3.2.json'),
              mock.call('https://www.bible.com/bible/1/jhn.3.16.json')]
     mock_fetch.assert_has_calls(calls)
     self.assertEquals({'chapter': 3,
                        'verses': [
                            {'content': 'There was a man of the Pharisees, named Nicodemus, a ruler of the Jews:',
                             'verse': 1
                             },
                            {'content': 'The same came to Jesus by night, and said unto him, Rabbi, we know that '
                                        'thou art a teacher come from God: for no man can do these miracles that '
                                        'thou doest, except God be with him.',
                             'verse': 2
                             },
                            {'content': 'For God so loved the world, that he gave his only begotten Son, '
                                        'that whosoever believeth in him should not perish, '
                                        'but have everlasting life.',
                             'verse': 16
                             }
                        ],
                        'book': 'John',
                        'version': 'KJV',
                        'title': 'John 3:1-2,16'}, resp)
Пример #4
0
 def test_get_passage_range(self, mock_fetch):
     mock_resp = mock.Mock()
     mock_resp.status_code = 200
     mock_resp.content = json.dumps({
       "reader_chapter": "3",
       "reader_version": "KJV",
       "reader_html": "There was a man of the Pharisees, named Nicodemus, a ruler of the Jews:",
       "to_path": "/bible/1/jhn.3.1.kjv",
       "reader_book": "John 3",
       "human": "John 3:1"
     })
     mock_resp_2 = mock.Mock()
     mock_resp_2.status_code = 200
     mock_resp_2.content = json.dumps({
       "reader_chapter": "3",
       "reader_version": "KJV",
       "reader_html": "The same came to Jesus by night, and said unto him, Rabbi, we know that thou art a teacher "
                      "come from God: for no man can do these miracles that thou doest, except God be with him.",
       "to_path": "/bible/1/jhn.3.2.kjv",
       "reader_book": "John 3",
       "human": "John 3:2"
     })
     mock_fetch.side_effect = [mock_resp, mock_resp_2]
     resp = bible_service.get_passage('john', 3, ['1-2'])
     calls = [mock.call('https://www.bible.com/bible/1/jhn.3.1.json'),
              mock.call('https://www.bible.com/bible/1/jhn.3.2.json')]
     mock_fetch.assert_has_calls(calls)
     self.assertEquals({'chapter': 3,
                        'verses': [
                            {'content': 'There was a man of the Pharisees, named Nicodemus, a ruler of the Jews:',
                             'verse': 1
                             },
                            {'content': 'The same came to Jesus by night, and said unto him, Rabbi, we know that '
                                        'thou art a teacher come from God: for no man can do these miracles that '
                                        'thou doest, except God be with him.',
                             'verse': 2
                             }
                        ],
                        'book': 'John',
                        'version': 'KJV',
                        'title': 'John 3:1-2'}, resp)
Пример #5
0
    def test_get_passage_full_chapter(self, mock_fetch):
        mock_resp = mock.Mock()
        mock_resp.status_code = 200
        mock_resp.content = json.dumps({
            "reader_chapter": "117",
            "reader_version": "KJV",
            "reader_html": "<div class=\"version vid1 iso6393eng\" data-vid=\"1\" data-iso6393=\"eng\">\n    <div class=\"book bkPSA\">\n        <div class=\"chapter ch117\" data-usfm=\"PSA.117\">\n            <div class=\"label\">117</div><div class=\"p\"><span class=\"content\">  </span><span class=\"verse v1\" data-usfm=\"PSA.117.1\"><span class=\"label\">1</span><span class=\"content\">O praise the </span><span class=\"nd\"><span class=\"content\">Lord</span></span><span class=\"content\">, all ye nations: praise him, all ye people.</span></span></div><div class=\"p\"><span class=\"verse v1\" data-usfm=\"PSA.117.1\"><span class=\"content\">  </span></span><span class=\"verse v2\" data-usfm=\"PSA.117.2\"><span class=\"label\">2</span><span class=\"content\">For his merciful kindness is great toward us: and the truth of the </span><span class=\"nd\"><span class=\"content\">Lord</span></span><span class=\"content\"> endureth for ever. Praise ye the </span><span class=\"nd\"><span class=\"content\">Lord</span></span><span class=\"content\">.</span></span></div>\n        </div>\n    </div>\n</div>",
            "to_path": "/bible/1/psa.117.kjv",
            "reader_book": "Psalms",
            "human": "Psalms 117"
        })

        mock_fetch.return_value = mock_resp
        resp = bible_service.get_passage('psalm', 117, [])
        mock_fetch.assert_called_once_with('https://www.bible.com/bible/1/psa.117.json')
        self.assertEquals({'chapter': 117,
                           'verses': [
                               {'content': 'O praise the Lord, all ye nations: praise him, all ye people.', 'verse': 1},
                               {'content': u'For his merciful kindness is great toward us: and the truth of the Lord endureth for ever. Praise ye the Lord.', 'verse': 2}],
                           'book': 'Psalms',
                           'version': 'KJV',
                           'title': 'Psalms 117'}, resp)