def test_prepare_btctx_api_and_send_key_for_download_when_link_true(
            self, mock_btctxstore):
        """
        Test, that when the ``main`` function passes ``link=False``
        argument to the ``download`` API function, the ``sender_key`` and
        ``btctx_api`` arguments will be prepared and passed to the
        ``download()`` call.
        """
        # Make a list of arguments for the parser.
        mock_sys_argv = '__file__ download FILE_HASH'.split()
        # Get argument's list from the "download" function before as mock it.
        download_available_args = get_all_func_args(core.download)
        # mock the Response object for the mocking the download's return
        trick_response = Response()
        trick_response.status_code = 200

        with patch('sys.argv', mock_sys_argv):
            with patch('metatool.cli.get_all_func_args',
                       return_value=get_all_func_args(core.download)):
                with patch('metatool.core.download',
                           return_value=trick_response) as mock_download:
                    main()
        passed_args = mock_download.call_args[1]
        omitted_args = set(download_available_args) - set(passed_args.keys())
        self.assertSetEqual(
            omitted_args, set(),
            'Full set of arguments should be passed '
            'to the download() call, when the "--link" is not occured.'
        )
        expected_BtcTxStore_call = call(testnet=True, dryrun=True).create_key()
        self.assertEqual(
            mock_btctxstore.mock_calls,
            expected_BtcTxStore_call.call_list(),
            "The btctxstore.BtcTxStore should be properly called to create "
            "credentials, as expected when the --link argument was parsed!"

        )
        self.assertEqual(
            mock_download.call_count,
            1,
            '"download" should be called only once!'
        )
    def test_omit_btctx_api_and_send_key_for_download_when_link_true(
            self, mock_btctxstore):
        """
        Test, that when the ``main`` function passes ``link=True`` argument
         to the ``download`` API function, the ``sender_key`` and
        ``btctx_api`` arguments will not be prepared and passed to the
        ``download()`` call.
        """
        # Make a list of arguments for the parser.
        mock_sys_argv = '__file__ download FILE_HASH --link'.split()

        # Get argument's list from the "download" function before as mock it.
        download_available_args = get_all_func_args(core.download)

        # mock the Response object for the mocking the download's return
        trick_response = Response()
        trick_response.status_code = 200

        with patch('sys.argv', mock_sys_argv):
            with patch('metatool.cli.get_all_func_args',
                       return_value=get_all_func_args(core.download)):
                with patch('metatool.core.download',
                           return_value=trick_response) as mock_download:
                    main()
        passed_args = mock_download.call_args[1]
        omitted_args = set(download_available_args) - set(passed_args.keys())
        self.assertFalse(
            mock_btctxstore.called,
            "The btctxstore.BtcTxStore module should not be called when "
            "the --link argument wasn't parsed!"
        )
        self.assertSetEqual(
            omitted_args, {'btctx_api', 'sender_key'},
            "Only btctx_api and sender_key arguments should not be passed "
            "to the download() call, when the `--link` argument is occurred."
        )
        self.assertEqual(
            mock_download.call_count,
            1,
            '"download" should be called only once!'
        )
    def test_get_all_func_args(self):
        """
        Test of accurate discovery of required arguments of the function.
        """
        expected_args_set = ['arg_1', 'arg_2', 'arg_3']

        self.assertListEqual(
            get_all_func_args(lambda arg_1, arg_2, arg_3=True: None),
            expected_args_set,
            '"get_all_func_args" must return tuple like "expected_args_set" !'
        )

        # definition of the tested function
        def test_function(one, two=True, *args, **kwargs):
            local_variable = None
        expected_args_set = ['one', 'two']
        self.assertListEqual(
            get_all_func_args(test_function),
            expected_args_set,
            '"get_all_func_args" must return tuple like "expected_args_set" !'
        )