def test_team_member_authenticates_just_to_channels_he_belongs(self): user_id = 0 team_id = 0 channel_id = 0 token = Authenticator.generate(user_id) authentication = MagicMock() authentication.token = token authentication.team_id = team_id authentication.channel_id = channel_id '''Mocked outputs''' user = User(user_id=user_id, token=token) team_user = PublicUser(user_id=user_id) team_user.team_role = TeamRoles.MEMBER.value team_user.team_id = team_id channel_user = PublicUser(user_id=user_id) channel_user.team_id = team_id channel_user.channel_id = channel_id channel_user.is_channel_creator = False sys.modules[ "daos.users"].UserDatabaseClient.get_user_by_id.return_value = user sys.modules[ "daos.users"].UserDatabaseClient.get_team_user_by_ids.return_value = team_user sys.modules[ "daos.users"].UserDatabaseClient.get_channel_user_by_ids.return_value = channel_user authenticated_user = Authenticator.authenticate_channel(authentication) self.assertEqual(user_id, authenticated_user.id) self.assertEqual(team_id, authenticated_user.team_id) self.assertEqual(channel_id, authenticated_user.channel_id) self.assertFalse(authenticated_user.is_channel_creator)
def to_channel_user(cls, table_entry): if table_entry is None: return None user = PublicUser(user_id=table_entry.user_id, username=table_entry.username, email=table_entry.email, first_name=table_entry.first_name, last_name=table_entry.last_name, profile_pic=table_entry.profile_pic, online=table_entry.online, role=table_entry.role, created=table_entry.created) user.team_id = table_entry.team_id user.channel_id = table_entry.channel_id user.is_channel_creator = table_entry.creator == table_entry.user_id return user
def test_channel_regular_member_authenticating_to_channel_moderation_throws_exception( self): user_id = 0 team_id = 0 channel_id = 0 token = Authenticator.generate(user_id) authentication = MagicMock() authentication.token = token authentication.team_id = team_id authentication.channel_id = channel_id '''Mocked outputs''' user = User(user_id=user_id, token=token) team_user = PublicUser(user_id=user_id) team_user.team_role = TeamRoles.MEMBER.value team_user.team_id = team_id channel_user = PublicUser(user_id=user_id) channel_user.team_id = team_id channel_user.channel_id = channel_id channel_user.is_channel_creator = False sys.modules[ "daos.users"].UserDatabaseClient.get_user_by_id.return_value = user sys.modules[ "daos.users"].UserDatabaseClient.get_team_user_by_ids.return_value = team_user sys.modules[ "daos.users"].UserDatabaseClient.get_channel_user_by_ids.return_value = channel_user self.assertRaises(NoPermissionsError, Authenticator.authenticate_channel, authentication, TeamRoles.is_channel_creator) channel_user.is_channel_creator = True sys.modules[ "daos.users"].UserDatabaseClient.get_channel_user_by_ids.return_value = channel_user authenticated_user = Authenticator.authenticate_channel( authentication, TeamRoles.is_channel_creator) self.assertEqual(user_id, authenticated_user.id) self.assertEqual(team_id, authenticated_user.team_id) self.assertEqual(channel_id, authenticated_user.channel_id) self.assertTrue(authenticated_user.is_channel_creator)