Пример #1
0
 def setUp(self, annotate=True):
     """
     Setup the tests by creating the ChannelObject instance.
     """
     super(TestChannel, self).setUp(annotate=annotate)
     self.channel_object = ChannelObject(self.fake_session,
                                         self.fake_channel_community)
Пример #2
0
 def setUp(self, annotate=True, autoload_discovery=True):
     """
     Setup the tests by creating the ChannelObject instance.
     """
     yield super(TestChannel,
                 self).setUp(annotate=annotate,
                             autoload_discovery=autoload_discovery)
     self.channel_object = ChannelObject(self.fake_session,
                                         self.fake_channel_community)
Пример #3
0
    def initialize(self):
        self.dispersy = self.session.get_dispersy_instance()

        # get all channels owned by me
        from Tribler.community.channel.community import ChannelCommunity
        for community in self.session.lm.dispersy.get_communities():
            if isinstance(community, ChannelCommunity) and community.master_member and community.master_member.private_key:
                channel_obj = ChannelObject(self.session, community, is_created=True)
                channel_obj.initialize()
                self._channel_list.append(channel_obj)

                self._logger.debug(u"loaded channel '%s', %s", channel_obj.name, hexlify(community.cid))
    def test_create_channel_duplicate_name_error(self):
        config = TriblerConfig()
        config.set_state_dir(self.getStateDir())
        self.session = Session(config)

        class LmMock(object):
            channel_manager = ChannelManager(self.session)

        self.session.lm = LmMock()

        class MockCommunity(object):
            cid = ""

            def get_channel_name(self):
                return "Channel name"

        channel_obj = ChannelObject(self.session,
                                    MockCommunity(),
                                    is_created=True)
        self.session.lm.channel_manager._channel_list = [channel_obj]

        with self.assertRaises(DuplicateChannelNameError) as cm:
            self.session.lm.channel_manager.create_channel(
                "Channel name", "description", "open")
        self.assertEqual(cm.exception.message,
                         u"Channel name already exists: Channel name")
Пример #5
0
class TestChannel(BaseTestChannel):
    """
    This class contains some tests for the ChannelObject class.
    """
    @blocking_call_on_reactor_thread
    @inlineCallbacks
    def setUp(self, annotate=True, autoload_discovery=True):
        """
        Setup the tests by creating the ChannelObject instance.
        """
        yield super(TestChannel,
                    self).setUp(annotate=annotate,
                                autoload_discovery=autoload_discovery)
        self.channel_object = ChannelObject(self.fake_session,
                                            self.fake_channel_community)

    def test_get_channel_id(self):
        self.assertEqual(self.channel_object.channel_id, 42)

    def test_get_channel_name(self):
        self.assertEqual(self.channel_object.name, "my fancy channel")

    def test_get_rss_feed_url_list(self):
        rss_parser = ChannelRssParser(self.fake_session,
                                      self.fake_channel_community, 'a')
        self.channel_object._rss_feed_dict['a'] = rss_parser
        self.assertEqual(self.channel_object.get_rss_feed_url_list(), ['a'])
Пример #6
0
    def initialize(self):
        self.dispersy = self.session.get_dispersy_instance()

        # get all channels owned by me
        from Tribler.community.channel.community import ChannelCommunity
        for community in self.session.lm.dispersy.get_communities():
            if isinstance(
                    community, ChannelCommunity
            ) and community.master_member and community.master_member.private_key:
                channel_obj = ChannelObject(self.session,
                                            community,
                                            is_created=True)
                channel_obj.initialize()
                self._channel_list.append(channel_obj)

                self._logger.debug(u"loaded channel '%s', %s",
                                   channel_obj.name, hexlify(community.cid))
Пример #7
0
    def create_fake_channel(self, name, description, mode=u'closed'):
        # Use a fake ChannelCommunity object (we don't actually want to create a Dispersy community)
        my_channel_id = self.create_my_channel(name, description)
        self.session.lm.channel_manager = ChannelManager(self.session)

        channel_obj = ChannelObject(
            self.session,
            ChannelCommunityMock(my_channel_id, name, description, mode))
        self.session.lm.channel_manager._channel_list.append(channel_obj)
        return my_channel_id
