import pytest from vector_utils.connections import connection_info @pytest.fixture def base_data_set(): return { 'authenticate_type': 'password', 'connection_type': 'itp', 'user_name': 'user', 'password': 'pass', 'port': 22, 'remote_initial_dir': '/', 'domain_name': 'mydomain'} @pytest.fixture def cloud_data_set(): return { 'udp_port': 3001, 'cloud_domain_name': 'cloud domain', 'cloud_user_name': 'cloud user', 'cloud_password': 'cloud pass', 'cloud_protocol': 'azu', 'gcs_config_file': 'gcs config file'} @pytest.fixture def aspera_data_set(base_data_set, cloud_data_set): data_set = base_data_set data_set.update(cloud_data_set) data_set['connection_type'] = 'aspera_cloud' return data_set @pytest.fixture def gcs_data_set(base_data_set, cloud_data_set): data_set = base_data_set data_set.update(cloud_data_set) data_set['connection_type'] = 'gcs' return data_set def test_connection_info_setup(base_data_set): """Test connection info setup.""" c = connection_info.ConnectionInfo(base_data_set, 'release') assert c.port == 22 assert c.authenticate_type == 'password' assert c.connection_type == 'itp' assert c.user_name == 'user' assert c.password == 'pass' assert c.remote_initial_dir == '/' def test_exception(): with pytest.raises(Exception): connection_info.ConnectionInfo({}, 'release') def test_missing_domain_name(base_data_set): base_data_set['connection_type'] = 'sftp' del base_data_set['domain_name'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(base_data_set, 'release') assert str(excinfo.value) == 'Domain Name is missing.' def test_missing_password(base_data_set): del base_data_set['password'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(base_data_set, 'release') assert str(excinfo.value) == 'Password is missing.' def test_missing_auth_type(base_data_set): del base_data_set['authenticate_type'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(base_data_set, 'release') assert str(excinfo.value) == 'Authenticate Type is missing.' def test_missing_connection_type(base_data_set): del base_data_set['connection_type'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(base_data_set, 'release') assert str(excinfo.value) == 'Connection Type is missing.' def test_missing_port(base_data_set): base_data_set['connection_type'] = 'sftp' del base_data_set['port'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(base_data_set, 'release') assert str(excinfo.value) == 'Port is missing.' def test_missing_username(base_data_set): del base_data_set['user_name'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(base_data_set, 'release') assert str(excinfo.value) == 'User Name is missing.' def test_missing_private_key(base_data_set): base_data_set['authenticate_type'] = 'public_key' with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(base_data_set, 'release') assert str(excinfo.value) == 'Private Key is missing.' def test_invalid_s3_region(base_data_set): base_data_set['aws_s3_region'] = 'abcdef' with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(base_data_set, 'release') assert str(excinfo.value) == 'Invalid AWS S3 region.' def test_valid_s3_region(base_data_set): base_data_set['aws_s3_region'] = 'us-east-1' c = connection_info.ConnectionInfo(base_data_set, 'release') assert c.s3_region == 'us-east-1' def test_domain_name_with_s3_protocol(base_data_set): base_data_set['domain_name'] = 's3://my_bucket_name' c = connection_info.ConnectionInfo(base_data_set, 'release') assert c.domain_name == 'my_bucket_name' def test_domain_name_with_sftp_protocol(base_data_set): base_data_set['domain_name'] = 'sftp://my.sftp.com' c = connection_info.ConnectionInfo(base_data_set, 'release') assert c.domain_name == 'my.sftp.com' def test_domain_name_with_ftp_protocol(base_data_set): base_data_set['domain_name'] = 'ftp://my.ftp.com' c = connection_info.ConnectionInfo(base_data_set, 'release') assert c.domain_name == 'my.ftp.com' def test_domain_name_with_itp_protocol(base_data_set): base_data_set['domain_name'] = 'itp://my.itp.com' c = connection_info.ConnectionInfo(base_data_set, 'release') assert c.domain_name == 'my.itp.com' def test_aspera_cloud_setup(aspera_data_set): c = connection_info.ConnectionInfo(aspera_data_set, 'release') assert c.cloud_domain_name == 'cloud domain' assert c.cloud_user_name == 'cloud user' assert c.cloud_password == 'cloud pass' assert c.udp_port == 3001 assert c.cloud_protocol == 'azu' def test_missing_udp_port(aspera_data_set): del aspera_data_set['udp_port'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(aspera_data_set, 'release') assert str(excinfo.value) == 'UDP Port is missing.' def test_missing_cloud_domain(aspera_data_set): del aspera_data_set['cloud_domain_name'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(aspera_data_set, 'release') assert str(excinfo.value) == 'Cloud Domain Name is missing.' def test_missing_cloud_user(aspera_data_set): del aspera_data_set['cloud_user_name'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(aspera_data_set, 'release') assert str(excinfo.value) == 'Cloud User Name is missing.' def test_missing_cloud_password(aspera_data_set): del aspera_data_set['cloud_password'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(aspera_data_set, 'release') assert str(excinfo.value) == 'Cloud Password is missing.' def test_missing_cloud_protocol(aspera_data_set): del aspera_data_set['cloud_protocol'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(aspera_data_set, 'release') assert str(excinfo.value) == 'Cloud Protocol is missing.' def test_gcs_setup(gcs_data_set): c = connection_info.ConnectionInfo(gcs_data_set, 'release') assert c.connection_type == 'gcs' def test_missing_gcs_file(gcs_data_set): del gcs_data_set['gcs_config_file'] with pytest.raises(Exception) as excinfo: connection_info.ConnectionInfo(gcs_data_set, 'release') assert str(excinfo.value) == 'GCS Config file is missing.'