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 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