示例#1
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)
示例#2
0
 def test_fetch_agent_locally_with_deps_positive(self, *mocks):
     """Test for fetch_agent_locally method with deps positive result."""
     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())
示例#3
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],
     )
     with self.assertRaises(ClickException):
         fetch_agent_locally(ctx_mock, PublicIdMock())
示例#4
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)
示例#5
0
 def test__check_is_item_in_local_registry_negative(self):
     """Test for _check_is_item_in_local_registry negative result."""
     public_id = PublicIdMock.from_str("author/name:version")
     registry_path = "some-registry-path"
     item_type_plural = "items"
     with self.assertRaises(ClickException):
         _check_is_item_in_local_registry(public_id, item_type_plural, registry_path)
示例#6
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)
示例#7
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())
示例#8
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)
示例#9
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"},
     )
示例#10
0
 def test__check_package_public_id_positive(self, *mocks):
     """Test for _check_package_public_id positive result."""
     _check_package_public_id(
         "source-path",
         "item-type",
         PublicIdMock.from_str("{}/name:0.1.0".format(AUTHOR)),
     )
示例#11
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")
示例#12
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()
     ctx_mock = ContextMock(connections=["1"],
                            protocols=["2"],
                            skills=["3"])
     _fetch_agent_locally(ctx_mock, PublicIdMock(), click_context_mock)
     click_context_mock.invoke.assert_called()
示例#13
0
 def test__check_package_public_id_negative(self, *mocks):
     """Test for _check_package_public_id negative result."""
     with self.assertRaises(ClickException):
         _check_package_public_id(
             "source-path",
             "item-type",
             PublicIdMock.from_str("{}/name:0.1.1".format(AUTHOR)),
         )
示例#14
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."
        )
示例#15
0
 def test__check_is_item_in_local_registry_positive(self, get_path_mock):
     """Test for _check_is_item_in_local_registry positive result."""
     public_id = PublicIdMock.from_str("author/name:version")
     registry_path = "some-registry-path"
     item_type_plural = "items"
     _check_is_item_in_local_registry(public_id, item_type_plural, registry_path)
     get_path_mock.assert_called_once_with(
         registry_path, public_id.author, item_type_plural, public_id.name
     )
示例#16
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)
示例#17
0
 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")
示例#18
0
 def test_fetch_agent_positive(
     self, request_api_mock, extract_mock, download_file_mock, *mocks
 ):
     """Test for fetch_agent method positive result."""
     public_id_mock = PublicIdMock()
     fetch_agent(ContextMock(), public_id_mock, alias="alias")
     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")
示例#19
0
    def test_push_item_item_not_found(
        self,
        path_exists_mock,
        request_api_mock,
        load_yaml_mock,
        compress_mock,
        getcwd_mock,
        rm_tarfiles_mock,
        check_is_author_logged_in_mock,
    ):
        """Test for push_item - item not found."""
        with self.assertRaises(ClickException):
            push_item(ContextMock(), "some-type", PublicIdMock())

        request_api_mock.assert_not_called()
示例#20
0
 def test_fetch_agent_with_dependencies_positive(
     self, request_api_mock, add_item_mock, extract_mock, download_file_mock, *mocks
 ):
     """Test for fetch_agent method with dependencies positive result."""
     public_id_mock = PublicIdMock()
     ctx_mock = ContextMock(
         connections=["public/id:{}".format(PublicIdMock.DEFAULT_VERSION)]
     )
     fetch_agent(ctx_mock, public_id_mock)
     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")
     add_item_mock.assert_called()
示例#21
0
 def test_fetch_agent_with_dependencies_positive(
     self,
     request_api_mock,
     fetch_package_mock,
     extract_mock,
     download_file_mock,
 ):
     """Test for fetch_agent method with dependencies positive result."""
     public_id_mock = PublicIdMock()
     fetch_agent(ContextMock(), public_id_mock)
     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/name")
     fetch_package_mock.assert_called()
示例#22
0
 def test_push_item_positive_without_readme(self, is_readme_present_mock,
                                            path_exists_mock,
                                            request_api_mock, *mocks):
     """Test for push_item without readme 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": PublicIdMock.DEFAULT_VERSION,
             "protocols": ["protocol_id"],
         },
         is_auth=True,
         files={"file": open("opened_file", "r")},
     )
示例#23
0
 def test_fetch_agent_with_dependencies_unable_to_fetch(self, *mocks):
     """Test for fetch_agent method positive result."""
     with self.assertRaises(ClickException):
         fetch_agent(ContextMock(), PublicIdMock())
示例#24
0
 def test__fetch_agent_locally_with_deps_sys_exit(self, *mocks):
     """Test for fetch_agent_locally method with deps system exit catch."""
     click_context_mock = ContextMock()
     click_context_mock.invoke = _raise_sys_exit
     ctx_mock = ContextMock(connections=["1"])
     _fetch_agent_locally(ctx_mock, PublicIdMock(), click_context_mock)
示例#25
0
 def test_fetch_agent_locally_incorrect_version(self, *mocks):
     """Test for fetch_agent_locally method incorrect agent version."""
     ctx = ContextMock()
     ctx.config["is_local"] = True
     with self.assertRaises(ClickException):
         fetch_agent_locally(ctx, PublicIdMock())
示例#26
0
 def test__fingerprint_item_package_not_found(self, *mocks):
     """Test for _fingerprint_item package not found result."""
     public_id = PublicIdMock()
     with self.assertRaises(ClickException) as cm:
         _fingerprint_item(ContextMock(), "skill", public_id)
     self.assertIn("Package not found at path", cm.exception.message)
示例#27
0
 def test__fingerprint_item_exception(self, *mocks):
     """Test for _fingerprint_item exception raised."""
     public_id = PublicIdMock()
     with self.assertRaises(ClickException):
         _fingerprint_item(ContextMock(), "skill", public_id)
示例#28
0
 def test_fetch_agent_locally_positive(self, copy_tree, *mocks):
     """Test for fetch_agent_locally method positive result."""
     fetch_agent_locally(ContextMock(), PublicIdMock(), alias="some-alias")
     copy_tree.assert_called_once_with("path", "joined-path")
示例#29
0
 def test_fetch_agent_locally_already_exists(self, *mocks):
     """Test for fetch_agent_locally method agent already exists."""
     with self.assertRaises(ClickException):
         fetch_agent_locally(ContextMock(), PublicIdMock())
示例#30
0
 def test_fetch_agent_locally_incorrect_version(self, *mocks):
     """Test for fetch_agent_locally method incorrect agent version."""
     with self.assertRaises(ClickException):
         fetch_agent_locally(ContextMock(), PublicIdMock())