def test_contributor(self): thread = LiveThread(self.reddit, 'ukaeu1ik4sw5') with self.recorder.use_cassette('TestLiveThread_test_contributor'): contributors = thread.contributor() assert isinstance(contributors, RedditorList) assert len(contributors) > 0 for contributor in contributors: assert 'permissions' in contributor.__dict__ assert isinstance(contributor, Redditor)
def test_contributor(self): thread = LiveThread(self.reddit, "ukaeu1ik4sw5") with self.recorder.use_cassette("TestLiveThread_test_contributor"): contributors = thread.contributor() assert isinstance(contributors, RedditorList) assert len(contributors) > 0 for contributor in contributors: assert "permissions" in contributor.__dict__ assert isinstance(contributor, Redditor)
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_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_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
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 = thread._reddit.request("GET", url) contributors = thread.contributor() assert isinstance(data, list) assert isinstance(contributors, RedditorList) assert len(contributors) > 0
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.recorder.use_cassette( 'TestLiveThread_test_contributor__with_manage_permission'): data = thread._reddit.request('GET', url) contributors = thread.contributor() assert isinstance(data, list) assert isinstance(contributors, RedditorList) assert len(contributors) > 0
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'
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"
def test_invite__limited(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") with self.recorder.use_cassette( "TestLiveContributorRelationship_test_invite__limited" ): thread.contributor.invite("nmtake", ["manage", "edit"])
def test_update__limited(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "ydwwxneu7vsa") with self.recorder.use_cassette( "TestLiveContributorRelationship_test_update__limited" ): thread.contributor.update("nmtake", ["manage", "edit"])
def test_remove_invite__fullname(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") with self.recorder.use_cassette( "TestLiveContributorRelationship_test_remove_invite__fullname" ): thread.contributor.remove_invite("t2_ll32z")
def test_update_invite__empty_list(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "ydwwxneu7vsa") with self.recorder.use_cassette( "TestLiveContributorRelationship_test_update_invite__empty_list" ): thread.contributor.update_invite("nmtake", [])
def test_invite__empty_list(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") with self.recorder.use_cassette( "TestLiveContributorRelationship_test_invite__empty_list" ): thread.contributor.invite("nmtake", [])
def test_getitem(self): thread_id = 'dummy_thread_id' update_id = 'dummy_update_id' thread = LiveThread(self.reddit, id=thread_id) update = thread[update_id] assert isinstance(update, LiveUpdate) assert update.id == update_id
def test_accept_invite(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") with self.recorder.use_cassette( "TestLiveContributorRelationship_test_accept_invite" ): thread.contributor.accept_invite()
def test_invite__already_invited(self, _): self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") with self.use_cassette(): thread.contributor.invite("nmtake") with pytest.raises(RedditAPIException) as excinfo: thread.contributor.invite("nmtake") assert excinfo.value.items[0].error_type == "LIVEUPDATE_ALREADY_CONTRIBUTOR"
def test_remove_invite__redditor(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") redditor = Redditor(self.reddit, _data={"name": "nmtake", "id": "ll32z"}) with self.recorder.use_cassette( "TestLiveContributorRelationship_test_remove_invite__redditor" ): thread.contributor.remove_invite(redditor)
def test_invite__already_invited(self, _): self.reddit.read_only = False thread = LiveThread(self.reddit, 'xyu8kmjvfrww') with self.recorder.use_cassette('TestLiveContributorRelationship_' 'test_invite__already_invited'): thread.contributor.invite('nmtake') with pytest.raises(APIException) as excinfo: thread.contributor.invite('nmtake') assert excinfo.value.error_type == 'LIVEUPDATE_ALREADY_CONTRIBUTOR'
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, "xyu8kmjvfrww") with self.use_cassette(): thread.contrib.update(**new_settings)
def test_remove__redditor(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") redditor = Redditor(self.reddit, _data={ "name": "nmtake", "id": "ll32z" }) with self.use_cassette(): thread.contributor.remove(redditor)
def test_remove_invite__redditor(self): self.reddit.read_only = False thread = LiveThread(self.reddit, 'xyu8kmjvfrww') redditor = Redditor(self.reddit, _data={ 'name': 'nmtake', 'id': 'll32z' }) with self.recorder.use_cassette('TestLiveContributorRelationship_' 'test_remove_invite__redditor'): thread.contributor.remove_invite(redditor)
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, 'xyu8kmjvfrww') with self.recorder.use_cassette( 'TestLiveThreadContribution.test_update__other_settings'): thread.contrib.update(**new_settings)
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, "xyu8kmjvfrww") with self.use_cassette(): thread.contrib.update(**new_settings) 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_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, 'xyu8kmjvfrww') with self.recorder.use_cassette( 'TestLiveThreadContribution.test_update__full_settings'): thread.contrib.update(**new_settings) 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_update__partial_settings(self, _): old_settings = { "title": "old title", "description": "## old description", "nsfw": False, "resources": "## old resources", } new_settings = {"title": "new title", "nsfw": True} self.reddit.read_only = False thread = LiveThread(self.reddit, "xyu8kmjvfrww") with self.use_cassette(): thread.contrib.update(**new_settings) assert thread.title == new_settings["title"] assert thread.description == old_settings["description"] assert thread.nsfw == new_settings["nsfw"] assert thread.resources == old_settings["resources"]
def test_contributor(self, _): thread = LiveThread(self.reddit, 'ukaeu1ik4sw5') with self.recorder.use_cassette('TestLiveThread_test_contributor'): contributors = thread.contributor() assert isinstance(contributors, RedditorList) assert len(contributors) > 0
def test_updates(self, _): thread = LiveThread(self.reddit, "ukaeu1ik4sw5") with self.recorder.use_cassette("TestLiveThread_test_updates"): for update in thread.updates(limit=None): assert update.thread == thread assert update.body.startswith("Small change:")
def test_report(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "ydwwxneu7vsa") with self.recorder.use_cassette("TestLiveThread_test_report"): thread.report("spam")
def test_discussions(self): thread = LiveThread(self.reddit, "ukaeu1ik4sw5") with self.recorder.use_cassette("TestLiveThread_test_discussions"): for submission in thread.discussions(limit=None): assert isinstance(submission, Submission) assert submission.title == "reddit updates"
def test_init(self): thread = LiveThread(self.reddit, "ukaeu1ik4sw5") with self.recorder.use_cassette("TestLiveThread_test_init"): assert thread.title == "reddit updates"
def test_discussions(self): thread = LiveThread(self.reddit, 'ukaeu1ik4sw5') with self.recorder.use_cassette('TestLiveThread_test_discussions'): for submission in thread.discussions(limit=None): assert isinstance(submission, Submission) assert submission.title == 'reddit updates'
def test_report(self): self.reddit.read_only = False thread = LiveThread(self.reddit, 'ydwwxneu7vsa') with self.recorder.use_cassette('TestLiveThread_test_report'): thread.report('spam')
def test_updates(self, _): thread = LiveThread(self.reddit, 'ukaeu1ik4sw5') with self.recorder.use_cassette('TestLiveThread_test_updates'): for update in thread.updates(limit=None): assert update.thread == thread assert update.body.startswith('Small change:')
def test_report(self): self.reddit.read_only = False thread = LiveThread(self.reddit, "ydwwxneu7vsa") with self.recorder.use_cassette("TestLiveThread_test_report"): thread.report("spam")