23 lines
749 B
Python
23 lines
749 B
Python
from __future__ import annotations
|
|
|
|
from twitter_cli.serialization import tweet_from_dict, tweet_to_dict, tweets_from_json, tweets_to_json
|
|
|
|
|
|
def test_tweet_roundtrip_dict(tweet_factory) -> None:
|
|
tweet = tweet_factory("42")
|
|
payload = tweet_to_dict(tweet)
|
|
restored = tweet_from_dict(payload)
|
|
|
|
assert restored.id == tweet.id
|
|
assert restored.author.screen_name == tweet.author.screen_name
|
|
assert restored.metrics.likes == tweet.metrics.likes
|
|
|
|
|
|
def test_tweets_json_roundtrip(tweet_factory) -> None:
|
|
tweets = [tweet_factory("1"), tweet_factory("2", lang="zh")]
|
|
raw = tweets_to_json(tweets)
|
|
restored = tweets_from_json(raw)
|
|
|
|
assert [tweet.id for tweet in restored] == ["1", "2"]
|
|
assert restored[1].lang == "zh"
|