def test_construct_failure(self): message = "Either `id` or `_data` must be provided." with pytest.raises(TypeError) as excinfo: LiveThread(self.reddit) assert str(excinfo.value) == message with pytest.raises(TypeError) as excinfo: LiveThread(self.reddit, id="dummy", _data={"id": "dummy"}) assert str(excinfo.value) == message
def test_hash(self): thread1 = LiveThread(self.reddit, id="dummy1") thread2 = LiveThread(self.reddit, id="Dummy1") thread3 = LiveThread(self.reddit, id="dummy3") assert hash(thread1) == hash(thread1) assert hash(thread2) == hash(thread2) assert hash(thread3) == hash(thread3) assert hash(thread1) != hash(thread2) assert hash(thread2) != hash(thread3) assert hash(thread1) != hash(thread3)
def test_construct_success(self): thread_id = "ukaeu1ik4sw5" data = {"id": thread_id} thread = LiveThread(self.reddit, thread_id) assert isinstance(thread, LiveThread) assert thread.id == thread_id thread = LiveThread(self.reddit, _data=data) assert isinstance(thread, LiveThread) assert thread.id == thread_id
async def test_contributor(self): thread = LiveThread(self.reddit, "ukaeu1ik4sw5") with self.use_cassette(): contributors = [ contributor async for contributor in thread.contributor() ] assert isinstance(contributors, list) assert len(contributors) > 0 for contributor in contributors: assert "permissions" in contributor.__dict__ assert isinstance(contributor, Redditor)
def test_equality(self): thread1 = LiveThread(self.reddit, id="dummy1") thread2 = LiveThread(self.reddit, id="Dummy1") thread3 = LiveThread(self.reddit, id="dummy3") assert thread1 == thread1 assert thread2 == thread2 assert thread3 == thread3 assert thread1 != thread2 # live thread ID in a URL is case sensitive assert thread2 != thread3 assert thread1 != thread3 assert "dummy1" == thread1 assert thread2 != "dummy1" assert thread2 == "Dummy1"
async def test_contributor__with_manage_permission(self, _): # see issue #710 for more info self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") url = API_PATH["live_contributors"].format(id=thread.id) with self.use_cassette(): data = await thread._reddit.request("GET", url) contributors = [ contributor async for contributor in thread.contributor() ] assert isinstance(data, dict) assert isinstance(contributors, list) assert len(contributors) > 0
async def test_getitem(self): thread_id = "dummy_thread_id" update_id = "dummy_update_id" thread = LiveThread(self.reddit, id=thread_id) update = await thread.get_update(update_id, lazy=True) assert isinstance(update, LiveUpdate) assert update.id == update_id
async def test_invite__already_invited(self, _): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): with pytest.raises(RedditAPIException) as excinfo: await thread.contributor.invite(pytest.placeholders.username) assert excinfo.value.items[ 0].error_type == "LIVEUPDATE_ALREADY_CONTRIBUTOR"
async def test_attributes(self): thread = LiveThread(self.reddit, "ukaeu1ik4sw5") with self.use_cassette(): update = await thread.get_update( "7827987a-c998-11e4-a0b9-22000b6a88d2") assert isinstance(update.author, Redditor) assert update.author == "umbrae" assert update.name == "LiveUpdate_7827987a-c998-11e4-a0b9-22000b6a88d2" assert update.body.startswith("Small change")
async def test_update__other_settings(self, _): new_settings = { "title": "new title", "other1": "other 1", "other2": "other 2", } self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contrib.update(**new_settings)
async def test_remove_invite__redditor(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") redditor = Redditor(self.reddit, _data={ "name": pytest.placeholders.username, "id": "3ebyblla" }) with self.use_cassette(): await thread.contributor.remove_invite(redditor)
async def test_update__full_settings(self, _): new_settings = { "title": "new title 2", "description": "## new description 2", "nsfw": True, "resources": "## new resources 2", } self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contrib.update(**new_settings) thread = await self.reddit.live("1595195m6j9zw", fetch=True) assert thread.title == new_settings["title"] assert thread.description == new_settings["description"] assert thread.nsfw == new_settings["nsfw"] assert thread.resources == new_settings["resources"]
def test_repr(self): thread = LiveThread(self.reddit, id="dummy") assert repr(thread) == "LiveThread(id='dummy')"
async def test_invite__empty_list(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contributor.invite(pytest.placeholders.username, [])
async def test_remove_invite__fullname(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contributor.remove_invite("t2_3ebyblla")
def test_contributor(self): thread_id = "ukaeu1ik4sw5" thread = LiveThread(self.reddit, thread_id) assert isinstance(thread.contributor, LiveContributorRelationship)
def test_contrib(self): thread_id = "ukaeu1ik4sw5" thread = LiveThread(self.reddit, thread_id) assert isinstance(thread.contrib, LiveThreadContribution)
async def test_update__limited(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contributor.update(pytest.placeholders.username, ["manage", "edit"])
async def test_update_invite__none(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contributor.update_invite( pytest.placeholders.username, None)
async def test_accept_invite(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contributor.accept_invite()
async def test_updates(self, _): thread = LiveThread(self.reddit, "ukaeu1ik4sw5") with self.use_cassette(): async for update in thread.updates(limit=None): assert update.thread == thread assert update.body.startswith("Small change:")
async def test_report(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.report("spam")
async def test_add(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contrib.add("* `LiveThreadContribution.add() test`")
def test_str(self): thread = LiveThread(self.reddit, id="dummy") assert str(thread) == "dummy"
async def test_close(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): await thread.contrib.close()
async def test_update__no_args(self): thread = LiveThread(self.reddit, "xyu8kmjvfrww") assert await thread.contrib.update() is None
async def test_discussions(self): thread = LiveThread(self.reddit, "1595195m6j9zw") with self.use_cassette(): async for submission in thread.discussions(limit=None): assert isinstance(submission, Submission) assert submission.title == "reddit updates"