def runTest(self): fake_plugin = Plugin.byName('fake_plugin') user = User(fullname='User', email='test@localhost') assert fake_plugin.channels_number == 0 pc1 = PluginChannel(plugin=fake_plugin, name='Plugin Channel 1', subscription_right='public') assert fake_plugin.channels_number == 1 pc2 = PluginChannel(plugin=fake_plugin, name='Plugin Channel 2', subscription_right='public') assert fake_plugin.channels_number == 2 pc2.destroySelf() assert fake_plugin.channels_number == 1 pc2 = PluginChannel(plugin=fake_plugin, name='Plugin Channel 2', subscription_right='public') pc3 = PluginChannel(plugin=fake_plugin, name='Plugin Channel 3', subscription_right='public') bundle_channel = ChannelBundle(name='Bundle', subscription_right='public') bundle_channel.add_channel(pc3) building = Building(name='building') screen1 = Screen(name='Screen1', building=building) screen2 = Screen(name='Screen2', building=building) screen3 = Screen(name='Screen3', building=building) assert fake_plugin.screens_number == 0 screen1.subscribe_to(user, pc1) assert fake_plugin.screens_number == 1 screen1.subscribe_to(user, pc2) assert fake_plugin.screens_number == 1 screen2.subscribe_to(user, pc3) assert fake_plugin.screens_number == 2 screen2.subscribe_to(user, bundle_channel) assert fake_plugin.screens_number == 2 screen3.subscribe_to(user, bundle_channel) assert fake_plugin.screens_number == 3
def runTest(self): """ Tests the Channel object. """ try: PluginChannel(name='test', plugin=Plugin(name='channel_plugin', activated='no'), subscription_right='restricted') PluginChannel( name='test2', plugin=Plugin.selectBy(name='channel_plugin').getOne(), subscription_right='restricted') c = PluginChannel.selectBy(name="test").getOne() assert_not_equal(None, c) c.set(name="testNew") assert_equal(c.name, "testNew") u = User(username='******', fullname='test test', email='*****@*****.**', super_admin=True, disabled=False) up = UserPermissions.channel_contributor c.give_permission_to_user(u, up) role = Role.selectBy(user=u, channel=c).getOne(None) assert_true(role != None) c.give_permission_to_user(u, up) role = Role.selectBy(user=u, channel=c).getOne(None) assert_true(role != None) getup = c.get_channel_permissions_of(u) assert_equal(getup, up) getupnoperm = c.get_channel_permissions_of(User.get(1)) assert_equal(getupnoperm, UserPermissions.no_permission) c.remove_permission_to_user(u) role = Role.selectBy(user=u, channel=c).getOne(None) assert_true(role == None) assert_false(c.has_admin(u)) up = UserPermissions.channel_administrator c.give_permission_to_user(u, up) assert_true(c.has_admin(u)) assert_true(c.has_contrib(u)) assert_is_not_none(c.get_admins()) assert_is_not_none(c.get_contribs()) assert_in(str(u.id), c.get_users_as_json()) c.remove_permission_to_user(u) role = Role.selectBy(user=u, channel=c).getOne(None) assert_true(role == None) c.give_permission_to_user(None, up) role = Role.selectBy(user=u).getOne(None) assert_true(role == None) tru = c.has_visible_params_for(u) assert_true(tru) u3 = User(username='******', fullname='test3 test2', email='*****@*****.**', super_admin=False, disabled=False) tru = c.has_visible_params_for(u3) assert_false(tru) t = PluginChannel.delete(c.id) assert_equal(t, None) # try to delete a channel used by a screen - Seems to work... sc = Screen(name='A', building=Building(name='A')) sc.subscribe_to(u, PluginChannel.get(2)) # t2 = PluginChannel.delete(2) c4 = PluginChannel.get(2) nbSub = c4.subscriptions.count() c4.set(enabled=False) assert_equal(nbSub, c4.subscriptions.count()) c4.set(enabled=True) c4.set(subscription_right="private") assert_equal(nbSub, c4.subscriptions.count()) c4.set(subscription_right="public") # todo seems working by bypassing the webinterface c4.set(cache_validity=-10) assert_true(c4.cache_validity < 0) sc.unsubscribe_from(u, PluginChannel.get(2)) u2 = User(username='******', fullname='test2 test2', email='*****@*****.**', super_admin=False, disabled=False) l = PluginChannel.get_screens_channels_from(u2) assert_is_not_none(l) temp = PluginChannel.get_visible_channels_of(u2) assert_is_not_none(temp) User.delete(u.id) User.delete(u2.id) User.delete(u3.id) except DuplicateEntryError: assert_true(False) return
def runTest(self): """ Tests the User SQLObject """ user = User(username='******', fullname='fullname', email='email') fake_plugin = Plugin(name='fake_plugin', activated='notfound') plugin_channel = PluginChannel(plugin=fake_plugin, name='Channel', subscription_right='public') building = Building(name='building') screen = Screen(name='Screen', building=building) screen.subscribe_to(user, plugin_channel) # Miscellaneous test assert user.log_name == 'fullname (%d)' % user.id user.fullname = None assert user.log_name == 'email (%d)' % user.id user.fullname = 'fullname' assert user.log_name == 'fullname (%d)' % user.id assert user.readable_name == 'fullname' user.fullname = None assert user.readable_name == 'username' user.username = None assert user.readable_name == 'email' # Test permissions assert user.highest_permission_level == UserPermissions.no_permission assert list(user.get_subscriptions_of_owned_screens()) == [] assert list( user.get_channels_with_permission_level( UserPermissions.channel_contributor)) == [] assert list( user.get_channels_with_permission_level( UserPermissions.channel_administrator)) == [] plugin_channel.give_permission_to_user( user, UserPermissions.channel_contributor) assert user.highest_permission_level == UserPermissions.channel_contributor assert list( user.get_channels_with_permission_level( UserPermissions.channel_contributor)) == [plugin_channel] assert list( user.get_channels_with_permission_level( UserPermissions.channel_administrator)) == [] plugin_channel.give_permission_to_user( user, UserPermissions.channel_administrator) assert user.highest_permission_level == UserPermissions.channel_administrator assert list( user.get_channels_with_permission_level( UserPermissions.channel_contributor)) == [] assert list( user.get_channels_with_permission_level( UserPermissions.channel_administrator)) == [plugin_channel] plugin_channel.remove_permission_to_user(user) assert user.highest_permission_level == UserPermissions.no_permission assert list(user.get_subscriptions_of_owned_screens()) == [] user.admin = True assert user.highest_permission_level == UserPermissions.administrator assert list(user.get_subscriptions_of_owned_screens()) == list( screen.subscriptions) user.admin = False assert user.highest_permission_level == UserPermissions.no_permission assert list(user.get_subscriptions_of_owned_screens()) == [] user.super_admin = True assert user.highest_permission_level == UserPermissions.super_administrator assert list(user.get_subscriptions_of_owned_screens()) == list( screen.subscriptions) user.super_admin = False assert user.highest_permission_level == UserPermissions.no_permission assert list(user.get_subscriptions_of_owned_screens()) == [] screen.safe_add_user(user) assert user.highest_permission_level == UserPermissions.screen_administrator assert list(user.get_subscriptions_of_owned_screens()) == list( screen.subscriptions) screen.removeUser(user) assert list(user.get_subscriptions_of_owned_screens()) == [] assert user.highest_permission_level == UserPermissions.no_permission
def runTest(self): """ Tests the Screen SQLObject """ Channel.deleteMany(None) Screen.deleteMany(None) channel = Channel(name='Channel', subscription_right='public', secret='abcdef') plugin_channel = PluginChannel(name='Channel2', plugin=Plugin.byName('fake_plugin'), subscription_right='public') plugin_channel2 = PluginChannel(name='Channel3', plugin=Plugin.byName('fake_plugin'), subscription_right='public') bundle_channel = ChannelBundle(name='Channel4', subscription_right='public') bundle_channel.add_channel(plugin_channel2) building = Building(name='building') screen = Screen(name='Screen', building=building, secret='abcdef') screen2 = Screen(name='Screen2', building=building) user = User(fullname='User', email='test@localhost') user2 = User(fullname='User2', email='test2@localhost') # Miscellaneous test assert screen.get_view_link() == '/screens/%d/view/abcdef' % screen.id assert screen.get_client_link( ) == '/screens/%d/client/abcdef' % screen.id assert screen.get_macs_string() == '' assert screen not in user.screens screen.safe_add_user(user) assert screen in user.screens assert screen not in user2.screens screen.removeUser(user) assert screen not in user2.screens # Test subscription assert not screen.is_subscribed_to(channel) screen.subscribe_to(user, channel) assert screen.is_subscribed_to(channel) sub = screen.subscriptions[0] screen.subscribe_to(user2, channel, weight=42) assert sub.created_by == user2 assert sub.weight == 42 assert screen.is_subscribed_to(channel) assert list(screen.subscribed_channels) == [channel] screen.unsubscribe_from(user2, channel) assert not screen.is_subscribed_to(channel) # Test macs ScreenMac(screen=screen, mac='00b16b00b500') ScreenMac(screen=screen, mac='00b16b00b501') assert screen.get_macs_string( ) == '00:b1:6b:00:b5:00;00:b1:6b:00:b5:01' # Test get_visible_screens_of() assert list(Screen.get_visible_screens_of(user)) == list( Screen.get_visible_screens_of(user2)) == [] user.admin = True assert list(Screen.get_visible_screens_of(user)) == [screen, screen2] assert list(Screen.get_visible_screens_of(user2)) == [] user.admin = False user2.super_admin = True assert list(Screen.get_visible_screens_of(user2)) == [screen, screen2] assert list(Screen.get_visible_screens_of(user)) == [] user2.super_admin = False screen.safe_add_user(user) screen2.safe_add_user(user2) assert list(Screen.get_visible_screens_of(user)) == [screen] assert list(Screen.get_visible_screens_of(user2)) == [screen2] # Test channel content screen.subscribe_to(user, plugin_channel) screen.subscribe_to(user, bundle_channel) screen_content = screen.get_channels_content(self.ictv_app) assert len(screen_content) == 2 assert len(screen_content[0].get_slides()) == 1 assert screen_content[0].get_slides()[0].get_content() == { 'background-1': { 'size': 'contain', 'src': '' }, 'title-1': { 'text': 'Channel2' }, 'text-1': { 'text': '' } } assert len(screen_content[1].get_slides()) == 1 assert screen_content[1].get_slides()[0].get_content() == { 'background-1': { 'size': 'contain', 'src': '' }, 'title-1': { 'text': 'Channel3' }, 'text-1': { 'text': '' } } screen.shuffle = True assert len(screen.get_channels_content(self.ictv_app)) == 2