Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
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.use_cassette():
         data = thread._reddit.request("GET", url)
         contributors = thread.contributor()
     assert isinstance(data, list)
     assert isinstance(contributors, RedditorList)
     assert len(contributors) > 0
Ejemplo n.º 9
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
Ejemplo n.º 10
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'
Ejemplo n.º 11
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"
Ejemplo n.º 12
0
 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"])
Ejemplo n.º 13
0
 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"])
Ejemplo n.º 14
0
 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")
Ejemplo n.º 15
0
 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", [])
Ejemplo n.º 16
0
 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", [])
Ejemplo n.º 17
0
 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
Ejemplo n.º 18
0
 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()
Ejemplo n.º 19
0
 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"
Ejemplo n.º 20
0
 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)
Ejemplo n.º 21
0
 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'
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
 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)
Ejemplo n.º 24
0
 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)
Ejemplo n.º 25
0
 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)
Ejemplo n.º 26
0
 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"]
Ejemplo n.º 27
0
 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']
Ejemplo n.º 28
0
 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"]
Ejemplo n.º 29
0
 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
Ejemplo n.º 30
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:")
Ejemplo n.º 31
0
 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")
Ejemplo n.º 32
0
 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"
Ejemplo n.º 33
0
 def test_init(self):
     thread = LiveThread(self.reddit, "ukaeu1ik4sw5")
     with self.recorder.use_cassette("TestLiveThread_test_init"):
         assert thread.title == "reddit updates"
Ejemplo n.º 34
0
 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'
Ejemplo n.º 35
0
 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')
Ejemplo n.º 36
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:')
Ejemplo n.º 37
0
 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")