コード例 #1
0
    def setup_class(cls):
        """Initialise the class."""

        cls.address = "my_key"
        cls.host = get_host()
        cls.port = get_unused_tcp_port()
        cls.api_spec_path = os.path.join(ROOT_DIR, "tests", "data",
                                         "petstore_sim.yaml")
        cls.connection_id = PublicId("fetchai", "http", "0.1.0")
        cls.protocol_id = PublicId("fetchai", "http", "0.1.0")

        cls.http_connection = HTTPConnection(
            address=cls.address,
            host=cls.host,
            port=cls.port,
            api_spec_path=cls.api_spec_path,
            connection_id=cls.connection_id,
            restricted_to_protocols=set([cls.protocol_id]),
        )
        cls.loop = asyncio.new_event_loop()
        cls.http_connection.loop = cls.loop
        value = cls.loop.run_until_complete(cls.http_connection.connect())
        assert value is None
        assert cls.http_connection.connection_status.is_connected
        assert not cls.http_connection.channel.is_stopped

        cls.t = Thread(target=cls.loop.run_forever)
        cls.t.start()
コード例 #2
0
def test_conn_from_config():
    """Test the Connection from config File."""
    conf = ConnectionConfig()
    conf.config["api_spec_path"] = os.path.join(ROOT_DIR, "tests", "data",
                                                "petstore_sim.yaml")
    conf.config["host"] = get_host()
    conf.config["port"] = get_unused_tcp_port()
    conf.config["restricted_to_protocols"] = set(["fetchai/http:0.1.0"])
    con = HTTPConnection.from_config(address="my_key",
                                     connection_configuration=conf)
    assert con is not None
    assert not con.connection_status.is_connected
コード例 #3
0
    def setup_class(cls):
        """Initialise the class and test connect."""

        cls.address = "my_key"
        cls.host = get_host()
        cls.port = get_unused_tcp_port()
        cls.api_spec_path = os.path.join(ROOT_DIR, "tests", "data",
                                         "petstore_sim.yaml")
        cls.connection_id = PublicId("fetchai", "http", "0.1.0")
        cls.protocol_id = PublicId("fetchai", "http", "0.1.0")

        cls.http_connection = HTTPConnection(
            address=cls.address,
            host=cls.host,
            port=cls.port,
            api_spec_path=cls.api_spec_path,
            connection_id=cls.connection_id,
            restricted_to_protocols=set([cls.protocol_id]),
        )
        assert cls.http_connection.channel.is_stopped

        cls.http_connection.channel.connect()
        assert not cls.http_connection.channel.is_stopped