-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #472 from das7pad/hotfix/default-user-detection
[user] extend default user detection
- Loading branch information
Showing
2 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
"""Tests for the user module""" | ||
|
||
|
||
import hangups.user | ||
import hangups.hangouts_pb2 | ||
|
||
|
||
USER_ID = hangups.user.UserID(1, 1) | ||
|
||
|
||
def test_default_type_detection_empty_0(): | ||
# missing names | ||
user = hangups.user.User( | ||
USER_ID, | ||
full_name='', | ||
first_name='', | ||
photo_url='', | ||
emails=[], | ||
is_self=False, | ||
) | ||
|
||
assert user.full_name == hangups.user.DEFAULT_NAME | ||
assert user.first_name == hangups.user.DEFAULT_NAME | ||
assert user.name_type == hangups.user.NameType.DEFAULT | ||
|
||
|
||
def test_default_type_detection_empty_1(): | ||
# missing names | ||
user = hangups.user.User( | ||
USER_ID, | ||
full_name=None, | ||
first_name=None, | ||
photo_url='', | ||
emails=[], | ||
is_self=False, | ||
) | ||
|
||
assert user.full_name == hangups.user.DEFAULT_NAME | ||
assert user.first_name == hangups.user.DEFAULT_NAME | ||
assert user.name_type == hangups.user.NameType.DEFAULT | ||
|
||
|
||
def test_default_type_detection_from_conv_part_data(): | ||
# default user in 201904 | ||
conv_part_data = hangups.hangouts_pb2.ConversationParticipantData( | ||
id=hangups.hangouts_pb2.ParticipantId( | ||
chat_id='1', | ||
gaia_id='1' | ||
), | ||
fallback_name='unknown', | ||
invitation_status=hangups.hangouts_pb2.INVITATION_STATUS_ACCEPTED, | ||
participant_type=hangups.hangouts_pb2.PARTICIPANT_TYPE_GAIA, | ||
new_invitation_status=hangups.hangouts_pb2.INVITATION_STATUS_ACCEPTED, | ||
) | ||
|
||
user = hangups.user.User.from_conv_part_data( | ||
conv_part_data=conv_part_data, | ||
self_user_id=USER_ID | ||
) | ||
|
||
assert user.full_name == hangups.user.DEFAULT_NAME | ||
assert user.first_name == hangups.user.DEFAULT_NAME | ||
assert user.name_type == hangups.user.NameType.DEFAULT | ||
|
||
|
||
def test_real_type(): | ||
# regular name | ||
user = hangups.user.User( | ||
USER_ID, | ||
full_name='Joe Doe', | ||
first_name='Joe', | ||
photo_url='', | ||
emails=[], | ||
is_self=False, | ||
) | ||
|
||
assert user.full_name == 'Joe Doe' | ||
assert user.first_name == 'Joe' | ||
assert user.name_type == hangups.user.NameType.REAL | ||
|
||
|
||
def test_real_type_from_conv_part_data(): | ||
conv_part_data = hangups.hangouts_pb2.ConversationParticipantData( | ||
id=hangups.hangouts_pb2.ParticipantId( | ||
chat_id='1', | ||
gaia_id='1' | ||
), | ||
fallback_name='Joe Doe', | ||
invitation_status=hangups.hangouts_pb2.INVITATION_STATUS_ACCEPTED, | ||
participant_type=hangups.hangouts_pb2.PARTICIPANT_TYPE_GAIA, | ||
new_invitation_status=hangups.hangouts_pb2.INVITATION_STATUS_ACCEPTED, | ||
) | ||
|
||
user = hangups.user.User.from_conv_part_data( | ||
conv_part_data=conv_part_data, | ||
self_user_id=USER_ID | ||
) | ||
|
||
assert user.full_name == 'Joe Doe' | ||
assert user.first_name == 'Joe' | ||
assert user.name_type == hangups.user.NameType.REAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters