Пример #1
0
    def is_subscribed_to(self, item):
        """ Check if user is subscribed to the following item

        :param item: Item object
        :rtype: bool
        :returns: if user is subscribed to the item
        """
        from MoinMoin.items import NonExistent
        if not self.valid or isinstance(item, (NonExistent, Undefined)):
            return False

        meta = item.meta
        item_namespace = meta[NAMESPACE]
        subscriptions = set()
        itemid = meta.get(ITEMID)
        if itemid is not None:
            subscriptions.update([u"{0}:{1}".format(ITEMID, itemid)])
        subscriptions.update(u"{0}:{1}:{2}".format(NAME, item_namespace, name)
                             for name in meta.get(NAME, []))
        subscriptions.update(u"{0}:{1}:{2}".format(TAGS, item_namespace, tag)
                             for tag in meta.get(TAGS, []))
        if subscriptions & set(self.subscriptions):
            return True

        if get_matched_subscription_patterns(self.subscriptions, **meta):
            return True
        return False
Пример #2
0
    def is_subscribed_to(self, item):
        """ Check if user is subscribed to the following item

        :param item: Item object
        :rtype: bool
        :returns: if user is subscribed to the item
        """
        from MoinMoin.items import NonExistent
        if not self.valid or isinstance(item, (NonExistent, Undefined)):
            return False

        meta = item.meta
        item_namespace = meta[NAMESPACE]
        subscriptions = set()
        itemid = meta.get(ITEMID)
        if itemid is not None:
            subscriptions.update(["{0}:{1}".format(ITEMID, itemid)])
        subscriptions.update("{0}:{1}:{2}".format(NAME, item_namespace, name)
                             for name in meta.get(NAME, []))
        subscriptions.update("{0}:{1}:{2}".format(TAGS, item_namespace, tag)
                             for tag in meta.get(TAGS, []))
        if subscriptions & set(self.subscriptions):
            return True

        if get_matched_subscription_patterns(self.subscriptions, **meta):
            return True
        return False
Пример #3
0
    def test_get_matched_subscription_patterns(self, item, namespace):
        meta = item.meta
        patterns = get_matched_subscription_patterns([], **meta)
        assert patterns == []
        non_matching_patterns = [
            "{0}:{1}:{2}".format(NAMERE, NAMESPACE_USERPROFILES, ".*"),
            "{0}:{1}:{2}".format(NAMERE, namespace, "\d+"),
            "{0}:{1}:{2}".format(NAMEPREFIX, namespace, "bar"),
        ]
        patterns = get_matched_subscription_patterns(non_matching_patterns, **meta)
        assert patterns == []

        matching_patterns = [
            "{0}:{1}:{2}".format(NAMERE, namespace, "fo+"),
            "{0}:{1}:{2}".format(NAMEPREFIX, namespace, "fo"),
        ]
        patterns = get_matched_subscription_patterns(non_matching_patterns + matching_patterns, **meta)
        assert patterns == matching_patterns
Пример #4
0
    def test_get_matched_subscription_patterns(self, item, namespace):
        meta = item.meta
        patterns = get_matched_subscription_patterns([], **meta)
        assert patterns == []
        non_matching_patterns = [
            "{0}:{1}:{2}".format(NAMERE, NAMESPACE_USERPROFILES, ".*"),
            "{0}:{1}:{2}".format(NAMERE, namespace, "\d+"),
            "{0}:{1}:{2}".format(NAMEPREFIX, namespace, "bar"),
        ]
        patterns = get_matched_subscription_patterns(non_matching_patterns,
                                                     **meta)
        assert patterns == []

        matching_patterns = [
            "{0}:{1}:{2}".format(NAMERE, namespace, "fo+"),
            "{0}:{1}:{2}".format(NAMEPREFIX, namespace, "fo"),
        ]
        patterns = get_matched_subscription_patterns(
            non_matching_patterns + matching_patterns, **meta)
        assert patterns == matching_patterns