Exemple #1
0
 def test_upload_badfile(self):
     self.site.login("GoodUsername", "goodpassword")
     f1 = wikifile.File(self.site, "File:Test2.jpg")
     with self.assertRaises(wikitools.exceptions.UploadError):
         f1.upload(fileobj=io.BytesIO())
     with self.assertRaises(wikitools.exceptions.UploadError):
         f1.upload(fileobj="notafile.jpg")
Exemple #2
0
 def test_getFileHistory(self):
     f1 = wikifile.File(self.site, "File:Test1.jpg")
     api.logging = True
     f1.getFileHistory(exif=False)
     self.assertIs(len(api.querylog), 1)
     log = api.querylog.pop()
     self.assertNotIn("metadata", log["iiprop"])
Exemple #3
0
 def test_getFileHistoryGen(self):
     f1 = wikifile.File(self.site, "File:Test1.jpg")
     api.logging = True
     for rev in f1.getFileHistoryGen():
         pass
     self.assertGreater(len(api.querylog), 1)
     log = api.querylog.pop()
     self.assertIn("metadata", log["iiprop"])
Exemple #4
0
 def test_getUsage(self):
     f1 = wikifile.File(self.site, "File:Test1.jpg")
     api.logging = True
     usage = f1.getUsage()
     self.assertIsInstance(usage[0], page.Page)
     log = api.querylog.pop()
     self.assertNotIn("iunamespace", log)
     usage = f1.getUsage(namespaces=[3, 5])
     self.assertEqual(len(usage), 0)
     log = api.querylog.pop()
     self.assertIn("iunamespace", log)
Exemple #5
0
logger.setLevel('INFO')
try:
    with open(_json_dir + site + '.json', 'r') as infile:
        old_json = json.load(infile)
    g_old = json_graph.node_link_graph(old_json)
    if is_isomorphic(g, g_old):
        logger.info('No change in graph since last map generation')
        update_needed = False
except:
    logger.info('No old json file')
    update_needed = True
    pass

if update_needed:
    logger.info('Updating wiki image and json cache')
    pagename = site.title() + ' Network Topology'
    text = "This page is generated automatically from the Network API " + \
        "and shows you the topology of [[" + site.title() + ":Network]].\n\n" + \
        "[[File:topo_" + site + ".png|500px|center]]"
    website = wiki.Wiki("http://140.77.13.123/mediawiki/api.php")
    website.login('lolo', password='******')
    topo = page.Page(website, pagename)
    topo.edit(text=text)
    fig = treemap(g, layout='neato')
    fig.savefig("topo_" + site + ".png")
    upload_file = wikifile.File(website, "topo_" + site + ".png")
    upload_file.upload(open("topo_" + site + ".png"), ignorewarnings=True)
    fresh_json = json_graph.node_link_data(g)
    with open(_json_dir + site + '.json', 'w') as outfile:
        json.dump(fresh_json, outfile)
Exemple #6
0
 def test_upload_good(self):
     self.site.login("GoodUsername", "goodpassword")
     f1 = wikifile.File(self.site, "File:Test1.jpg")
     res = f1.upload(fileobj=open("Test1.jpg", "rb"), ignorewarnings=True)
     self.assertEqual(res["upload"]["result"], "Success")
Exemple #7
0
 def test_upload_warning(self):
     self.site.login("GoodUsername", "goodpassword")
     f1 = wikifile.File(self.site, "File:Test1.jpg")
     with self.assertWarns(UserWarning):
         f1.upload(fileobj=open("Test1.jpg", "rb"))
Exemple #8
0
 def test_download(self):
     f1 = wikifile.File(self.site, "File:Test1.jpg")
     loc = f1.download(location="Temp.jpg")
     self.assertEqual(loc, "Temp.jpg")
     self.assertGreater(os.stat(loc).st_size, 8000)
     os.remove(loc)