def setUp(self): self.grass = fandom.page(wiki="starwars", title="Grass") self.moisture_farm = fandom.page(wiki="starwars", title="Moisture farm") self.Boba_Fett = fandom.page(wiki="starwars", title="Boba Fett") self.holden_ledbury = fandom.page(wiki="harrypotter", title="Holden Ledbury")
def test_redirect_normalization(self): """Test that a page redirect loads correctly with or without a query normalization""" capital_party = fandom.page(wiki="elderscrolls", title="Stormcloaks") lower_party = fandom.page(wiki="elderscrolls", title="stormcloaks") self.assertIsInstance(capital_party, fandom.FandomPage) self.assertIsInstance(lower_party, fandom.FandomPage) self.assertEqual(capital_party.title, "Stormcloaks") self.assertEqual(capital_party, lower_party)
def query_text(inline_query): nada = telebot.types.InlineQueryResultArticle( "0", "Nada encontrado", telebot.types.InputTextMessageContent("Não há nada sobre '" + inline_query.query + "' no " + WIKI)) try: search_results = fandom.search(inline_query.query) results = [] for i, page_result in enumerate(search_results): page = fandom.page(page_result[0]) title, url = page.title, page.url url = url.replace(' ', '%20') results.append( telebot.types.InlineQueryResultArticle( str(i), title, telebot.types.InputTextMessageContent(url))) if (len(results) == 0): results.append(nada) BOT.answer_inline_query(inline_query.id, results) except: BOT.answer_inline_query(inline_query.id, [nada])
def test_lang(self): fandom.set_lang("nl") self.assertEqual(fandom.default_url(), 'https://fandom.com/nl/') fandom.set_wiki("runescape") self.assertEqual(fandom.default_url(), 'https://runescape.fandom.com/nl/') page = fandom.page("runes") self.assertEqual(page.language, "nl")
def test_redirect_true(self): """Test that a page successfully redirects a query.""" # no error should be raised if redirect is test_redirect_true mp = fandom.page(wiki="harrypotter", title="Professor Slughorn") self.assertEqual(mp.title, "Horace Slughorn") self.assertEqual( mp.url, "https://harrypotter.fandom.com/en/wiki/Horace_Slughorn")
async def fandom(self, ctx: commands.Context, fandom_community: str, *, item: str): try: name = fan.search(query=item, wiki=fandom_community, results=1)[0][0] except IndexError: await ctx.send(content="Can't find item") page = fan.page(title=name, wiki=fandom_community, preload=True) m = Fandom_Menu(page) await m.start(ctx)
def test_wrong_lang(self): fandom.set_lang("ln") fandom.set_wiki("runescape") rp = lambda: fandom.page("runes") self.assertRaises(fandom.error.RequestError, rp)
def test_missing(self): """Test that page raises a PageError for a nonexistant page.""" purpleberry = lambda: fandom.page(wiki="harrypotter", title="purpleberry") self.assertRaises(fandom.error.PageError, purpleberry)
def test_from_page_id(self): """Test loading from a page id""" self.assertEqual(self.grass, fandom.page(wiki="starwars", pageid=508340))
def test_redirect_with_normalization(self): """Test that a page redirect with a normalized query loads correctly""" the_party = fandom.page(wiki="elderscrolls", title="stormcloaks") self.assertIsInstance(the_party, fandom.FandomPage) self.assertEqual(the_party.title, "Stormcloaks")
def test_redirect_false(self): """Test that page raises an error on a redirect when redirect == False.""" mp = lambda: fandom.page( wiki="harrypotter", title="The Potters", redirect=False) self.assertRaises(fandom.error.RedirectError, mp)