def assert_no_creation(status=200): assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert ChannelBundle.selectBy( name=bundle_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy( name=bundle_params['name']).getOne(None) is None
def runTest(self): """ Tests the Role object. """ try: u = User(username='******', fullname='test test', email='*****@*****.**', super_admin=True, disabled=False) PluginChannel(name='test', plugin=Plugin(name='role_plugin', activated='no'), subscription_right='restricted') c = PluginChannel.selectBy(name="test").getOne() r = Role(user=u, channel=c, permission_level=UserPermissions.channel_contributor) assert_true(r != None) assert_true( r.permission_level == UserPermissions.channel_contributor) r.permission_level = UserPermissions.channel_administrator assert_true( r.permission_level == UserPermissions.channel_administrator) Role.delete(r.id) role = Role.selectBy(user=u, channel=c).getOne(None) assert_true(role == None) PluginChannel.delete(c.id) User.delete(u.id) except DuplicateEntryError: assert_true(False)
def assert_no_deletion(channel_params=channel_params, bundle_params=bundle_params, status=200): assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy(id=pc1_id).getOne(None) is not None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy( id=bundle_id).getOne(None) is not None
def assert_deletion(channel_params=channel_params, bundle_params=bundle_params, status=200): assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy(id=pc1_id).getOne(None) is None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy(id=bundle_id).getOne(None) is None return (PluginChannel(plugin=self.fake_plugin, name='PC 1', subscription_right='public').id, ChannelBundle(name='Bundle', subscription_right='public').id)
def runTest(self): """ Tests the cache mecanism. """ u = User(username='******', fullname='testasset test', email='*****@*****.**', super_admin=True, disabled=False) PluginChannel(name='testasset2', plugin=Plugin(name='cache_plugin', activated='no'), subscription_right='restricted') c = PluginChannel.selectBy(name="testasset2").getOne() a = Asset(plugin_channel=c, user=u) self.testApp.get('/cache/' + str(a.id), status=303) try: Asset.delete(a.id) except SQLObjectNotFound: pass finally: User.delete(u.id) PluginChannel.delete(c.id)
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 channels creation via the Channels page """ channel_params = { 'action': 'create-channel', 'name': 'Plugin Channel test creation', 'description': 'Descr.', 'enabled': 'on', 'subscription_right': 'public', 'plugin': self.fake_plugin.id } bundle_params = dict(**channel_params) bundle_params.update({ 'action': 'create-bundle', 'name': 'Channel Bundle test creation' }) def assert_creation(status=200): assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=channel_params, status=status).body is not None chan = PluginChannel.selectBy( name=channel_params['name']).getOne(None) assert chan is not None chan.destroySelf() assert ChannelBundle.selectBy( name=bundle_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None chan = ChannelBundle.selectBy( name=bundle_params['name']).getOne(None) assert chan is not None chan.destroySelf() def assert_no_creation(status=200): assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert ChannelBundle.selectBy( name=bundle_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy( name=bundle_params['name']).getOne(None) is None # Test basic creation assert_creation() # Test name less than 3 chars channel_params['name'] = bundle_params['name'] = 'aa' assert_no_creation() channel_params['name'] = 'Proper channel name' bundle_params['name'] = 'Proper bundle name' # Test invalid subscription right channel_params['subscription_right'] = bundle_params[ 'subscription_right'] = 'invalid' assert_no_creation() channel_params['subscription_right'] = bundle_params[ 'subscription_right'] = 'public' # Test insufficient permissions for channel creation for u in [ self.user_nothing, self.user_contrib, self.user_chan_admin, self.user_screen_admin ]: self.ictv_app.test_user = {'email': u.email} assert_no_creation(403) # Test sufficient permissions for channel creation for u in [self.user_admin, self.user_super_admin]: self.ictv_app.test_user = {'email': u.email} assert_creation() # Test invalid plugin channel_params['plugin'] = self.fake_plugin.id + 42 assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=channel_params, status=200).body is not None assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None channel_params['plugin'] = 'invalid' assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=channel_params, status=200).body is not None assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None channel_params['plugin'] = self.fake_plugin.id # Test invalid action channel_params['action'] = bundle_params['action'] = 'create-invalid' assert_no_creation(400) channel_params['action'] = 'create-channel' bundle_params['action'] = 'create-bundle' # Test duplicate name Channel(name='already taken', subscription_right='public') channel_params['name'] = bundle_params['name'] = 'already taken' assert_no_creation()
def runTest(self): """ Tests the channels deletion through the Channels page """ pc1_id = self.pc1.id bundle_id = self.bundle.id channel_params = {'action': 'delete-channel', 'id': pc1_id} bundle_params = {'action': 'delete-bundle', 'id': bundle_id} def assert_deletion(channel_params=channel_params, bundle_params=bundle_params, status=200): assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy(id=pc1_id).getOne(None) is None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy(id=bundle_id).getOne(None) is None return (PluginChannel(plugin=self.fake_plugin, name='PC 1', subscription_right='public').id, ChannelBundle(name='Bundle', subscription_right='public').id) def assert_no_deletion(channel_params=channel_params, bundle_params=bundle_params, status=200): assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy(id=pc1_id).getOne(None) is not None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy( id=bundle_id).getOne(None) is not None # Test basic functionality pc1_id, bundle_id = assert_deletion() channel_params['id'] = pc1_id bundle_params['id'] = bundle_id # Test insufficient permissions for channel edition for u in [ self.user_nothing, self.user_contrib, self.user_chan_admin, self.user_screen_admin, self.user_admin ]: self.ictv_app.test_user = {'email': u.email} assert_no_deletion(status=403) # Test sufficient permissions for channel edition for u in [self.user_super_admin]: self.ictv_app.test_user = {'email': u.email} pc1_id, bundle_id = assert_deletion() channel_params['id'] = pc1_id bundle_params['id'] = bundle_id # Test invalid id channel_params['id'] = bundle_params['id'] = -1 assert_no_deletion() channel_params['id'] = bundle_params['id'] = 'invalid' assert_no_deletion() channel_params['id'] = pc1_id bundle_params['id'] = bundle_id # Test subscriptions pc1_id, bundle_id = assert_deletion() channel_params['id'] = pc1_id bundle_params['id'] = bundle_id self.pc1 = PluginChannel.get(pc1_id) self.bundle = ChannelBundle.get(bundle_id) self.screen.subscribe_to(self.user_super_admin, self.pc1) assert self.testApp.post('/channels', params=channel_params, status=200).body is not None assert PluginChannel.selectBy(id=pc1_id).getOne(None) is not None self.screen.subscribe_to(self.user_super_admin, self.bundle) assert self.testApp.post('/channels', params=bundle_params, status=200).body is not None assert ChannelBundle.selectBy(id=bundle_id).getOne(None) is not None self.screen.unsubscribe_from(self.user_super_admin, self.pc1) assert self.testApp.post('/channels', params=channel_params, status=200).body is not None assert PluginChannel.selectBy(id=pc1_id).getOne(None) is None self.screen.unsubscribe_from(self.user_super_admin, self.bundle) assert self.testApp.post('/channels', params=bundle_params, status=200).body is not None assert ChannelBundle.selectBy(id=bundle_id).getOne(None) is None