def test_user_shortname_with_no_values(self): user = User(id='', name='', real_name='', team_id='', profile=Profile(real_name='', display_name='', real_name_normalized='', display_name_normalized='', team='')) self.assertEqual(user.get_short_name(), 'unknown')
def get_user(self, user_id) -> Optional[User]: return cache.get_or_set( key=User.create_key(user_id), default=lambda: self.__get(User, 'users.info', 'user', user=user_id) )
def test_cache_key_creation_on_instance(self): user = User.from_json(user_json) self.assertEqual('User:W012A3CDE', user.key())
def test_cache_key_creation(self): self.assertEqual('User:W012A3CDE', User.create_key('W012A3CDE'))
def test_user_short_name_with_null_profile(self): user_obj: User = User.from_json(user_json) user_obj.profile = None self.assertEqual('spengler', user_obj.get_short_name())
def test_user_short_name_with_empty_display_name(self): user_obj: User = User.from_json(user_json) user_obj.profile.display_name_normalized = '' user_obj.profile.display_name = '' self.assertEqual('Real Name Normalized', user_obj.get_short_name())
def test_user_short_name(self): user_obj: User = User.from_json(user_json) self.assertEqual('displaynamenormalized', user_obj.get_short_name())
def test_user_deserialization(self): user_obj: User = User.from_json(user_json) self.assertEqual('displaynamenormalized', user_obj.profile.display_name_normalized)
def test_user_deserialization_from_empty(self): with self.assertRaises(KeyError): user = User.from_dict({})
def test_user_deserialization_from_null(self): with self.assertRaises(AttributeError): user = User.from_dict(None)
"image_192": "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg", "image_512": "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg", "team": "T012AB3C4" }, "is_admin": true, "is_owner": false, "is_primary_owner": false, "is_restricted": false, "is_ultra_restricted": false, "is_bot": false, "updated": 1502138686, "is_app_user": false, "has_2fa": false } }""" USER_OK_MODEL = User.from_dict(json.loads(USER_OK)['user']) class TestClient: @pytest.fixture() def client(self) -> SlackApiClient: yield SlackApiClient('test-token') @pytest.mark.parametrize('cid, payload, expected', [ ('test_ok', { 'ok': True, 'messages': [{ 'user': '******', 'text': 'Im great', 'ts': '1581947248' }]