Beispiel #1
0
class CheckFileNotExistsTestCase(TestCase):
    """Test case for CLI add_key command."""
    def setUp(self):
        """Set it up."""
        self.runner = CliRunner()

    def test_file_specified_does_not_exist(self, *mocks):
        """Test for CLI add_key fails on file not exists."""
        with pytest.raises(BadParameter, match=r"File '.*' does not exist."):
            self.runner.invoke(
                cli,
                [
                    *CLI_LOG_OPTION,
                    "--skip-consistency-check",
                    "add-key",
                    FETCHAI,
                    "somefile",
                ],
                standalone_mode=False,
                catch_exceptions=False,
            )

    def test_file_not_specified_does_not_exist(self, *mocks):
        """Test for CLI add_key fails on file not exists."""
        with pytest.raises(BadParameter, match=r"File '.*' does not exist."):
            self.runner.invoke(
                cli,
                [
                    *CLI_LOG_OPTION, "--skip-consistency-check", "add-key",
                    FETCHAI
                ],
                standalone_mode=False,
                catch_exceptions=False,
            )
Beispiel #2
0
class TestSearchContractsLocal(TestCase):
    """Test that the command 'aea search contracts' works as expected."""
    def setUp(self):
        """Set the test up."""
        self.runner = CliRunner()

    @mock.patch("aea.cli.search.format_items",
                return_value=FORMAT_ITEMS_SAMPLE_OUTPUT)
    @mock.patch("aea.cli.search._search_items_locally", return_value=["item1"])
    def test_search_contracts_positive(self, *mocks):
        """Test search contracts command positive result."""
        result = self.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "search", "--local", "contracts"],
            standalone_mode=False,
        )
        assert result.output == ('Searching for ""...\n'
                                 "Contracts found:\n\n"
                                 "{}\n".format(FORMAT_ITEMS_SAMPLE_OUTPUT))

    @mock.patch("aea.cli.search.format_items",
                return_value=FORMAT_ITEMS_SAMPLE_OUTPUT)
    @mock.patch("aea.cli.search.request_api", return_value=["item1"])
    def test_search_contracts_registry_positive(self, *mocks):
        """Test search contracts in registry command positive result."""
        result = self.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "search", "contracts"],
            standalone_mode=False,
        )
        assert result.output == ('Searching for ""...\n'
                                 "Contracts found:\n\n"
                                 "{}\n".format(FORMAT_ITEMS_SAMPLE_OUTPUT))
Beispiel #3
0
class ListAllCommandTestCase(TestCase):
    """Test case for aea list all command."""

    def setUp(self):
        """Set the test up."""
        self.runner = CliRunner()

    @mock.patch("aea.cli.list.list_agent_items", return_value=[])
    @mock.patch("aea.cli.list.format_items")
    @mock.patch("aea.cli.utils.decorators._check_aea_project")
    def test_list_all_no_details_positive(self, *mocks):
        """Test list all command no details positive result."""
        result = self.runner.invoke(
            cli, [*CLI_LOG_OPTION, "list", "all"], standalone_mode=False
        )
        self.assertEqual(result.exit_code, 0)
        self.assertEqual(result.output, "")

    @mock.patch("aea.cli.list.list_agent_items", return_value=[{"name": "some"}])
    @mock.patch("aea.cli.list.format_items", return_value="correct")
    @mock.patch("aea.cli.utils.decorators._check_aea_project")
    def test_list_all_positive(self, *mocks):
        """Test list all command positive result."""
        result = self.runner.invoke(
            cli, [*CLI_LOG_OPTION, "list", "all"], standalone_mode=False
        )
        self.assertEqual(result.exit_code, 0)
        self.assertEqual(
            result.output,
            "Connections:\ncorrect\nContracts:\ncorrect\n"
            "Protocols:\ncorrect\nSkills:\ncorrect\n",
        )
