How to use prawcore - 10 common examples

To help you get started, we’ve selected a few prawcore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github praw-dev / prawcore / tests / test_authenticator.py View on Github external
def test_authorize_url__fail_with_implicit(self):
        authenticator = prawcore.TrustedAuthenticator(
            REQUESTOR, CLIENT_ID, CLIENT_SECRET, REDIRECT_URI
        )
        self.assertRaises(
            prawcore.InvalidInvocation,
            authenticator.authorize_url,
            "temporary",
            ["identity", "read"],
            "a_state",
            implicit=True,
        )
github praw-dev / praw / tests / unit / test_reddit.py View on Github external
def test_requestor_class(self):
        class CustomRequestor(Requestor):
            pass

        reddit = Reddit(
            client_id="dummy",
            client_secret="dummy",
            password="dummy",
            user_agent="dummy",
            username="dummy",
            requestor_class=CustomRequestor,
        )
        assert isinstance(reddit._core._requestor, CustomRequestor)
        assert not isinstance(self.reddit._core._requestor, CustomRequestor)

        reddit = Reddit(
            client_id="dummy",
            client_secret="dummy",
github praw-dev / praw / tests / integration / models / reddit / test_subreddit.py View on Github external
def test_sticky__not_set(self):
        subreddit = self.reddit.subreddit(pytest.placeholders.test_subreddit)
        with self.recorder.use_cassette("TestSubreddit.test_sticky__not_set"):
            with pytest.raises(NotFound):
                subreddit.sticky(2)
github praw-dev / praw / tests / integration / models / reddit / test_subreddit.py View on Github external
def test_traffic__not_public(self):
        subreddit = self.reddit.subreddit("announcements")
        with self.recorder.use_cassette(
            "TestSubreddit.test_traffic__not_public"
        ):
            with pytest.raises(NotFound):
                subreddit.traffic()
github praw-dev / praw / tests / integration / models / reddit / test_wikipage.py View on Github external
def test_invalid_page(self):
        subreddit = self.reddit.subreddit(pytest.placeholders.test_subreddit)
        page = WikiPage(self.reddit, subreddit, "invalid")
        with self.recorder.use_cassette("TestWikiPage.test_invalid_page"):
            with pytest.raises(NotFound):
                page.content_md
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def test_init__with_device_id_authorizer(self):
        authenticator = prawcore.UntrustedAuthenticator(REQUESTOR, CLIENT_ID)
        authorizer = prawcore.DeviceIDAuthorizer(authenticator)
        prawcore.Session(authorizer)
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def test_request__unsupported_media_type(self):
        with Betamax(REQUESTOR).use_cassette(
            "Session_request__unsupported_media_type"
        ):
            session = prawcore.Session(script_authorizer())
            exception_class = prawcore.SpecialError
            data = {
                "content": "type: submission\naction: upvote",
                "page": "config/automoderator",
            }
            with self.assertRaises(exception_class) as context_manager:
                session.request("POST", "r/ttft/api/wiki/edit/", data=data)
            self.assertEqual(
                415, context_manager.exception.response.status_code
            )
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def test_request__cloudflare_connection_timed_out(self):
        with Betamax(REQUESTOR).use_cassette(
            "Session_request__cloudflare_connection_timed_out"
        ):
            session = prawcore.Session(readonly_authorizer())
            with self.assertRaises(prawcore.ServerError) as context_manager:
                session.request("GET", "/")
                session.request("GET", "/")
                session.request("GET", "/")
            self.assertEqual(
                522, context_manager.exception.response.status_code
            )
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def test_request__bad_gateway(self):
        with Betamax(REQUESTOR).use_cassette("Session_request__bad_gateway"):
            session = prawcore.Session(readonly_authorizer())
            with self.assertRaises(prawcore.ServerError) as context_manager:
                session.request("GET", "/")
            self.assertEqual(
                502, context_manager.exception.response.status_code
            )
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def test_request__raw_json(self):
        with Betamax(REQUESTOR).use_cassette("Session_request__raw_json"):
            session = prawcore.Session(readonly_authorizer())
            response = session.request(
                "GET",
                ("/r/reddit_api_test/comments/" "45xjdr/want_raw_json_test/"),
            )
        self.assertEqual(
            "WANT_RAW_JSON test: < > &",
            response[0]["data"]["children"][0]["data"]["title"],
        )