Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_update(self):
subreddit = self.reddit.subreddit(pytest.placeholders.test_subreddit)
page = WikiPage(self.reddit, subreddit, "test")
self.reddit.read_only = False
with self.recorder.use_cassette("TestWikiPageModeration.test_update"):
updated = page.mod.update(listed=False, permlevel=1)
assert {"editors": [], "listed": False, "permlevel": 1} == updated
def test_pickle(self):
page = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="x"
)
for level in range(pickle.HIGHEST_PROTOCOL + 1):
other = pickle.loads(pickle.dumps(page, protocol=level))
assert page == other
def test_settings(self):
subreddit = self.reddit.subreddit(pytest.placeholders.test_subreddit)
page = WikiPage(self.reddit, subreddit, "test")
self.reddit.read_only = False
with self.recorder.use_cassette(
"TestWikiPageModeration.test_settings"
):
settings = page.mod.settings()
assert {"editors": [], "listed": True, "permlevel": 0} == settings
def test__iter(self, _):
self.reddit.read_only = False
subreddit = self.reddit.subreddit(pytest.placeholders.test_subreddit)
with self.recorder.use_cassette("TestSubredditWiki.iter"):
count = 0
for wikipage in subreddit.wiki:
assert isinstance(wikipage, WikiPage)
count += 1
assert count > 0
def test_equality(self):
page1 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="x"
)
page2 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="2"
)
page3 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "b"), name="1"
)
page4 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "A"), name="x"
)
page5 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="X"
)
assert page1 == page1
assert page2 == page2
assert page3 == page3
assert page1 != page2
assert page1 != page3
def test_edit(self):
subreddit = self.reddit.subreddit(pytest.placeholders.test_subreddit)
page = WikiPage(self.reddit, subreddit, "test")
self.reddit.read_only = False
with self.recorder.use_cassette("TestWikiPage.test_edit"):
page.edit("PRAW updated")
def post_page(page_text, reddit, subreddit, live_wiki_title):
praw.models.WikiPage(reddit, subreddit, live_wiki_title).edit(page_text)
print("Updated " + str(subreddit) + " " + str(live_wiki_title))
print("https://www.reddit.com/r/" + str(subreddit) + "/wiki/" + str(live_wiki_title))
elif msgsub[1] == "update_wiki":
print("--User want to see settings!")
write_set('wiki')
msgfrom.message('Pigrow Control', "Settings Wiki written at " + wikilink)
elif msgsub[1] == 'datawall':
print("--User want's a datawall!")
datawalllink = "[Settings Wiki](https://www.reddit.com/r/" + str(subreddit) + "/wiki/"+str(wiki_title)+ "datawall)"
os.system(path+"scripts/visualisation/caps_graph.py")
os.system(path+"scripts/visualisation/temp_graph.py hours=24")
os.system(path+"scripts/visualisation/humid_graph.py hours=24")
os.system(path+"scripts/visualisation/selflog_graph.py")
os.system(path+"scripts/visualisation/assemble_datawall.py")
photo_loc = subreddit.stylesheet.upload('datawall', path+"graphs/datawall.jpg")
page_text = "#Datawall \n \n"
page_text += '![datawall](%%datawall%%) \n \n'
praw.models.WikiPage(reddit, subreddit, live_wiki_title).edit(page_text)
live_wikilink = "[Datawall](https://www.reddit.com/r/" + str(subreddit) + "/wiki/"+str(live_wiki_title)+ ")"
msgfrom.message('Pigrow Control', "Datawall uploaded to " + str(live_wikilink))
elif msgsub[1] == "timelapse_hour":
print("Generating the last hour into a timelapse, this will take a while...")
os.system(path+"scripts/visualisation/timelapse_assemble.py of=" + homedir + "/Pigrow/graphs/hour.gif dc=hour1 ds=1 fps=5 ow=r")
#msgfrom.message('Pigrow Control', "Gif created " + homedir + "/Pigrow/graphs/hour.gif")#at " + giflink)
photo_loc = subreddit.stylesheet.upload('onehour', path+"graphs/hour.gif")
page_text = "#Last Hour \n \n"
page_text += '![onehour](%%onehour%%) \n \n'
praw.models.WikiPage(reddit, subreddit, live_wiki_title).edit(page_text)
live_wikilink = "[Timelapse](https://www.reddit.com/r/" + str(subreddit) + "/wiki/"+str(live_wiki_title)+ ")"
msgfrom.message('Pigrow Control', "Last hour timelapse gif uploaded to " + str(live_wikilink))
elif msgsub[1] == "timelapse_5hours":
print("Generating the last five hours into a timelapse, this will take a while...")
os.system(path+"scripts/visualisation/timelapse_assemble.py of=" + homedir + "/Pigrow/graphs/5hours.gif dc=hour5 ds=1 fps=5 ow=r")
graph8 = subreddit.stylesheet.upload('test', resizeda)
page_text += '\n\n##Graphs \n \n'
page_text += '![temp](%%temp%%) '
page_text += '![humidity](%%humid%%) \n'
page_text += '###System Graphs \n'
page_text += '![sec since up](%%ssup%%) '
page_text += '![step graph](%%step%%) '
page_text += '![sec between up](%%sbu%%) '
page_text += '![sec between comps](%%sbc%%) \n'
page_text += '###camera graphs \n'
page_text += 'This is a graph of the file sizes \n ![file sizes of the camera images](%%test%%) '
page_text += '![file time dif](%%fsd%%) \n'
page_text += ' \nIf you can\'t tell this is a very much inprogress bit of work here...'
praw.models.WikiPage(reddit, subreddit, live_wiki_title).edit(page_text)