Beispiel #1
0
 def test_cite_formatting(self):
     items = bib_parser.BibParser()._parse_string(TEST_ITEMS)
     self.assertEqual(
         utils.make_html_cite(items[-1]),
         ("<em>Людовик Петровский, Николай Проклович Петров</em> "
          "Побрюзжим на досуге. "
          "Москва, Одесса, "
          "1825. "
          '<a href="/books/id_2">https://bib.hda.org.ru/books/id_2</a>'))
Beispiel #2
0
    def test_inverted_index_search(self):
        items = bib_parser.BibParser()._parse_string(TEST_ITEMS)
        item_index = index.Index(items)

        DIRECT_KEY = "cinquecento"
        INVERTED_KEY = const.INVERTED_INDEX_KEY_PREFIX + DIRECT_KEY
        subindex = item_index["keywords"]
        self.assertIn(DIRECT_KEY, subindex)
        self.assertIn(INVERTED_KEY, subindex)
        filtered_items = item_index["keywords"][INVERTED_KEY]
        self.assertEqual(len(filtered_items), 1)
        self.assertEqual(utils.first(filtered_items).id(), "id_2")
Beispiel #3
0
    def test_search_items(self):
        """
		Tests if parsed items can be searched by a bunch of parameters
		"""
        items = bib_parser.BibParser()._parse_string(TEST_ITEMS)
        item_index = index.Index(items)

        author_search = search.search_for_iterable("author", "Петров")
        filtered_items = filter(author_search, items)
        self.assertEqual(len(list(filtered_items)), 1)

        #testing exact match
        year_search = search.and_([
            search.search_for("year_from", 1825),
            search.search_for("year_to", 1825)
        ])
        filtered_items = filter(year_search, items)
        self.assertEqual(len(list(filtered_items)), 1)

        #testing partial intersection
        year_search = search.and_([
            search.search_for("year_from", 1500),
            search.search_for("year_to", 1600)
        ])
        filtered_items = filter(year_search, items)
        self.assertEqual(len(list(filtered_items)), 1)

        #testing inner containment
        year_search = search.and_([
            search.search_for("year_from", 1499),
            search.search_for("year_to", 1501)
        ])
        filtered_items = filter(year_search, items)
        self.assertEqual(len(list(filtered_items)), 1)

        #testing outer containment
        year_search = search.and_([
            search.search_for("year_from", 1400),
            search.search_for("year_to", 1600)
        ])
        filtered_items = filter(year_search, items)
        self.assertEqual(len(list(filtered_items)), 1)

        filtered_items = item_index["keywords"]["grumbling"]
        self.assertEqual(len(list(filtered_items)), 1)

        filtered_items = \
         item_index["keywords"]["cinquecento"] & \
         item_index["keywords"]["historical dance"]
        self.assertEqual(len(list(filtered_items)), 1)
Beispiel #4
0
    def test_parse_string(self):
        """
		Tests if string can be succesfully parsed by BibParser
		"""
        items = bib_parser.BibParser()._parse_string(TEST_ITEMS)
        item_index = index.Index(items)

        languages = set(langid for langid in item_index["langid"].keys()
                        if not langid.startswith("!"))
        keywords = set(item_index["keywords"].keys())

        self.assertEqual(len(items), 2)
        self.assertEqual(languages, EXPECTED_LANGUAGES)
        self.assertEqual(keywords, EXPECTED_KEYWORDS)

        item1 = next(iter(item_index["id"]["id_1"]))
        self.assertTrue('{' not in item1.title())
        self.assertTrue('}' not in item1.title())
Beispiel #5
0
import flask
from flaskext import markdown as flask_markdown
import flask_babel

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dancebooks.config import config
from dancebooks import bib_parser
from dancebooks import const
from dancebooks import db
from dancebooks import search
from dancebooks import messenger
from dancebooks import utils
from dancebooks import utils_flask

items, item_index = bib_parser.BibParser().parse_folder(
    config.parser.bibdata_dir)

langids = sorted(langid for langid in item_index["langid"].keys()
                 if not langid.startswith("!"))
source_files = sorted(item_index["source_file"].keys())
booktypes = sorted(item_index["booktype"].keys())
markdown_cache = utils.MarkdownCache()

debug_mode = False

flask_app = flask.Flask(__name__)
flask_app.config["BABEL_DEFAULT_LOCALE"] = utils.first(config.www.languages)
flask_app.config["USE_EVALEX"] = False
babel_app = flask_babel.Babel(flask_app)
flask_markdown_app = flask_markdown.Markdown(flask_app)