Beispiel #4
0
class CreateCommandTestCase(TestCase):
    """Test case for CLI create command."""
    def setUp(self):
        """Set it up."""
        self.runner = CliRunner()

    def test_create_no_init(self):
        """Test for CLI create no init result."""
        result = self.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "agent_name", "--author=some"],
            standalone_mode=False,
        )
        self.assertEqual(
            result.exception.message,
            "Author is not set up. Please use 'aea init' to initialize.",
        )

    @patch("aea.cli.create.get_or_create_cli_config", return_value={})
    def test_create_no_author_local(self, *mocks):
        """Test for CLI create no author local result."""
        result = self.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", "agent_name"],
            standalone_mode=False,
        )
        expected_message = (
            "The AEA configurations are not initialized. "
            "Uses `aea init` before continuing or provide optional argument `--author`."
        )
        self.assertEqual(result.exception.message, expected_message)
Beispiel #5
0
def test_fetch_twice_remote():
    """Test fails on fetch if dir exists."""
    with TemporaryDirectory() as tmp_dir:
        with cd(tmp_dir):
            name = "my_first_aea"
            runner = CliRunner()
            result = runner.invoke(
                cli,
                [
                    "--registry-path",
                    PACKAGES_DIR,
                    "fetch",
                    "--local",
                    "fetchai/my_first_aea",
                ],
                catch_exceptions=False,
            )
            assert result.exit_code == 0, result.stdout
            assert os.path.exists(name)

            with pytest.raises(
                ClickException,
                match='Item "my_first_aea" already exists in target folder.',
            ):
                result = runner.invoke(
                    cli,
                    ["fetch", "--remote", "fetchai/my_first_aea"],
                    standalone_mode=False,
                    catch_exceptions=False,
                )
Beispiel #6
0
def test_flag_help():
    """Test that the flag '--help' works correctly."""
    runner = CliRunner()
    result = runner.invoke(cli, ["--help"])
    assert (result.stdout == """Usage: aea [OPTIONS] COMMAND [ARGS]...

  Command-line tool for setting up an Autonomous Economic Agent (AEA).

Options:
  --version                     Show the version and exit.
  -v, --verbosity LVL           One of NOTSET, DEBUG, INFO, WARNING, ERROR,
                                CRITICAL, OFF

  -s, --skip-consistency-check  Skip consistency checks of agent during command
                                execution.

  --registry-path DIRECTORY     Provide a local registry directory full path.
  --help                        Show this message and exit.

Commands:
  add                  Add a package to the agent.
  add-key              Add a private key to the wallet of the agent.
  build                Build the agent and its components.
  config               Read or modify a configuration of the agent.
  create               Create a new agent.
  delete               Delete an agent.
  eject                Eject a vendor package of the agent.
  fetch                Fetch an agent from the registry.
  fingerprint          Fingerprint a non-vendor package of the agent.
  freeze               Get the dependencies of the agent.
  generate             Generate a package for the agent.
  generate-key         Generate a private key and place it in a file.
  generate-wealth      Generate wealth for the agent on a test network.
  get-address          Get the address associated with a private key of the...
  get-multiaddress     Get the multiaddress associated with a private key or...
  get-wealth           Get the wealth associated with the private key of the...
  gui                  Run the CLI GUI.
  init                 Initialize your AEA configurations.
  install              Install the dependencies of the agent.
  interact             Interact with the running agent via the stub...
  issue-certificates   Issue certificates for connections that require them.
  launch               Launch many agents at the same time.
  list                 List the installed packages of the agent.
  local-registry-sync  Upgrade the local package registry.
  login                Login to the registry account.
  logout               Logout from the registry account.
  publish              Publish the agent to the registry.
  push                 Push a non-vendor package of the agent to the registry.
  register             Create a new registry account.
  remove               Remove a package from the agent.
  remove-key           Remove a private key from the wallet of the agent.
  reset_password       Reset the password of the registry account.
  run                  Run the agent.
  scaffold             Scaffold a package for the agent.
  search               Search for packages in the registry.
  transfer             Transfer wealth associated with a private key of the...
  upgrade              Upgrade the packages of the agent.
""")
Beispiel #7
0
 def setup(self):
     """Set the test up."""
     self.cwd = os.getcwd()
     self.t = tempfile.mkdtemp()
     dir_path = Path("packages")
     tmp_dir = self.t / dir_path
     src_dir = self.cwd / Path(ROOT_DIR, dir_path)
     shutil.copytree(str(src_dir), str(tmp_dir))
     shutil.copytree(Path(CUR_PATH, "data", "dummy_aea"),
                     Path(self.t, "dummy_aea"))
     os.chdir(Path(self.t, "dummy_aea"))
     self.runner = CliRunner()
