def getSMW_Wiki(wikiId="or"): iniFile = WikiUser.iniFilePath(wikiId) if not os.path.isfile(iniFile): wikiUser = OpenResearch.createWikiUser(wikiId) wikiUser.save() wikibot = WikiBot.ofWikiUser(wikiUser) else: wikibot = WikiBot.ofWikiId(wikiId, lenient=True) return wikibot
def testPlantUML(self): if not getpass.getuser() == "travis": wikibot = WikiBot.ofWikiId("rq") smw = SMW(wikibot.site) ask = """{{#ask: [[Concept:SchemaProperty]][[SchemaProperty schema::ConfIDentSchema]] |mainlabel=SchemaProperty | ?SchemaProperty parent = parent | ?SchemaProperty cardinality = cardinality | ?SchemaProperty kind = kind | ?SchemaProperty definition = definition | ?SchemaProperty comment = comment | ?SchemaProperty allowedValue = allowedValue | ?SchemaProperty examples = examples | ?SchemaProperty name = name | ?SchemaProperty type = type | ?SchemaProperty mapsTo = mapsTo | ?SchemaProperty id = id | ?SchemaProperty schema = schema |sort=SchemaProperty kind,SchemaProperty name |order=ascending,ascending | limit=200 }}""" result = smw.query(ask) if TestPlantUML.debug: print(result) pu = PlantUML("http://rq.bitplan.com/index.php") pu.generate(result)
def test_ask(self): """ test using the SMW ask API """ if not getpass.getuser() == "travis": wikibot = WikiBot.ofWikiId("rq") smw = SMW(wikibot.site) ask = """{{#ask: [[Concept:SchemaProperty]][[SchemaProperty schema::ConfIDentSchema]] |mainlabel=SchemaProperty | ?SchemaProperty parent = parent | ?SchemaProperty cardinality = cardinality | ?SchemaProperty kind = kind | ?SchemaProperty definition = definition | ?SchemaProperty comment = comment | ?SchemaProperty allowedValue = allowedValue | ?SchemaProperty examples = examples | ?SchemaProperty name = name | ?SchemaProperty type = type | ?SchemaProperty mapsTo = mapsTo | ?SchemaProperty id = id | ?SchemaProperty schema = schema |sort=SchemaProperty kind,SchemaProperty name |order=ascending,ascending | limit=200 }}""" result = smw.query(ask) if TestWikiAccess.debug: print(result)
def getWikis(self, wikiId): ''' get the wikis ''' wikiuser = TestWikiUser.getSMW_WikiUser(wikiId) wikibot = WikiBot.ofWikiUser(wikiuser) wikiclient = WikiClient.ofWikiUser(wikiuser) return wikibot, wikiclient
def getSMWs(self, wikiId='smwcopy'): ''' get the alternative SMW access instances for the given wiki id ''' wikiuser = TestWikiUser.getSMW_WikiUser(wikiId) wikibot = WikiBot.ofWikiUser(wikiuser) wikiclient = WikiClient.ofWikiUser(wikiuser) smwbot = SMWBot(wikibot.site) smwclient = SMWClient(wikiclient.getSite()) return [smwbot, smwclient]
def test_rq(self): ''' test accessing wiki with id "rq" using encrypted credentials''' # can not test this on travis if not getpass.getuser() == "travis": wikibot = WikiBot.ofWikiId("rq") site = wikibot.site page = pywikibot.Page(site, u"WikiCFP") text = page.text #self.assertEqual(True, False) self.assertTrue('Nonprofit' in text)
def testWikiBot(self): ''' test collecting all bots for which credentials have been set up ''' bots=WikiBot.getBots(name="url",valueExpr="www.*\.org") for bot in bots.values(): print (bot) if bot.site is not None: print (bot.site.sitename) print (bot.getPage("MainPage").text) #bot2=WikiBot.ofWikiId(bot.wikiId) #self.assertEquals(bot2.url,bot.url) pass
def fromWiki(self, wikiId, ask): ''' get the ontology from the given wikiId Args: wikiId(string): the wikiId to get the ontology from Returns: the list of schema properties ''' self.wikibot = WikiBot.ofWikiId(wikiId) self.smw = SMWBot(self.wikibot.site) askResult = self.smw.query(ask) if self.debug: for askRecord in askResult.values(): print(askRecord) return askResult
def getSMW_Wiki(wikiId="smw"): wikiUser=TestWikiUser.getSMW_WikiUser(wikiId) wikibot=None if wikiUser is not None: wikibot=WikiBot.ofWikiUser(wikiUser) return wikibot