<commit_before>"""Test praw.models.auth."""
from praw import Reddit
from praw.exceptions import ClientException
import pytest

from .. import UnitTest


class TestAuth(UnitTest):
    def test_implicit__from_script_app(self):
        with pytest.raises(ClientException):
            self.reddit.auth.implicit('dummy token', 10, '')

    def test_url__installed_app(self):
        reddit = Reddit(client_id='dummy client', client_secret=None,
                        redirect_uri='https://dummy.tld/',
                        user_agent='dummy')
        url = reddit.auth.url(['dummy scope'], 'dummy state')
        assert 'client_id=dummy+client' in url
        assert 'redirect_uri=https%3A%2F%2Fdummy.tld%2F' in url
        assert 'scope=dummy+scope' in url
        assert 'state=dummy+state' in url

    def test_url__web_app(self):
        reddit = Reddit(client_id='dummy client', client_secret='dummy secret',
                        redirect_uri='https://dummy.tld/', user_agent='dummy')
        url = reddit.auth.url(['dummy scope'], 'dummy state')
        assert 'client_id=dummy+client' in url
        assert 'secret' not in url
        assert 'redirect_uri=https%3A%2F%2Fdummy.tld%2F' in url
        assert 'scope=dummy+scope' in url
        assert 'state=dummy+state' in url

    def test_url__web_app_without_redirect_uri(self):
        reddit = Reddit(client_id='dummy client', client_secret='dummy secret',
                        user_agent='dummy')
        with pytest.raises(ClientException):
            reddit.auth.url(['dummy scope'], 'dummy state')<commit_msg>Create three _app factories in Auth unit test.<commit_after>"""Test praw.models.auth."""
from praw import Reddit
from praw.exceptions import ClientException
import pytest

from .. import UnitTest


def installed_app():
    return Reddit(client_id='dummy client', client_secret=None,
                  redirect_uri='https://dummy.tld/', user_agent='dummy')


def script_app():
    return Reddit(client_id='dummy client', client_secret='dummy secret',
                  password='<PASSWORD>', user_agent='dummy',
                  username='dummy username')


def web_app():
    return Reddit(client_id='dummy client', client_secret='dummy secret',
                  redirect_uri='https://dummy.tld/', user_agent='dummy')


class TestAuth(UnitTest):
    def test_implicit__from_script_app(self):
        with pytest.raises(ClientException):
            script_app().auth.implicit('dummy token', 10, '')

    def test_url__installed_app(self):
        url = installed_app().auth.url(['dummy scope'], 'dummy state')
        assert 'client_id=dummy+client' in url
        assert 'redirect_uri=https%3A%2F%2Fdummy.tld%2F' in url
        assert 'scope=dummy+scope' in url
        assert 'state=dummy+state' in url

    def test_url__web_app(self):
        url = web_app().auth.url(['dummy scope'], 'dummy state')
        assert 'client_id=dummy+client' in url
        assert 'secret' not in url
        assert 'redirect_uri=https%3A%2F%2Fdummy.tld%2F' in url
        assert 'scope=dummy+scope' in url
        assert 'state=dummy+state' in url

    def test_url__web_app_without_redirect_uri(self):
        reddit = Reddit(client_id='dummy client', client_secret='dummy secret',
                        user_agent='dummy')
        with pytest.raises(ClientException):
            reddit.auth.url(['dummy scope'], 'dummy state')
{'fraction_non_alphanumeric': 0.1188235294117647, 'fraction_numerical': 0.0058823529411764705, 'mean_word_length': 3.082833133253301, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6250723', 'n_tokens_mistral': 1005, 'n_tokens_neox': 993, 'n_words': 225}