2021-02-15 17:16:51 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-03-10 07:41:46 +08:00
|
|
|
import configparser
|
|
|
|
import socket
|
|
|
|
from pathlib import Path
|
|
|
|
|
2021-02-15 17:16:51 +08:00
|
|
|
import praw
|
|
|
|
import pytest
|
|
|
|
|
2021-04-12 15:58:32 +08:00
|
|
|
from bdfr.oauth2 import OAuth2TokenManager
|
2021-03-10 07:41:46 +08:00
|
|
|
|
2021-02-15 17:16:51 +08:00
|
|
|
|
2022-12-03 13:11:17 +08:00
|
|
|
@pytest.fixture(scope="session")
|
2021-02-15 17:16:51 +08:00
|
|
|
def reddit_instance():
|
2021-04-23 18:47:16 +08:00
|
|
|
rd = praw.Reddit(
|
2022-12-03 13:11:17 +08:00
|
|
|
client_id="U-6gk4ZCh3IeNQ",
|
|
|
|
client_secret="7CZHY6AmKweZME5s50SfDGylaPg",
|
|
|
|
user_agent="test",
|
2021-04-23 18:47:16 +08:00
|
|
|
)
|
2021-02-15 17:16:51 +08:00
|
|
|
return rd
|
2021-03-10 07:41:46 +08:00
|
|
|
|
|
|
|
|
2022-12-03 13:11:17 +08:00
|
|
|
@pytest.fixture(scope="session")
|
2021-03-10 07:41:46 +08:00
|
|
|
def authenticated_reddit_instance():
|
2022-12-03 13:11:17 +08:00
|
|
|
test_config_path = Path("./tests/test_config.cfg")
|
2021-03-10 07:41:46 +08:00
|
|
|
if not test_config_path.exists():
|
2022-12-03 13:11:17 +08:00
|
|
|
pytest.skip("Refresh token must be provided to authenticate with OAuth2")
|
2021-03-10 07:41:46 +08:00
|
|
|
cfg_parser = configparser.ConfigParser()
|
|
|
|
cfg_parser.read(test_config_path)
|
2022-12-03 13:11:17 +08:00
|
|
|
if not cfg_parser.has_option("DEFAULT", "user_token"):
|
|
|
|
pytest.skip("Refresh token must be provided to authenticate with OAuth2")
|
2021-03-10 07:41:46 +08:00
|
|
|
token_manager = OAuth2TokenManager(cfg_parser, test_config_path)
|
2021-04-23 18:47:16 +08:00
|
|
|
reddit_instance = praw.Reddit(
|
2022-12-03 13:11:17 +08:00
|
|
|
client_id=cfg_parser.get("DEFAULT", "client_id"),
|
|
|
|
client_secret=cfg_parser.get("DEFAULT", "client_secret"),
|
2021-04-23 18:47:16 +08:00
|
|
|
user_agent=socket.gethostname(),
|
|
|
|
token_manager=token_manager,
|
|
|
|
)
|
2021-03-10 07:41:46 +08:00
|
|
|
return reddit_instance
|