Exemple #1
0
 def test_fetch_agent_with_dependencies_unable_to_fetch(self, *mocks):
     """Test for fetch_agent method unable to fetch."""
     ctx_mock = ContextMock(
         connections=["public/id:{}".format(PublicIdMock.DEFAULT_VERSION)]
     )
     with self.assertRaises(ClickException):
         fetch_agent(ctx_mock, PublicIdMock(), ContextMock())
Exemple #2
0
 def test_publish_agent_fails(self, *mocks):
     """Test for publish_agent positive result."""
     description = "Some description."
     version = "0.1.0"
     context_mock = ContextMock(description=description, version=version)
     context_mock.cwd = "."
     publish_agent(context_mock)
Exemple #3
0
 def test_convert_root_vendor_positive(self, *mocks):
     """Test for convert method with root "vendor" positive result."""
     value = "vendor.author.protocols.package_name.attribute_name"
     ctx_mock = ContextMock()
     ctx_mock.obj = mock.Mock()
     ctx_mock.obj.set_config = mock.Mock()
     obj = AEAJsonPathType()
     obj.convert(value, "param", ctx_mock)
 def test__fetch_agent_locally_with_deps_positive(self, *mocks):
     """Test for fetch_agent_locally method with deps positive result."""
     click_context_mock = ContextMock()
     ctx_mock = ContextMock(connections=["1"],
                            protocols=["2"],
                            skills=["3"])
     _fetch_agent_locally(ctx_mock, PublicIdMock(), click_context_mock)
     click_context_mock.invoke.assert_called()
Exemple #5
0
 def test__fetch_agent_locally_with_deps_positive(self, *mocks):
     """Test for fetch_agent_locally method with deps positive result."""
     click_context_mock = ContextMock()
     public_id = PublicIdMock.from_str("author/name:0.1.0")
     ctx_mock = ContextMock(
         connections=[public_id],
         protocols=[public_id],
         skills=[public_id],
         contracts=[public_id],
     )
     _fetch_agent_locally(ctx_mock, PublicIdMock(), click_context_mock)
 def test_fetch_agent_locally_positive(
     self,
     exists_mock,
     try_to_load_agent_config_mock,
     _try_get_item_source_path_mock,
     join_mock,
     copy_tree,
 ):
     """Test for fetch_agent_locally method positive result."""
     _fetch_agent_locally(ContextMock(), PublicIdMock(), ContextMock())
     copy_tree.assert_called_once_with("path", "joined-path")
Exemple #7
0
 def test_fetch_agent_locally_with_deps_fail(self, *mocks):
     """Test for fetch_agent_locally method with deps ClickException catch."""
     public_id = PublicIdMock.from_str("author/name:0.1.0")
     ctx_mock = ContextMock(
         connections=[public_id],
         protocols=[public_id],
         skills=[public_id],
         contracts=[public_id],
     )
     ctx_mock.config["is_local"] = True
     with self.assertRaises(ClickException):
         fetch_agent_locally(ctx_mock, PublicIdMock())
Exemple #8
0
 def test__is_version_correct_negative(self):
     """Test for _is_version_correct method negative result."""
     ctx_mock = ContextMock(version="correct")
     public_id_mock = PublicIdMock()
     public_id_mock.version = "incorrect"
     result = _is_version_correct(ctx_mock, public_id_mock)
     self.assertFalse(result)
Exemple #9
0
 def test_remove_item_item_folder_not_exists(
     self, *mocks
 ):  # pylint: disable=unused-argument
     """Test for save_agent_locally item folder not exists."""
     public_id = PublicIdMock.from_str("author/name:0.1.0")
     with pytest.raises(ClickException, match="Can not find folder for the package"):
         remove_item(ContextMock(protocols=[public_id]), "protocol", public_id)
Exemple #10
0
    def testfind_item_in_distribution_bad_config(self, *mocks):
        """Test find_item_in_distribution for bad config result."""
        public_id = PublicIdMock.from_str("fetchai/echo:0.11.0")
        with self.assertRaises(ClickException) as cm:
            find_item_in_distribution(ContextMock(), "skill", public_id)

        self.assertIn("configuration file not valid", cm.exception.message)
Exemple #11
0
    def testfind_item_in_distribution_not_found(self, *mocks):
        """Test find_item_in_distribution for not found result."""
        public_id = PublicIdMock.from_str("fetchai/echo:0.11.0")
        with self.assertRaises(ClickException) as cm:
            find_item_in_distribution(ContextMock(), "skill", public_id)

        self.assertIn("Cannot find skill", cm.exception.message)
Exemple #12
0
 def test__generate_item_prerequisite_app_not_installed(self, *mocks):
     """Test for fetch_agent_locally method parsing specs fail."""
     ctx_mock = ContextMock()
     with self.assertRaises(ClickException) as cm:
         _generate_protocol(ctx_mock, "path")
     expected_msg = "Protocol is NOT generated. The following error happened while generating the protocol:\n"
     self.assertIn(expected_msg, cm.exception.message)
