This repository has been archived on 2025-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
fbchat/tests/test_thread.py
Mads Marquart 8b6d9b16c6 Remove ThreadColor
Replaced with raw color values. In the future, we should probably
investigate using "themes"
2020-01-09 21:00:34 +01:00

64 lines
2.1 KiB
Python

import pytest
import fbchat
from fbchat import ThreadABC, Thread
def test_parse_color():
assert "#0084ff" == ThreadABC._parse_color(None)
assert "#0084ff" == ThreadABC._parse_color("")
assert "#44bec7" == ThreadABC._parse_color("FF44BEC7")
assert "#adbeef" == ThreadABC._parse_color("DEADBEEF")
def test_thread_parse_customization_info_empty():
default = {"color": "#0084ff", "emoji": None}
assert default == ThreadABC._parse_customization_info(None)
assert default == ThreadABC._parse_customization_info({"customization_info": None})
def test_thread_parse_customization_info_group():
data = {
"thread_key": {"thread_fbid": "11111", "other_user_id": None},
"customization_info": {
"emoji": "🎉",
"participant_customizations": [
{"participant_id": "123456789", "nickname": "A"},
{"participant_id": "987654321", "nickname": "B"},
],
"outgoing_bubble_color": "FFFF5CA1",
},
"customization_enabled": True,
"thread_type": "GROUP",
# ... Other irrelevant fields
}
expected = {
"emoji": "🎉",
"color": "#ff5ca1",
"nicknames": {"123456789": "A", "987654321": "B"},
}
assert expected == ThreadABC._parse_customization_info(data)
def test_thread_parse_customization_info_user():
data = {
"thread_key": {"thread_fbid": None, "other_user_id": "987654321"},
"customization_info": {
"emoji": None,
"participant_customizations": [
{"participant_id": "123456789", "nickname": "A"},
{"participant_id": "987654321", "nickname": "B"},
],
"outgoing_bubble_color": None,
},
"customization_enabled": True,
"thread_type": "ONE_TO_ONE",
# ... Other irrelevant fields
}
expected = {"emoji": None, "color": "#0084ff", "own_nickname": "A", "nickname": "B"}
assert expected == ThreadABC._parse_customization_info(data)
def test_thread_create_and_implements_thread_abc(session):
thread = Thread(session=session, id="123")
assert thread._parse_customization_info