def test_instantiates_with_connection_string_no_shared_access_key(self): connection_string = ( "HostName={hostname};DeviceId={device_id};SharedAccessKeyName={skn}" .format(hostname=fake_hostname, device_id=fake_device_id, skn=fake_shared_access_key_name)) with pytest.raises(ValueError): IoTHubHttpRuntimeManager.from_connection_string(connection_string)
def test_instantiates_with_connection_string_no_device_id(self): connection_string = "HostName={hostname};SharedAccessKeyName={skn};SharedAccessKey={sk}".format( hostname=fake_hostname, skn=fake_shared_access_key_name, sk=fake_shared_access_key) obj = IoTHubHttpRuntimeManager(connection_string) assert isinstance(obj, IoTHubHttpRuntimeManager)
def test_instantiates_with_connection_string_no_host_name(self): connection_string = "DeviceId={device_id};SharedAccessKeyName={skn};SharedAccessKey={sk}".format( device_id=fake_device_id, skn=fake_shared_access_key_name, sk=fake_shared_access_key) with pytest.raises(ValueError): IoTHubHttpRuntimeManager(connection_string)
def test_connection_string_auth(self, connection_string): client = IoTHubHttpRuntimeManager.from_connection_string( connection_string=connection_string) assert repr(client.auth) == connection_string assert client.protocol.config.base_url == "https://" + client.auth[ "HostName"] assert client.protocol.config.credentials == client.auth
def iothub_http_runtime_manager(): connection_string = "HostName={hostname};DeviceId={device_id};SharedAccessKeyName={skn};SharedAccessKey={sk}".format( hostname=fake_hostname, device_id=fake_device_id, skn=fake_shared_access_key_name, sk=fake_shared_access_key, ) iothub_http_runtime_manager = IoTHubHttpRuntimeManager(connection_string) return iothub_http_runtime_manager
def test_token_credential_auth(self, mocker): mock_azure_identity_TokenCredential = mocker.MagicMock() client = IoTHubHttpRuntimeManager.from_token_credential( fake_hostname, mock_azure_identity_TokenCredential) assert client.auth._policy._credential == mock_azure_identity_TokenCredential assert client.protocol.config.base_url == "https://" + fake_hostname assert client.protocol.config.credentials == client.auth
def test_instantiates_with_empty_connection_string(self): with pytest.raises(ValueError): IoTHubHttpRuntimeManager("")