| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import pytest
- from click.testing import CliRunner
- from bs4 import BeautifulSoup
- from twhatter.api import ApiUser
- from twhatter.parser import TweetList
- from typing import NamedTuple
- @pytest.fixture
- def cli_runner():
- """Runner for Click"""
- return CliRunner()
- @pytest.fixture(scope="session")
- def user():
- return "the_english_way"
- @pytest.fixture(scope="session")
- def tweet_limit():
- return 10
- # Fixtures for extraction of specific tweets of several kinds, whose author
- # and id are known in advance
- class TweetInfo(NamedTuple):
- """Class to hold information about a tweet that is already known"""
- id: int
- screen_name: str
- user_id: int
- comments_nb: int = None
- retweets_nb: int = None
- likes_nb: int = None
- retweeter: str = None
- @pytest.fixture(scope="session")
- def tweet_collection():
- return {
- 'plain': TweetInfo(
- id=1077838164813848576,
- screen_name="the_english_way",
- user_id=943804775942033408
- ),
- 'reaction_tweet': TweetInfo(
- id=1078281840945963008,
- screen_name="the_english_way",
- user_id=943804775942033408
- ),
- 'with_link': TweetInfo(
- id=1078281840945963008,
- screen_name="the_english_way",
- user_id=943804775942033408
- ),
- 'retweet': TweetInfo(
- id=1055037291108974592,
- screen_name="Senficon",
- user_id=14861745,
- retweeter="the_english_way"
- ),
- 'stats': TweetInfo(
- id=1039969574555471873,
- screen_name="BurgerQuizOff",
- user_id=949604705772228608,
- retweeter="the_english_way",
- comments_nb=12,
- retweets_nb=176,
- likes_nb=556
- ),
- }
- @pytest.fixture(scope="session")
- def raw_html_user_initial_page_factory():
- def _raw_html_user_initial_page(user):
- a = ApiUser(user)
- response = a.get_initial()
- return BeautifulSoup(response.text, "lxml")
- return _raw_html_user_initial_page
- @pytest.fixture(scope="session")
- def raw_html_user_initial_page(raw_html_user_initial_page_factory, user):
- return raw_html_user_initial_page_factory(user)
- @pytest.fixture(scope="session")
- def raw_tweet_factory(raw_html_user_initial_page_factory):
- def _raw_tweet_factory(tweet_info):
- user_page = tweet_info.retweeter or tweet_info.screen_name
- soup = raw_html_user_initial_page_factory(user_page)
- return soup.find(id="stream-item-tweet-{}".format(tweet_info.id))
- return _raw_tweet_factory
|