def test_get_field(self, get_credentials_mock, get_connection_mock):
        # Inputs to constructor
        default_folder_id = 'test_id'
        default_public_ssh_key = 'test_key'

        extra_dejson = {"extra__yandexcloud__one": "value_one"}
        get_connection_mock['extra_dejson'] = "sdsd"
        get_connection_mock.extra_dejson = '{"extras": "extra"}'
        get_connection_mock.return_value = mock.Mock(
            connection_id='yandexcloud_default', extra_dejson=extra_dejson)
        get_credentials_mock.return_value = {"token": 122323}

        hook = YandexCloudBaseHook(None, default_folder_id,
                                   default_public_ssh_key)

        self.assertEqual(hook._get_field('one'), 'value_one')
Example #2
0
    def test_get_credentials_raise_exception(self, get_connection_mock):
        """tests 'get_credentials' method raising exception if none of the required fields are passed."""

        # Inputs to constructor
        default_folder_id = 'test_id'
        default_public_ssh_key = 'test_key'

        extra_dejson = '{"extras": "extra"}'
        get_connection_mock['extra_dejson'] = "sdsd"
        get_connection_mock.extra_dejson = '{"extras": "extra"}'
        get_connection_mock.return_value = mock.Mock(
            connection_id='yandexcloud_default', extra_dejson=extra_dejson)

        with pytest.raises(AirflowException):
            YandexCloudBaseHook(None, default_folder_id,
                                default_public_ssh_key)
Example #3
0
    def test_client_created_without_exceptions(self, get_credentials_mock, get_connection_mock):
        """tests `init` method to validate client creation when all parameters are passed"""

        # Inputs to constructor
        default_folder_id = 'test_id'
        default_public_ssh_key = 'test_key'

        extra_dejson = '{"extras": "extra"}'
        get_connection_mock['extra_dejson'] = "sdsd"
        get_connection_mock.extra_dejson = '{"extras": "extra"}'
        get_connection_mock.return_value = mock.Mock(
            connection_id='yandexcloud_default', extra_dejson=extra_dejson
        )
        get_credentials_mock.return_value = {"token": 122323}

        hook = YandexCloudBaseHook(None, default_folder_id, default_public_ssh_key)
        assert hook.client is not None