Пример #8
0
    def create_channel(self, name, description, mode, rss_url=None):
        """
        Creates a new Channel.
        :param name: Name of the Channel.
        :param description: Description of the Channel.
        :param mode: Mode of the Channel ('open', 'semi-open', or 'closed').
        :param rss_url: RSS URL for the Channel.
        :return: Channel ID
        :raises DuplicateChannelNameError if name already exists
        """
        assert isinstance(name, basestring), u"name is not a basestring: %s" % type(name)
        assert isinstance(description, basestring), u"description is not a basestring: %s" % type(description)
        assert mode in self._channel_mode_map, u"invalid mode: %s" % mode
        assert isinstance(rss_url, basestring) or rss_url is None, u"rss_url is not a basestring or None: %s" % type(rss_url)

        # if two channels have the same name, this will not work
        for channel_object in self._channel_list:
            if name == channel_object.name:
                raise DuplicateChannelNameError(u"Channel name already exists: %s" % name)

        channel_mode = self._channel_mode_map[mode]
        community = ChannelCommunity.create_community(self.dispersy, self.session.dispersy_member,
                                                      tribler_session=self.session)

        channel_obj = ChannelObject(self.session, community)
        channel_obj.initialize()

        community.set_channel_mode(channel_mode)
        community.create_channel(name, description)

        # create channel object
        self._channel_list.append(channel_obj)

        if rss_url is not None:
            channel_obj.create_rss_feed(rss_url)

        self._logger.debug(u"creating channel '%s', %s", channel_obj.name, hexlify(community.cid))
        return channel_obj.channel_id
Пример #9
0
    def create_channel(self, name, description, mode, rss_url=None):
        """
        Creates a new Channel.
        :param name: Name of the Channel.
        :param description: Description of the Channel.
        :param mode: Mode of the Channel ('open', 'semi-open', or 'closed').
        :param rss_url: RSS URL for the Channel.
        :return: Channel ID
        :raises DuplicateChannelNameError if name already exists
        """
        assert isinstance(
            name, basestring), u"name is not a basestring: %s" % type(name)
        assert isinstance(
            description, basestring
        ), u"description is not a basestring: %s" % type(description)
        assert mode in self._channel_mode_map, u"invalid mode: %s" % mode
        assert isinstance(
            rss_url, basestring
        ) or rss_url is None, u"rss_url is not a basestring or None: %s" % type(
            rss_url)

        # if two channels have the same name, this will not work
        for channel_object in self._channel_list:
            if name == channel_object.name:
                raise DuplicateChannelNameError(
                    u"Channel name already exists: %s" % name)

        channel_mode = self._channel_mode_map[mode]
        community = ChannelCommunity.create_community(
            self.dispersy,
            self.session.dispersy_member,
            tribler_session=self.session)

        channel_obj = ChannelObject(self.session, community)
        channel_obj.initialize()

        community.set_channel_mode(channel_mode)
        community.create_channel(name, description)

        # create channel object
        self._channel_list.append(channel_obj)

        if rss_url is not None:
            channel_obj.create_rss_feed(rss_url)

        self._logger.debug(u"creating channel '%s', %s", channel_obj.name,
                           hexlify(community.cid))
        return channel_obj.channel_id
Пример #10
0
class TestChannel(BaseTestChannel):
    """
    This class contains some tests for the ChannelObject class.
    """
    def setUp(self, annotate=True):
        """
        Setup the tests by creating the ChannelObject instance.
        """
        super(TestChannel, self).setUp(annotate=annotate)
        self.channel_object = ChannelObject(self.fake_session,
                                            self.fake_channel_community)

    def test_get_channel_id(self):
        self.assertEqual(self.channel_object.channel_id, 42)

    def test_get_channel_name(self):
        self.assertEqual(self.channel_object.name, "my fancy channel")

    def test_get_rss_feed_url_list(self):
        rss_parser = ChannelRssParser(self.fake_session,
                                      self.fake_channel_community, 'a')
        self.channel_object._rss_feed_dict['a'] = rss_parser
        self.assertEqual(self.channel_object.get_rss_feed_url_list(), ['a'])
Пример #11
0
class TestChannel(BaseTestChannel):
    """
    This class contains some tests for the ChannelObject class.
    """

    @inlineCallbacks
    def setUp(self):
        """
        Setup the tests by creating the ChannelObject instance.
        """
        yield super(TestChannel, self).setUp()
        self.channel_object = ChannelObject(self.fake_session, self.fake_channel_community)

    def test_get_channel_id(self):
        self.assertEqual(self.channel_object.channel_id, 42)

    def test_get_channel_name(self):
        self.assertEqual(self.channel_object.name, "my fancy channel")

    def test_get_rss_feed_url_list(self):
        rss_parser = ChannelRssParser(self.fake_session, self.fake_channel_community, 'a')
        self.channel_object._rss_feed_dict['a'] = rss_parser
        self.assertEqual(self.channel_object.get_rss_feed_url_list(), ['a'])
Пример #12
0
 def setUp(self):
     """
     Setup the tests by creating the ChannelObject instance.
     """
     yield super(TestChannel, self).setUp()
     self.channel_object = ChannelObject(self.fake_session, self.fake_channel_community)