Beispiel #8
0
 def setup(self):
     """Set the test up."""
     self.runner = CliRunner()
     self.agent_name = "myagent"
     self.cwd = os.getcwd()
     self.t = tempfile.mkdtemp()
     self.agent_folder = Path(self.t, self.agent_name)
     os.chdir(self.t)
     self.cli_config_file = f"{self.t}/cli_config.yaml"
     self.cli_config_patch = patch("aea.cli.utils.config.CLI_CONFIG_PATH",
                                   self.cli_config_file)
     self.cli_config_patch.start()
Beispiel #9
0
 def setUp(self):
     """Set the test up."""
     self.runner = CliRunner()
     self.schema = json.load(open(AGENT_CONFIGURATION_SCHEMA))
     self.resolver = jsonschema.RefResolver(
         "file://{}/".format(Path(CONFIGURATION_SCHEMA_DIR).absolute()), self.schema
     )
     self.validator = Draft4Validator(self.schema, resolver=self.resolver)
     self.cwd = os.getcwd()
     self.t = tempfile.mkdtemp()
     # copy the 'dummy_aea' directory in the parent of the agent folder.
     shutil.copytree(Path(CUR_PATH, "data", "dummy_aea"), Path(self.t, "dummy_aea"))
     os.chdir(Path(self.t, "dummy_aea"))
Beispiel #10
0
def test_flag_help():
    """Test that the flag '--help' works correctly."""
    runner = CliRunner()
    result = runner.invoke(cli, ["--help"])
    assert (result.stdout == """Usage: aea [OPTIONS] COMMAND [ARGS]...

  Command-line tool for setting up an Autonomous Economic Agent.

Options:
  --version                     Show the version and exit.
  -v, --verbosity LVL           One of NOTSET, DEBUG, INFO, WARNING, ERROR,
                                CRITICAL, OFF

  -s, --skip-consistency-check  Skip consistency check.
  --help                        Show this message and exit.

Commands:
  add               Add a resource to the agent.
  add-key           Add a private key to the wallet.
  config            Read or modify a configuration.
  create            Create an agent.
  delete            Delete an agent.
  eject             Eject an installed item.
  fetch             Fetch Agent from Registry.
  fingerprint       Fingerprint a resource.
  freeze            Get the dependencies.
  generate          Generate a resource for the agent.
  generate-key      Generate private keys.
  generate-wealth   Generate wealth for address on test network.
  get-address       Get the address associated with the private key.
  get-multiaddress  Get the multiaddress associated with a private key or...
  get-wealth        Get the wealth associated with the private key.
  gui               Run the CLI GUI.
  init              Initialize your AEA configurations.
  install           Install the dependencies.
  interact          Interact with a running AEA via the stub connection.
  launch            Launch many agents at the same time.
  list              List the installed resources.
  login             Login to Registry account.
  logout            Logout from Registry account.
  publish           Publish Agent to Registry.
  push              Push item to Registry or save it in local packages.
  register          Register a new Registry account.
  remove            Remove a resource from the agent.
  reset_password    Reset password of Registry account.
  run               Run the agent.
  scaffold          Scaffold a resource for the agent.
  search            Search for components in the registry.
  transfer          Get the wealth associated with the private key.
  upgrade           Upgrade agent's component.
""")
Beispiel #11
0
class ListContractsCommandTestCase(TestCase):
    """Test that the command 'aea list contracts' works as expected."""

    def setUp(self):
        """Set the test up."""
        self.runner = CliRunner()
        self.schema = json.load(open(AGENT_CONFIGURATION_SCHEMA))
        self.resolver = jsonschema.RefResolver(
            "file://{}/".format(Path(CONFIGURATION_SCHEMA_DIR).absolute()), self.schema
        )
        self.validator = Draft4Validator(self.schema, resolver=self.resolver)
        self.cwd = os.getcwd()
        self.t = tempfile.mkdtemp()
        # copy the 'dummy_aea' directory in the parent of the agent folder.
        shutil.copytree(Path(CUR_PATH, "data", "dummy_aea"), Path(self.t, "dummy_aea"))
        os.chdir(Path(self.t, "dummy_aea"))

    @mock.patch("aea.cli.list.list_agent_items")
    @mock.patch("aea.cli.utils.formatting.format_items")
    def test_list_contracts_positive(self, *mocks):
        """Test list contracts command positive result."""
        result = self.runner.invoke(
            cli, [*CLI_LOG_OPTION, "list", "contracts"], standalone_mode=False
        )
        self.assertEqual(result.exit_code, 0)

    def tearDown(self):
        """Tear the test down."""
        os.chdir(self.cwd)
        try:
            shutil.rmtree(self.t)
        except (OSError, IOError):
            pass
