Exemplo n.º 1
0
 def test_hash(self):
     redditor1 = Redditor(self.reddit, _data={"name": "dummy1", "n": 1})
     redditor2 = Redditor(self.reddit, _data={"name": "Dummy1", "n": 2})
     redditor3 = Redditor(self.reddit, _data={"name": "dummy3", "n": 2})
     assert hash(redditor1) == hash(redditor1)
     assert hash(redditor2) == hash(redditor2)
     assert hash(redditor3) == hash(redditor3)
     assert hash(redditor1) == hash(redditor2)
     assert hash(redditor2) != hash(redditor3)
     assert hash(redditor1) != hash(redditor3)
Exemplo n.º 2
0
 def test_equality(self):
     redditor1 = Redditor(self.reddit, _data={"name": "dummy1", "n": 1})
     redditor2 = Redditor(self.reddit, _data={"name": "Dummy1", "n": 2})
     redditor3 = Redditor(self.reddit, _data={"name": "dummy3", "n": 2})
     assert redditor1 == redditor1
     assert redditor2 == redditor2
     assert redditor3 == redditor3
     assert redditor1 == redditor2
     assert redditor2 != redditor3
     assert redditor1 != redditor3
     assert "dummy1" == redditor1
     assert redditor2 == "dummy1"
Exemplo n.º 3
0
    def test_construct_failure(self):
        message = "Exactly one of `name`, `fullname`, or `_data` must be provided."
        with pytest.raises(TypeError) as excinfo:
            Redditor(self.reddit)
        assert str(excinfo.value) == message

        with pytest.raises(TypeError) as excinfo:
            Redditor(self.reddit, "dummy", _data={"id": "dummy"})
        assert str(excinfo.value) == message

        with pytest.raises(TypeError) as excinfo:
            Redditor(self.reddit, name="dummy", fullname="t2_dummy")
        assert str(excinfo.value) == message

        with pytest.raises(TypeError) as excinfo:
            Redditor(
                self.reddit,
                name="dummy",
                fullname="t2_dummy",
                _data={"id": "dummy"},
            )
        assert str(excinfo.value) == message

        with pytest.raises(AssertionError):
            Redditor(self.reddit, _data=[{"name": "dummy"}])

        with pytest.raises(AssertionError):
            Redditor(self.reddit, _data={"notname": "dummy"})

        with pytest.raises(ValueError):
            Redditor(self.reddit, "")
        with pytest.raises(ValueError):
            Redditor(self.reddit, fullname="")
Exemplo n.º 4
0
 def test__params_not_modified_in_mixed_listing(self):
     params = {"dummy": "value"}
     redditor = Redditor(self.reddit, name="spez")
     for listing in ["controversial", "hot", "new", "top"]:
         generator = getattr(redditor, listing)(params=params)
         assert params == {"dummy": "value"}
         assert listing == generator.params["sort"]
         assert "value" == generator.params["dummy"]
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 async def test_trophies__user_not_exist(self):
     with self.use_cassette():
         redditor = Redditor(self.reddit, "thisusershouldnotexist")
         with pytest.raises(RedditAPIException) as excinfo:
             await redditor.trophies()
         assert "USER_DOESNT_EXIST" == excinfo.value.error_type
Exemplo n.º 7
0
    def mod(self) -> "Redditor":
        """Return the Redditor who the action was issued by."""
        from asyncpraw.models import Redditor

        return Redditor(self._reddit, name=self._mod)  # pylint: disable=no-member
Exemplo n.º 8
0
 def test_str(self):
     redditor = Redditor(self.reddit, _data={"name": "name", "id": "dummy"})
     assert str(redditor) == "name"
Exemplo n.º 9
0
 def test_repr(self):
     redditor = Redditor(self.reddit, name="RedditorName")
     assert repr(redditor) == "Redditor(name='RedditorName')"
Exemplo n.º 10
0
 def test_fullname(self):
     redditor = Redditor(self.reddit, _data={"name": "name", "id": "dummy"})
     assert redditor.fullname == "t2_dummy"