Exemple #13
0
 def test_save_item_locally_positive(
     self,
     _check_package_public_id_mock,
     try_get_item_source_path_mock,
     try_get_item_target_path_mock,
     copy_tree_mock,
 ):
     """Test for save_item_locally positive result."""
     item_type = "skill"
     item_id = PublicIdMock()
     ctx_mock = ContextMock()
     _save_item_locally(ctx_mock, item_type, item_id)
     try_get_item_source_path_mock.assert_called_once_with(
         "cwd", None, "skills", item_id.name
     )
     try_get_item_target_path_mock.assert_called_once_with(
         ctx_mock.agent_config.registry_path,
         item_id.author,
         item_type + "s",
         item_id.name,
     )
     _check_package_public_id_mock.assert_called_once_with(
         "source", item_type, item_id
     )
     copy_tree_mock.assert_called_once_with("source", "target")
Exemple #14
0
 def test__is_version_correct_positive(self):
     """Test for _is_version_correct method positive result."""
     public_id = PublicId("author", "package", "0.1.0")
     ctx_mock = ContextMock(version=public_id.version)
     ctx_mock.agent_config.public_id = public_id
     result = _is_version_correct(ctx_mock, public_id)
     self.assertTrue(result)
Exemple #15
0
 def test_push_item_positive(
     self,
     is_readme_present_mock,
     path_exists_mock,
     request_api_mock,
     load_yaml_mock,
     compress_mock,
     getcwd_mock,
     rm_tarfiles_mock,
     check_is_author_logged_in_mock,
     open_mock,
 ):
     """Test for push_item positive result."""
     public_id = PublicIdMock(
         name="some-name",
         author="some-author",
         version="{}".format(PublicIdMock.DEFAULT_VERSION),
     )
     push_item(ContextMock(), "some-type", public_id)
     request_api_mock.assert_called_once_with(
         "POST",
         "/some-types/create",
         data={
             "name": "some-name",
             "description": "some-description",
             "version": "some-version",
             "protocols": ["protocol_id"],
         },
         is_auth=True,
         files={"file": "opened_file", "readme": "opened_file"},
     )
Exemple #16
0
 def test_publish_agent_positive(self, is_readme_present_mock,
                                 request_api_mock, *mocks):
     """Test for publish_agent positive result."""
     description = "Some description."
     version = "0.1.0"
     context_mock = ContextMock(description=description, version=version)
     publish_agent(context_mock)
     request_api_mock.assert_called_once_with(
         "POST",
         "/agents/create",
         data={
             "name": "agent-name",
             "description": description,
             "version": version,
             "connections": [],
             "contracts": [],
             "protocols": [],
             "skills": [],
         },
         is_auth=True,
         files={
             "file": mock.ANY,
             "readme": mock.ANY
         },
     )
Exemple #17
0
 def test__scaffold_dm_handler_positive(self, *mocks):
     """Test _scaffold_dm_handler method for positive result."""
     dm_handler = {}
     ctx = ContextMock()
     ctx.agent_config.decision_maker_handler = dm_handler
     ctx.agent_loader.dump = mock.Mock()
     _scaffold_dm_handler(ctx)
     ctx.agent_loader.dump.assert_called_once()
 def test__add_item_deps_missing_skills_positive(self, add_item_mock):
     """Test _add_item_deps for positive result with missing skills."""
     ctx = ContextMock(skills=[])
     item_config = mock.Mock()
     item_config.protocols = []
     item_config.contracts = []
     item_config.skills = ["skill-1", "skill-2"]
     _add_item_deps(ctx, "skill", item_config)
Exemple #19
0
 def test__scaffold_dm_handler_exception(self, os_remove_mock, *mocks):
     """Test _scaffold_dm_handler method exception raised result."""
     dm_handler = {}
     ctx = ContextMock()
     ctx.agent_config.decision_maker_handler = dm_handler
     with self.assertRaises(ClickException):
         _scaffold_dm_handler(ctx)
     os_remove_mock.assert_called_once()
Exemple #20
0
 def test__is_version_correct_negative(self):
     """Test for _is_version_correct method negative result."""
     public_id_a = PublicId("author", "package", "0.1.0")
     public_id_b = PublicId("author", "package", "0.1.1")
     ctx_mock = ContextMock(version=public_id_b.version)
     ctx_mock.agent_config.public_id = public_id_b
     result = _is_version_correct(ctx_mock, public_id_a)
     self.assertFalse(result)
Exemple #21
0
 def test__generate_item_parsing_specs_fail(self, *mocks):
     """Test for fetch_agent_locally method parsing specs fail."""
     ctx_mock = ContextMock()
     with self.assertRaises(ClickException) as cm:
         _generate_protocol(ctx_mock, "path")
     expected_msg = (
         "Protocol is NOT generated. The following error happened while generating the protocol:\n"
         "Error while parsing the protocol specification: ")
     self.assertIn(expected_msg, cm.exception.message)
