Example #1
0
def test_public_id_from_uri_path_wrong_input():
    """Test that when a bad formatted path is passed in input of PublicId.from_uri_path
    an exception is raised."""
    with pytest.raises(
            ValueError,
            match="Input 'bad/formatted:input' is not well formatted."):
        PublicId.from_uri_path("bad/formatted:input")
Example #2
0
    def get_active_handlers(
        self, protocol_id: PublicId, envelope_context: Optional[EnvelopeContext]
    ) -> List[Handler]:
        """
        Get active handlers.

        :param protocol_id: the protocol id
        :param envelope context: the envelope context
        :return: the list of handlers currently active
        """
        skill_id = None  # Optional[PublicId]
        if envelope_context is not None and envelope_context.uri is not None:
            uri_path = envelope_context.uri.path
            try:
                skill_id = PublicId.from_uri_path(uri_path)
            except ValueError:
                logger.warning("URI - {} - not a valid skill id.".format(uri_path))

        if skill_id is not None:
            handler = self.resources.get_handler(protocol_id, skill_id)
            active_handlers = (
                [] if handler is None or not handler.context.is_active else [handler]
            )
        else:
            handlers = self.resources.get_handlers(protocol_id)
            active_handlers = list(
                filter(lambda handler: handler.context.is_active, handlers)
            )
        return active_handlers
Example #3
0
    def skill_id(self) -> Optional[SkillId]:
        """
        Get the skill id from an envelope context, if set.

        :return: skill id
        """
        skill_id = None  # Optional[PublicId]
        if self.context is not None and self.context.uri is not None:
            uri_path = self.context.uri.path
            try:
                skill_id = PublicId.from_uri_path(uri_path)
            except ValueError:
                logger.debug(
                    "URI - {} - not a valid skill id.".format(uri_path))
        return skill_id
Example #4
0
def test_public_id_from_uri_path():
    """Test PublicId.from_uri_path"""
    result = PublicId.from_uri_path("author/package_name/0.1.0")
    assert result.name == "package_name"
    assert result.author == "author"
    assert result.version == "0.1.0"