mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-03-07 01:47:32 +01:00
Avance
This commit is contained in:
1
srcantiguo/test/sessions/twitter/__init__.py
Normal file
1
srcantiguo/test/sessions/twitter/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
13
srcantiguo/test/sessions/twitter/conftest.py
Normal file
13
srcantiguo/test/sessions/twitter/conftest.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
from tweepy.models import Status
|
||||
|
||||
@pytest.fixture
|
||||
def basic_tweet():
|
||||
data = {'created_at': 'Mon Jan 03 15:03:36 +0000 2022', 'id': 1478019218884857856, 'id_str': '1478019218884857856', 'full_text': 'Changes in projects for next year https://t.co/nW3GS9RmHd', 'truncated': False, 'display_text_range': [0, 57], 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [], 'urls': [{'url': 'https://t.co/nW3GS9RmHd', 'expanded_url': 'https://manuelcortez.net/blog/changes-in-projects-for-next-year/#.YdMQQU6t1FI.twitter', 'display_url': 'manuelcortez.net/blog/changes-i…', 'indices': [34, 57]}]}, 'source': '<a href="https://mobile.twitter.com" rel="nofollow">Twitter Web App</a>', 'in_reply_to_status_id': None, 'in_reply_to_status_id_str': None, 'in_reply_to_user_id': None, 'in_reply_to_user_id_str': None, 'in_reply_to_screen_name': None, 'user': {'id': 258677951, 'id_str': '258677951', 'name': 'Manuel Cortez', 'screen_name': 'manuelcortez00', 'location': 'Nuevo León, México', 'description': 'Python developer, , interested in reading, accessibility, astronomy, physics and science. Я учу русский.', 'url': 'https://t.co/JFRKRA73ZV', 'entities': {'url': {'urls': [{'url': 'https://t.co/JFRKRA73ZV', 'expanded_url': 'https://manuelcortez.net', 'display_url': 'manuelcortez.net', 'indices': [0, 23]}]}, 'description': {'urls': []}}, 'protected': False, 'followers_count': 1453, 'friends_count': 568, 'listed_count': 45, 'created_at': 'Mon Feb 28 06:52:48 +0000 2011', 'favourites_count': 283, 'utc_offset': None, 'time_zone': None, 'geo_enabled': True, 'verified': False, 'statuses_count': 43371, 'lang': None, 'contributors_enabled': False, 'is_translator': False, 'is_translation_enabled': False, 'profile_background_color': 'C0DEED', 'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png', 'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png', 'profile_background_tile': False, 'profile_image_url': 'http://pbs.twimg.com/profile_images/442466677645508608/3EBBC-OX_normal.jpeg', 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/442466677645508608/3EBBC-OX_normal.jpeg', 'profile_image_extensions_alt_text': None, 'profile_link_color': '1DA1F2', 'profile_sidebar_border_color': 'C0DEED', 'profile_sidebar_fill_color': 'DDEEF6', 'profile_text_color': '333333', 'profile_use_background_image': True, 'has_extended_profile': False, 'default_profile': True, 'default_profile_image': False, 'following': False, 'follow_request_sent': False, 'notifications': False, 'translator_type': 'regular', 'withheld_in_countries': []}, 'geo': None, 'coordinates': None, 'place': None, 'contributors': None, 'is_quote_status': False, 'retweet_count': 6, 'favorite_count': 2, 'favorited': False, 'retweeted': False, 'possibly_sensitive': False, 'possibly_sensitive_appealable': False, 'lang': 'en'}
|
||||
yield Status().parse(api=None, json=data)
|
||||
|
||||
@pytest.fixture
|
||||
def basic_tweet_multiple_mentions():
|
||||
data = {'created_at': 'Mon Dec 27 21:21:25 +0000 2021', 'id': 1475577584947707909, 'id_str': '1475577584947707909', 'full_text': '@tamaranatalia9 @Darkstrings @Chris88171572 @manuelcortez00 Well done, thanks Tamara', 'truncated': False, 'display_text_range': [60, 84], 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [{'screen_name': 'tamaranatalia9', 'name': 'Tamara', 'id': 914114584591597568, 'id_str': '914114584591597568', 'indices': [0, 15]}, {'screen_name': 'Darkstrings', 'name': 'Luc', 'id': 1374154151115042823, 'id_str': '1374154151115042823', 'indices': [16, 28]}, {'screen_name': 'Chris88171572', 'name': 'Chris', 'id': 1323980014799495168, 'id_str': '1323980014799495168', 'indices': [29, 43]}, {'screen_name': 'manuelcortez00', 'name': 'Manuel Cortez', 'id': 258677951, 'id_str': '258677951', 'indices': [44, 59]}], 'urls': []}, 'source': '<a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a>', 'in_reply_to_status_id': 1475550502083563526, 'in_reply_to_status_id_str': '1475550502083563526', 'in_reply_to_user_id': 914114584591597568, 'in_reply_to_user_id_str': '914114584591597568', 'in_reply_to_screen_name': 'tamaranatalia9', 'user': {'id': 784837522157436929, 'id_str': '784837522157436929', 'name': 'Paulus', 'screen_name': 'PauloPer01', 'location': '', 'description': '', 'url': None, 'entities': {'description': {'urls': []}}, 'protected': False, 'followers_count': 1082, 'friends_count': 3029, 'listed_count': 2, 'created_at': 'Sat Oct 08 19:27:01 +0000 2016', 'favourites_count': 78862, 'utc_offset': None, 'time_zone': None, 'geo_enabled': False, 'verified': False, 'statuses_count': 4976, 'lang': None, 'contributors_enabled': False, 'is_translator': False, 'is_translation_enabled': False, 'profile_background_color': 'F5F8FA', 'profile_background_image_url': None, 'profile_background_image_url_https': None, 'profile_background_tile': False, 'profile_image_url': 'http://pbs.twimg.com/profile_images/1464572633014587395/246oPPLa_normal.jpg', 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1464572633014587395/246oPPLa_normal.jpg', 'profile_image_extensions_alt_text': None, 'profile_link_color': '1DA1F2', 'profile_sidebar_border_color': 'C0DEED', 'profile_sidebar_fill_color': 'DDEEF6', 'profile_text_color': '333333', 'profile_use_background_image': True, 'has_extended_profile': True, 'default_profile': True, 'default_profile_image': False, 'following': False, 'follow_request_sent': False, 'notifications': False, 'translator_type': 'none', 'withheld_in_countries': []}, 'geo': None, 'coordinates': None, 'place': None, 'contributors': None, 'is_quote_status': False, 'retweet_count': 1, 'favorite_count': 2, 'favorited': False, 'retweeted': False, 'lang': 'en'}
|
||||
yield Status().parse(api=None, json=data)
|
||||
52
srcantiguo/test/sessions/twitter/test_twitter_templates.py
Normal file
52
srcantiguo/test/sessions/twitter/test_twitter_templates.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
import gettext
|
||||
import datetime
|
||||
gettext.install("test")
|
||||
from unittest import mock
|
||||
from sessions.twitter import templates
|
||||
|
||||
def test_default_values():
|
||||
""" Tests wheter default values are the expected ones.
|
||||
This might be useful so we will have this failing when we update anything from those values.
|
||||
As TWBlue might be using those from other dialogs.
|
||||
"""
|
||||
assert templates.tweet_variables == ["date", "display_name", "screen_name", "source", "lang", "text", "image_descriptions"]
|
||||
assert templates.dm_variables == ["date", "sender_display_name", "sender_screen_name", "recipient_display_name", "recipient_display_name", "text"]
|
||||
assert templates.person_variables == ["display_name", "screen_name", "location", "description", "followers", "following", "listed", "likes", "tweets", "created_at"]
|
||||
|
||||
@pytest.mark.parametrize("offset, language, expected_result", [
|
||||
(0, "en_US", "Wednesday, October 10, 2018 20:19:24"),
|
||||
(-21600, "en_US", "Wednesday, October 10, 2018 14:19:24"),
|
||||
(7200, "en_US", "Wednesday, October 10, 2018 22:19:24"),
|
||||
(0, "es_ES", "miércoles, octubre 10, 2018 20:19:24"),
|
||||
(-21600, "es_ES", "miércoles, octubre 10, 2018 14:19:24"),
|
||||
(7200, "es_ES", "miércoles, octubre 10, 2018 22:19:24"),
|
||||
(18000, "es_ES", "jueves, octubre 11, 2018 1:19:24"),
|
||||
])
|
||||
def test_process_date_absolute_time(offset, language, expected_result):
|
||||
""" Tests date processing function for tweets, when relative_times is set to False. """
|
||||
# Date representation used by twitter, converted to datetime object, as tweepy already does this.
|
||||
# Original date was Wed Oct 10 20:19:24 +0000 2018
|
||||
date_field = datetime.datetime(2018, 10, 10, 20, 19, 24)
|
||||
with mock.patch("languageHandler.curLang", new=language):
|
||||
processed_date = templates.process_date(date_field, relative_times=False, offset_seconds=offset)
|
||||
assert processed_date == expected_result
|
||||
|
||||
def test_process_date_relative_time():
|
||||
date_field = datetime.datetime(2018, 10, 10, 20, 19, 24)
|
||||
with mock.patch("languageHandler.curLang", new="es_ES"):
|
||||
processed_date = templates.process_date(date_field, relative_times=True, offset_seconds=7200)
|
||||
# As this depends in relative times and this is subject to change, let's do some light checks here and hope the string is going to be valid.
|
||||
assert isinstance(processed_date, str)
|
||||
assert "hace" in processed_date and "años" in processed_date
|
||||
|
||||
def test_process_text_basic_tweet(basic_tweet):
|
||||
expected_result = "Changes in projects for next year https://manuelcortez.net/blog/changes-in-projects-for-next-year/#.YdMQQU6t1FI.twitter"
|
||||
text = templates.process_text(basic_tweet)
|
||||
assert text == expected_result
|
||||
|
||||
def test_process_text_basic_tweet_multiple_mentions(basic_tweet_multiple_mentions):
|
||||
expected_result = "@tamaranatalia9, @Darkstrings and 2 more: Well done, thanks Tamara"
|
||||
text = templates.process_text(basic_tweet_multiple_mentions)
|
||||
assert text == expected_result
|
||||
Reference in New Issue
Block a user