def parse_and_upload(): cards = get_cards() links = [] for card in cards: node = JaggedArrayNode() node.add_title(card, 'en', primary=True) node.add_title(u'רמב"ם ' + Ref(card.replace('Rambam ', '')).he_normal(), 'he', primary=True) node.key = card node.depth = 3 node.addressTypes = ['Integer', 'Integer', 'Integer'] node.sectionNames = ['Chapter', 'Mishnah', 'Comment'] node.validate() node.toc_zoom = 2 index = { 'title': card, 'categories': ['Commentary2', 'Mishnah', 'Rambam'], 'schema': node.serialize(), } parsed = parser(card) links.extend(parsed['links']) version = { 'versionTitle': u'Vilna Edition', 'versionSource': 'http://primo.nli.org.il/primo_library/libweb/action/dlDisplay.do?vid=NLI&docId=NNL_ALEPH001300957', 'language': 'he', 'text': parsed['parsed'] } print 'posting {}'.format(card) post_index(index) post_text(card, version, index_count='on') post_link(links)
def test_jaggedarray_fields(self): j = JaggedArrayNode() j.add_title(u"title1", "en", primary=True)\ .add_title(u"ייי", "he", primary=True)\ .add_title(u"title2", "en")\ .add_title(u"ייכי", "he") j.depth = 1 j.sectionNames = ["Foo"] j.addressTypes = ["Integer"] j.key = "bob" j.validate() for f in ["depth", "sectionNames", "addressTypes", "key"]: t = copy.deepcopy(j) delattr(t, f) with pytest.raises(IndexSchemaError): t.validate() t = copy.deepcopy(j) t.sectionNames += ["foob"] with pytest.raises(IndexSchemaError): t.validate() t = copy.deepcopy(j) t.addressTypes += ["Integer"] with pytest.raises(IndexSchemaError): t.validate()
def test_remove(self): j = JaggedArrayNode() j.add_title(u"title1", "en", primary=True)\ .add_title(u"ייי", "he", primary=True)\ .add_title(u"title2", "en")\ .add_title(u"ייכי", "he") j.remove_title(u"title1", "en") j.depth = 1 j.sectionNames = ["Foo"] j.addressTypes = ["Integer"] j.key = "bob" with pytest.raises(IndexSchemaError): j.validate()