Beispiel #12
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        dir_path = Path("packages")
        tmp_dir = cls.t / dir_path
        src_dir = cls.cwd / Path(ROOT_DIR, dir_path)
        shutil.copytree(str(src_dir), str(tmp_dir))
        cls.skill_id = str(GYM_SKILL_PUBLIC_ID)

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]
        )
        assert result.exit_code == 0

        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0
        os.chdir(cls.agent_name)

        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "remove", "skill", cls.skill_id],
            standalone_mode=False,
        )
Beispiel #13
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        shutil.copytree(Path(CUR_PATH, "..", "packages"),
                        Path(cls.t, "packages"))
        cls.connection_id = str(LOCAL_CONNECTION_PUBLIC_ID)

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0
        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0
        os.chdir(cls.agent_name)

        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "remove", "connection", cls.connection_id],
            standalone_mode=False,
        )
Beispiel #14
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.connection_id = "author/unknown_connection:0.1.0"
        cls.connection_name = "unknown_connection"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        # copy the 'packages' directory in the parent of the agent folder.
        shutil.copytree(Path(ROOT_DIR, "packages"), Path(cls.t, "packages"))

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0

        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0

        os.chdir(Path(cls.t, cls.agent_name))

        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "run", "--connections", cls.connection_id],
            standalone_mode=False,
        )
Beispiel #15
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        cls.protocol_id = str(GymMessage.protocol_id)
        cls.protocol_name = "gym"

        # copy the 'packages' directory in the parent of the agent folder.
        shutil.copytree(Path(CUR_PATH, "..", "packages"),
                        Path(cls.t, "packages"))

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0

        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0

        os.chdir(cls.agent_name)
        Path(cls.t, cls.agent_name, "vendor", "fetchai", "protocols",
             cls.protocol_name).mkdir(parents=True, exist_ok=True)
        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "add", "--local", "protocol", cls.protocol_id],
            standalone_mode=False,
        )
Beispiel #16
0
    def setup_class(cls):
        """Set the test up."""
        if cls is BaseLaunchTestCase:
            raise unittest.SkipTest("Skip BaseTest tests, it's a base class")

        cls.runner = CliRunner()
        cls.agent_name_1 = "myagent_1"
        cls.agent_name_2 = "myagent_2"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        dir_path = Path("packages")
        tmp_dir = cls.t / dir_path
        src_dir = cls.cwd / Path(ROOT_DIR, dir_path)
        shutil.copytree(str(src_dir), str(tmp_dir))
        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]
        )
        assert result.exit_code == 0
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "create", "--local", cls.agent_name_1]
        )
        assert result.exit_code == 0
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "create", "--local", cls.agent_name_2]
        )
        assert result.exit_code == 0
Beispiel #17
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        # copy the 'packages' directory in the parent of the agent folder.
        shutil.copytree(Path(ROOT_DIR, "packages"), Path(cls.t, "packages"))

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0

        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0

        Path(cls.t, cls.agent_name, DEFAULT_AEA_CONFIG_FILE).write_text("")

        os.chdir(Path(cls.t, cls.agent_name))

        cls.result = cls.runner.invoke(cli, [*CLI_LOG_OPTION, "run"],
                                       standalone_mode=False)
Beispiel #18
0
    def setup_class(cls):
        """Set the test up."""
        cls.cwd = os.getcwd()
        cls.runner = CliRunner()
        cls.t = tempfile.mkdtemp()
        os.chdir(cls.t)

        # copy the packages directory in the temporary test directory.
        shutil.copytree(Path(ROOT_DIR, "packages"), Path(cls.t, "packages"))

        # remove all the skills except the echo and error skill (to make testing easier).
        for p in Path(cls.t, "packages", "fetchai", "skills").iterdir():
            if p.name not in ["echo", "error"] and p.is_dir():
                shutil.rmtree(p)

        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]
        )
        assert result.exit_code == 0

        # create an AEA proejct and enter into it.
        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", "myagent"],
            standalone_mode=False,
        )
        assert result.exit_code == 0
        os.chdir(Path(cls.t, "myagent"))

        cls.result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "search", "--local", "skills"], standalone_mode=False
        )
