Ejemplo n.º 1
0
 def runTest(self):
     """ Submits an empty diff to the page and ensures that nothing has changed """
     bundle = self.bundle_channels[0]
     before = {repr(b) for b in ChannelBundle.select()}
     post_params = {"diff": json.dumps({})}
     assert self.testApp.post("/channels/%d/manage_bundle" % bundle.id,
                              post_params,
                              status=303).body is not None
     after = {repr(b) for b in ChannelBundle.select()}
     assert after == before
Ejemplo n.º 2
0
 def runTest(self):
     """ Tries to add to the bundle a channel that does not exist and
         verifies that it is handled correctly for the user """
     bundle = self.bundle_channels[0]
     before = {dump_bundle(b) for b in ChannelBundle.select()}
     diff = {-1: True}
     post_params = {"diff": json.dumps(diff)}
     assert self.testApp.post("/channels/%d/manage_bundle" % bundle.id,
                              post_params,
                              status=403).body is not None
     after = {dump_bundle(b) for b in ChannelBundle.select()}
     assert after == before
Ejemplo n.º 3
0
    def render_page(self, channel):
        current_user = User.get(self.session['user']['id'])

        now = datetime.now()
        last_update = self.plugin_manager.get_last_update(channel.id) or now
        if type(channel) is PluginChannel and last_update + timedelta(
                minutes=channel.cache_validity) < now:
            last_update = now
        try:
            vertical = channel.get_config_param(
                'vertical') if type(channel) is PluginChannel else False
        except KeyError:
            vertical = False
        return self.renderer.channeld(
            channel=channel,
            channel_type=type(channel).__name__,
            current_user=current_user,
            bundles=ChannelBundle.select().filter(
                ChannelBundle.q.id != channel.id),
            can_force_update=UserPermissions.administrator
            in current_user.highest_permission_level
            or (type(channel) is PluginChannel
                and channel.has_contrib(current_user)),
            last_update=last_update,
            vertical=vertical)
Ejemplo n.º 4
0
 def runTest(self):
     """ Tries to add a bundle to itself and plugin_channels with disabled plugins to the bundle and checks that
         nothing has been added """
     bundle = self.bundle_channels[0]
     before = {dump_bundle(b) for b in ChannelBundle.select()}
     diff = {bundle.id: True}
     post_params = {"diff": json.dumps(diff)}
     assert self.testApp.post("/channels/%d/manage_bundle" % bundle.id,
                              post_params,
                              status=303).body is not None
     after = {dump_bundle(b) for b in ChannelBundle.select()}
     assert after == before
     channel = self.plugin_channels[0]
     channel.plugin.activated = "no"
     diff = {channel.id: True}
     post_params = {"diff": json.dumps(diff)}
     assert self.testApp.post("/channels/%d/manage_bundle" % bundle.id,
                              post_params,
                              status=303).body is not None
     assert after == before
Ejemplo n.º 5
0
 def _get_screens_number(self):
     """ Return the number of screens that are subscribed to channels of this plugin. """
     plugin_channels = PluginChannel.select().filter(
         PluginChannel.q.plugin == self)
     screens = set(plugin_channels.throughTo.subscriptions.throughTo.screen.
                   distinct())
     bundles = set(c for c in ChannelBundle.select()
                   if any(bc.plugin == self for bc in c.flatten()))
     for b in bundles:
         screens |= set(Subscription.select().filter(
             Subscription.q.channel == b).throughTo.screen.distinct())
     return len(screens)