def test_poll_from_graphql(session): data = { "id": "123456789", "text": "Some poll", "total_count": 5, "viewer_has_voted": "true", "options": [ { "id": "1111", "text": "Abc", "total_count": 1, "viewer_has_voted": "true", "voters": ["1234"], }, { "id": "2222", "text": "Def", "total_count": 2, "viewer_has_voted": "false", "voters": ["2345", "3456"], }, { "id": "3333", "text": "Ghi", "total_count": 0, "viewer_has_voted": "false", "voters": [], }, ], } assert Poll( session=session, question="Some poll", options=[ PollOption(text="Abc", vote=True, voters=["1234"], votes_count=1, id="1111"), PollOption( text="Def", vote=False, voters=["2345", "3456"], votes_count=2, id="2222", ), PollOption(text="Ghi", vote=False, voters=[], votes_count=0, id="3333"), ], options_count=5, id=123456789, ) == Poll._from_graphql(session, data)
def test_poll_option_from_graphql_unvoted(): data = { "id": "123456789", "text": "abc", "total_count": 0, "viewer_has_voted": "false", "voters": [], } assert PollOption(text="abc", vote=False, voters=[], votes_count=0, id="123456789") == PollOption._from_graphql(data)
def test_poll_option_from_graphql_voted(): data = { "id": "123456789", "text": "abc", "total_count": 2, "viewer_has_voted": "true", "voters": ["1234", "2345"], } assert PollOption(text="abc", vote=True, voters=["1234", "2345"], votes_count=2, id="123456789") == PollOption._from_graphql(data)
def hear_meet(client, author_id, message_object, thread_id, thread_type): """Creates poll to decide on time for given date""" global meeting_polls global time_options today = date.today() gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id] try: msg_date = parse(message_object.text.split(' ', 1)[1]) assert (not isinstance(msg_date, type(None))) if msg_date.date() < today: raise ValueError except (IndexError, AssertionError) as e: action_queue.put( Action(client, 'message', thread_id, thread_type, text='I can\'t read that date.')) return except ValueError: action_queue.put( Action(client, 'message', thread_id, thread_type, text='I\'m not stupid that date has passed.')) return meeting = Poll( title=f"Meeting on {datetime.strftime(msg_date, '%A, %x')}. Who's in?", options=[PollOption(text=time) for time in time_options]) action_queue.put( Action(client, 'makepoll', thread_id, thread_type, poll=meeting)) tag_all(client, author_id, None, thread_id, thread_type)
def test_poll_option_from_graphql_alternate_format(): # Format received when fetching poll options data = { "id": "123456789", "text": "abc", "viewer_has_voted": True, "voters": { "count": 2, "edges": [{ "node": { "id": "1234" } }, { "node": { "id": "2345" } }], }, } assert PollOption(text="abc", vote=True, voters=["1234", "2345"], votes_count=2, id="123456789") == PollOption._from_graphql(data)
def test_poll_answered(session): poll_data = { "id": "112233", "text": "A poll", "total_count": 3, "viewer_has_voted": "true", "options": [ { "id": "1002", "text": "Option B", "total_count": 2, "viewer_has_voted": "true", "voters": ["1234", "2345"], }, { "id": "1003", "text": "Option C", "total_count": 1, "viewer_has_voted": "true", "voters": ["1234"], }, { "id": "1001", "text": "Option A", "total_count": 0, "viewer_has_voted": "false", "voters": [], }, ], } data = { "irisSeqId": "1111111", "irisTags": ["DeltaAdminTextMessage", "is_from_iris_fanout"], "messageMetadata": { "actorFbId": "1234", "adminText": 'You changed your vote to "Option B" and 1 other option in the poll: A poll.', "folderId": { "systemFolderId": "INBOX" }, "messageId": "mid.$XYZ", "offlineThreadingId": "11223344556677889900", "skipBumpThread": False, "tags": ["source:titan:web"], "threadKey": { "threadFbId": "4321" }, "threadReadStateEffect": "MARK_UNREAD", "timestamp": "1500000000000", "unsendType": "deny_log_message", }, "participants": ["1234", "2345", "3456"], "requestContext": { "apiArgs": {} }, "tqSeqId": "1111", "type": "group_poll", "untypedData": { "added_option_ids": "[1002,1003]", "removed_option_ids": "[1001]", "question_json": _util.json_minimal(poll_data), "event_type": "update_vote", "question_id": "112233", }, "class": "AdminTextMessage", } assert PollVoted( author=User(session=session, id="1234"), thread=Group(session=session, id="4321"), poll=Poll( session=session, id="112233", question="A poll", options=[ PollOption( id="1002", text="Option B", vote=True, voters=["1234", "2345"], votes_count=2, ), PollOption( id="1003", text="Option C", vote=True, voters=["1234"], votes_count=1, ), PollOption(id="1001", text="Option A", vote=False, voters=[], votes_count=0), ], options_count=3, ), added_ids=["1002", "1003"], removed_ids=["1001"], at=datetime.datetime(2017, 7, 14, 2, 40, tzinfo=datetime.timezone.utc), ) == parse_admin_message(session, data)
import pytest from fbchat import Poll, PollOption, ThreadType from utils import random_hex, subset pytestmark = pytest.mark.online @pytest.fixture( scope="module", params=[ Poll(title=random_hex(), options=[]), Poll( title=random_hex(), options=[ PollOption(random_hex(), vote=True), PollOption(random_hex(), vote=True), ], ), Poll( title=random_hex(), options=[ PollOption(random_hex(), vote=False), PollOption(random_hex(), vote=False), ], ), Poll( title=random_hex(), options=[ PollOption(random_hex(), vote=True), PollOption(random_hex(), vote=True),