Пример #1
0
 def test_wiki_article_maradona(self):
     app = web_app.create_app(watchdog=None, with_static=False)
     app.art_mngr.get_item = lambda x: "Fake article <a>Yo soy el Diego</a>"
     client = Client(app, Response)
     response = client.get("/wiki/Diego_Armando_Maradona")
     self.assertEqual(response.status_code, 200)
     self.assertTrue("Yo soy el Diego" in response.data)
Пример #2
0
def test_search_real_search(create_app_client):
    app = web_app.create_app(watchdog=None, with_static=False)

    with patch.object(app.index, 'search') as index_mock:
        index_mock.return_value = [
            IndexEntry(IndexEntry.TYPE_ORIG_ARTICLE,
                       link='t/e/s/testlink1',
                       title='testtitle1',
                       score=123,
                       description='testtext1'),
            IndexEntry(IndexEntry.TYPE_ORIG_ARTICLE,
                       link='t/e/s/testlink moño',
                       title='testtitle2',
                       score=456,
                       description='testtext2'),
        ]
        results = app._search("foo bar Moño")
    index_mock.assert_called_once_with(['foo', 'bar', 'mono'])

    result1, result2 = results
    assert result1.link == 'wiki/testlink1'
    assert result1.title == 'testtitle1'
    assert result1.description == 'testtext1'
    assert result2.link == 'wiki/testlink%20mo%C3%B1o'
    assert result2.title == 'testtitle2'
    assert result2.description == 'testtext2'
Пример #3
0
def test_wiki_article_maradona(create_app_client):
    app, client = create_app_client()
    app = web_app.create_app(watchdog=None, with_static=False)
    app.art_mngr.get_item = lambda x: "Fake article <a>Yo soy el Diego</a>"
    client = Client(app, Response)
    response = client.get("/wiki/Diego_Armando_Maradona")
    assert response.status_code == 200
    assert b"Yo soy el Diego" in response.data
Пример #4
0
def test_wiki_article_with_special_chars(create_app_client):
    app, client = create_app_client()
    app = web_app.create_app(watchdog=None, with_static=False)
    html = "foo <a>bar</a> baz"
    app.art_mngr.get_item = lambda x: html
    client = Client(app, Response)
    response = client.get("/wiki/.foo/bar%baz")
    assert response.status_code == 200
    assert html.encode('utf-8') in response.data
Пример #5
0
def test_search_term_with_slash(create_app_client):
    app = web_app.create_app(watchdog=None, with_static=False)

    with patch.object(app.index, 'search') as index_mock:
        index_mock.return_value = [
            IndexEntry(IndexEntry.TYPE_ORIG_ARTICLE,
                       link='f/o/o/foo/bar',
                       title='testtitle')
        ]
        results = app._search("foo/bar")
    index_mock.assert_called_once_with(['foo/bar'])
    assert results[0].link == 'wiki/foo%2Fbar'
Пример #6
0
    def test_index_ready(self):
        app = web_app.create_app(watchdog=None, with_static=False)
        client = Client(app, Response)

        class FakeIndex(object):
            def __init__(self):
                self.ready = False

            def is_ready(self):
                return self.ready

        app.index = FakeIndex()
        response = client.get("/search_index/ready")
        self.assertEqual(response.data, "false")

        app.index.ready = True
        response = client.get("/search_index/ready")
        self.assertEqual(response.data, "true")
Пример #7
0
def create_app_client(mocker, tmp_path):
    """Helper to create tests app and client."""

    # fix config and write some setup files
    config.DIR_ASSETS = str(tmp_path)
    mocker.patch('config.LANGUAGE', 'es')
    mocker.patch('config.PORTAL_PAGE', 'Portal:Portal')
    mocker.patch('config.URL_WIKIPEDIA', 'http://es.wikipedia.org/')
    mocker.patch('config.PYTHON_DOCS_FILENAME', 'docs.tar.bz2')
    mocker.patch('src.armado.compresor.ArticleManager.archive_dir',
                 str(tmp_path))
    mocker.patch('src.armado.compresor.ImageManager.archive_dir',
                 str(tmp_path))
    mocker.patch.dict('os.environ', {'LANGUAGE': 'es'})
    with (tmp_path / 'numbloques.txt').open('wt') as fh:
        fh.write('42\n')
    with (tmp_path / 'language.txt').open('wt') as fh:
        fh.write('es\n')
    with tarfile.open(str(tmp_path / config.PYTHON_DOCS_FILENAME),
                      'w:bz2') as fh:
        fh.addfile(tarfile.TarInfo(name="testtuto"))
    inst_dir = tmp_path / 'institucional'
    inst_dir.mkdir()
    with (inst_dir / 'ayuda.html').open('wt') as fh:
        fh.write('lot of help\n')

    dynamic_assets = tmp_path / 'dynamic'
    dynamic_assets.mkdir()
    with (dynamic_assets / 'start_date.txt').open('wt') as fh:
        fh.write('20201122\n')

    # a bogus index with a couple of items (so it behaves properly for get_random and similar)
    mocker.patch('config.DIR_INDICE', str(tmp_path))
    # title, link, score, description, orig_words, redir_words
    fake_content = [('Page1', 'p/a/g/page1', 7, ' ', ['key1'], set()),
                    ('Page2', 'p/a/g/page2', 8, ' ', ['key2'], set())]
    cdpindex.Index.create(str(tmp_path), fake_content)

    app = web_app.create_app(watchdog=None, with_static=False)
    client = Client(app, Response)
    return lambda: (app, client)
Пример #8
0
        cd_wd_timer.start()

        threading.Thread(target=sleep_and_browse).start()

        browser_watchdog = None
        if config.BROWSER_WD_SECONDS:
            browser_watchdog = WatchDog(callback=close, sleep=config.BROWSER_WD_SECONDS)
            # Iniciamos el watchdog por más que aún no esté levantado el browser ya que
            # el tiempo del watchdog es mucho mayor que el que se tarda en levantar el server
            # y el browser.
            browser_watchdog.start()

        if options.verbose:
            print "Levantando el server..."

        app = create_app(browser_watchdog, verbose=options.verbose)

        server = ThreadedWSGIServer(config.HOSTNAME, config.PORT, app, handler=None,
                                    passthrough_errors=False)
        server_up.set()
        server.serve_forever()

        if options.verbose:
            print "Terminado, saliendo."
        cd_wd_timer.cancel()

    else:
        app = create_app(watchdog=None, verbose=options.verbose)
        server = ThreadedWSGIServer(config.HOSTNAME, port, app, handler=None,
                                    passthrough_errors=False)
        server.serve_forever()
Пример #9
0
 def test_watchdog_on(self):
     app = web_app.create_app(watchdog=True, with_static=False)
     client = Client(app, Response)
     response = client.get("/")
     self.assertTrue("watchdog" in response.data)
Пример #10
0
 def setUp(self):
     self.app = web_app.create_app(watchdog=None, with_static=False)
     self.client = Client(self.app, Response)
Пример #11
0
def test_watchdog_on(create_app_client):
    app, client = create_app_client()
    app = web_app.create_app(watchdog=True, with_static=False)
    client = Client(app, Response)
    response = client.get("/")
    assert b"watchdog" in response.data