Exemple #22
0
    def testfind_item_in_distribution_cant_find(self, from_conftype_mock, *mocks):
        """Test find_item_locally for can't find result."""
        public_id = PublicIdMock.from_str("fetchai/echo:0.11.0")
        with self.assertRaises(ClickException) as cm:
            find_item_in_distribution(ContextMock(), "skill", public_id)

        self.assertEqual(
            cm.exception.message, "Cannot find skill with author and version specified."
        )
 def test__generate_item_no_res(self, *mocks):
     """Test for fetch_agent_locally method no black."""
     ctx_mock = ContextMock()
     with self.assertRaises(ClickException) as cm:
         _generate_item(ctx_mock, "protocol", "path")
     expected_msg = (
         "Please install black code formater first! See the following link: "
         "https://black.readthedocs.io/en/stable/installation_and_usage.html"
     )
     self.assertEqual(cm.exception.message, expected_msg)
Exemple #24
0
 def test__generate_item_no_res_isort_missing(self, *_mocks):
     """Test for fetch_agent_locally method no isort."""
     ctx_mock = ContextMock()
     with self.assertRaises(ClickException) as cm:
         _generate_protocol(ctx_mock, "path")
     expected_msg = (
         "Protocol is NOT generated. The following error happened while generating the protocol:\n"
         "Cannot find isort code formatter! To install, please follow this link: "
         "https://pycqa.github.io/isort/#installing-isort")
     self.assertEqual(cm.exception.message, expected_msg)
Exemple #25
0
 def test_fetch_agent_positive(
     self,
     request_api_mock,
     extract_mock,
     download_file_mock,
     try_to_load_agent_config_mock,
     makedirs_mock,
 ):
     """Test for fetch_agent method positive result."""
     public_id_mock = PublicIdMock()
     fetch_agent(ContextMock(), public_id_mock, ContextMock())
     request_api_mock.assert_called_with(
         "GET",
         "/agents/{}/{}/{}".format(
             public_id_mock.author, public_id_mock.name, public_id_mock.version
         ),
     )
     download_file_mock.assert_called_once_with("url", "cwd")
     extract_mock.assert_called_once_with("filepath", "cwd")
Exemple #26
0
 def test_remove_item_item_folder_not_exists(
     self, *mocks
 ):  # pylint: disable=unused-argument
     """Test for component bad configuration load."""
     public_id = PublicIdMock.from_str("author/name:0.1.0")
     with pytest.raises(
         ClickException,
         match="Error loading .* configuration, author/name do not match: .*",
     ):
         remove_item(ContextMock(protocols=[public_id]), "protocol", public_id)
Exemple #27
0
 def test__generate_item_no_res(self, *_mocks):
     """Test for fetch_agent_locally method no black."""
     ctx_mock = ContextMock()
     with self.assertRaises(ClickException) as cm:
         _generate_protocol(ctx_mock, "path")
     expected_msg = (
         "Protocol is NOT generated. The following error happened while generating the protocol:\n"
         "Cannot find black code formatter! To install, please follow this link: "
         "https://black.readthedocs.io/en/stable/installation_and_usage.html"
     )
     self.assertEqual(cm.exception.message, expected_msg)
Exemple #28
0
    def test_clean_after_positive(self, rmtree_mock, *mocks):
        """Test clean_after decorator method for positive result."""
        @clean_after
        def func(click_context):
            ctx = cast(Context, click_context.obj)
            ctx.clean_paths.append("clean/path")
            raise ClickException("Message")

        with self.assertRaises(ClickException):
            func(ContextMock())
            rmtree_mock.assert_called_once_with("clean/path")
Exemple #29
0
 def test__scaffold_dm_handler_already_exists(self):
     """Test _scaffold_dm_handler method dm handler already exists result."""
     dm_handler = {"dm": "handler"}
     ctx = ContextMock()
     ctx.agent_config.decision_maker_handler = dm_handler
     with self.assertRaises(ClickException) as cm:
         _scaffold_dm_handler(ctx)
     self.assertEqual(
         "A decision maker handler specification already exists. Aborting...",
         str(cm.exception),
     )
Exemple #30
0
 def test_save_agent_locally_positive(
     self,
     path_join_mock,
     _try_get_item_target_path_mock,
     path_exists_mock,
     makedirs_mock,
     copyfile_mock,
     _check_is_item_in_local_registry_mock,
 ):
     """Test for save_agent_locally positive result."""
     _save_agent_locally(ContextMock(connections=["author/name:version"]))
     makedirs_mock.assert_called_once_with("target-dir", exist_ok=True)
     copyfile_mock.assert_called_once_with("joined-path", "joined-path")