Beispiel #19
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.resource_name = "myresource"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        dir_path = Path("packages")
        tmp_dir = cls.t / dir_path
        src_dir = cls.cwd / Path(ROOT_DIR, dir_path)
        shutil.copytree(str(src_dir), str(tmp_dir))

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0
        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0

        cls.patch = unittest.mock.patch(
            "shutil.copytree", side_effect=Exception("unknwon exception"))
        cls.patch.start()

        os.chdir(cls.agent_name)
        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "scaffold", "skill", cls.resource_name],
            standalone_mode=False,
        )
Beispiel #20
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        dir_path = Path("packages")
        tmp_dir = cls.t / dir_path
        src_dir = cls.cwd / Path(ROOT_DIR, dir_path)
        shutil.copytree(str(src_dir), str(tmp_dir))
        os.chdir(cls.t)

        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]
        )
        assert result.exit_code == 0

        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0

        # agent's directory does not exist -> command will fail.
        with unittest.mock.patch.object(shutil, "rmtree", side_effect=OSError):
            cls.result = cls.runner.invoke(
                cli, [*CLI_LOG_OPTION, "delete", cls.agent_name], standalone_mode=False
            )
Beispiel #21
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        cls.agent_folder = Path(cls.t, cls.agent_name)
        os.chdir(cls.t)

        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]
        )

        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "create", "--local", cls.agent_name]
        )
        assert result.exit_code == 0
        os.chdir(Path(cls.t, cls.agent_name))

        shutil.copy(
            Path(CUR_PATH, "data", FETCHAI_PRIVATE_KEY_FILE),
            cls.agent_folder / FETCHAI_PRIVATE_KEY_FILE,
        )

        cls.result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "add-key", FETCHAI, FETCHAI_PRIVATE_KEY_FILE],
        )
Beispiel #22
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        cls.skill_id = "different_author/error:0.1.0"
        cls.skill_name = "unknown_skill"

        # copy the 'packages' directory in the parent of the agent folder.
        shutil.copytree(Path(CUR_PATH, "..", "packages"), Path(cls.t, "packages"))

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]
        )
        assert result.exit_code == 0

        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0
        os.chdir(cls.agent_name)
        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "add", "--local", "skill", cls.skill_id],
            standalone_mode=False,
        )
class RegisterTestCase(TestCase):
    """Test case for CLI register command."""

    def setUp(self):
        """Set it up."""
        self.runner = CliRunner()

    def test_register_positive(self, do_register_mock):
        """Test for CLI register positive result."""
        username = "******"
        email = "*****@*****.**"
        fake_pwd = "fake_pwd"  # nosec

        result = self.runner.invoke(
            cli,
            [
                *CLI_LOG_OPTION,
                "register",
                "--username={}".format(username),
                "--email={}".format(email),
                "--password={}".format(fake_pwd),
                "--confirm_password={}".format(fake_pwd),
            ],
            standalone_mode=False,
        )
        self.assertEqual(result.exit_code, 0)
        do_register_mock.assert_called_once_with(username, email, fake_pwd, fake_pwd)
Beispiel #24
0
    def setup_class(cls):
        """Set the test up."""
        cls.schema = json.load(open(AGENT_CONFIGURATION_SCHEMA))
        cls.resolver = jsonschema.RefResolver(
            make_jsonschema_base_uri(
                Path(CONFIGURATION_SCHEMA_DIR).absolute()),
            cls.schema,
        )
        cls.validator = Draft4Validator(cls.schema, resolver=cls.resolver)

        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        os.chdir(cls.t)
        cls.cli_config_file = f"{cls.t}/cli_config.yaml"
        cls.cli_config_patch = patch("aea.cli.utils.config.CLI_CONFIG_PATH",
                                     cls.cli_config_file)
        cls.cli_config_patch.start()
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0

        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        cls.agent_config = cls._load_config_file(cls.agent_name)
Beispiel #25
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.resource_name = "myresource"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        dir_path = Path("packages")
        tmp_dir = cls.t / dir_path
        src_dir = cls.cwd / Path(ROOT_DIR, dir_path)
        shutil.copytree(str(src_dir), str(tmp_dir))

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0
        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0
        os.chdir(cls.agent_name)
        # create a dummy 'myresource' folder
        Path(cls.t, cls.agent_name, "skills",
             cls.resource_name).mkdir(exist_ok=False, parents=True)
        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "scaffold", "skill", cls.resource_name],
            standalone_mode=False,
        )
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        cls.connection_id = "fetchai/local:0.6.0"

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0
        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert result.exit_code == 0
        os.chdir(cls.agent_name)

        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "remove", "connection", cls.connection_id],
            standalone_mode=False,
        )
Beispiel #27
0
class TestFreeze:
    """Test that the command 'aea freeze' works as expected."""
    def setup(self):
        """Set the test up."""
        self.schema = json.load(open(AGENT_CONFIGURATION_SCHEMA))
        self.resolver = jsonschema.RefResolver(
            make_jsonschema_base_uri(Path(CONFIGURATION_SCHEMA_DIR)),
            self.schema)
        self.validator = Draft4Validator(self.schema, resolver=self.resolver)

        self.cwd = os.getcwd()
        self.t = tempfile.mkdtemp()
        # copy the 'dummy_aea' directory in the parent of the agent folder.
        shutil.copytree(Path(CUR_PATH, "data", "dummy_aea"),
                        Path(self.t, "dummy_aea"))
        self.runner = CliRunner()
        os.chdir(Path(self.t, "dummy_aea"))
        self.result = self.runner.invoke(cli, [*CLI_LOG_OPTION, "freeze"],
                                         standalone_mode=False)

    @pytest.mark.flaky(reruns=MAX_FLAKY_RERUNS)
    def test_exit_code_equal_to_zero_and_correct_output(self):
        """Assert that the exit code is equal to zero (i.e. success)."""
        assert self.result.exit_code == 0
        """Test that the command has printed the correct output."""
        assert self.result.output == """protobuf\nvyper==0.1.0b12\n"""

    def teardown(self):
        """Tear the test down."""
        os.chdir(self.cwd)
        try:
            shutil.rmtree(self.t)
        except (OSError, IOError):
            pass
Beispiel #28
0
    def setup_class(cls):
        """Set the test up."""
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        os.chdir(cls.t)

        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR])
        assert result.exit_code == 0

        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        assert cls.result.exit_code == 0

        # calling 'aea create myagent' again within an AEA project - recursively.
        os.chdir(cls.agent_name)
        os.mkdir("another_subdir")
        os.chdir("another_subdir")
        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
Beispiel #29
0
    def setup_class(cls):
        """Set the test up."""
        cls.runner = CliRunner()
        cls.agent_name = "myagent"
        cls.cwd = os.getcwd()
        cls.t = tempfile.mkdtemp()
        cls.skill_id = ERROR_PUBLIC_ID
        cls.skill_name = cls.skill_id.name
        cls.skill_author = cls.skill_id.author
        cls.skill_version = cls.skill_id.version

        # copy the 'packages' directory in the parent of the agent folder.
        shutil.copytree(Path(CUR_PATH, "..", "packages"), Path(cls.t, "packages"))

        os.chdir(cls.t)
        result = cls.runner.invoke(
            cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]
        )
        assert result.exit_code == 0

        result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "create", "--local", cls.agent_name],
            standalone_mode=False,
        )
        # this also by default adds the oef skill and error skill
        assert result.exit_code == 0
        os.chdir(cls.agent_name)

        # add the error skill again
        cls.result = cls.runner.invoke(
            cli,
            [*CLI_LOG_OPTION, "add", "--local", "skill", str(cls.skill_id)],
            standalone_mode=False,
        )
Beispiel #30
0
 def setup_class(cls):
     """Set the test up."""
     cls.runner = CliRunner()
     cls.agent_name = "myagent"
     cls.cwd = os.getcwd()
     cls.t = tempfile.mkdtemp()
     os.chdir(cls.t)