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):
         IoTHubConfigurationManager.from_connection_string(connection_string)
    def test_connection_string_auth(self, connection_string):
        client = IoTHubConfigurationManager.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 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 = IoTHubConfigurationManager.from_connection_string(connection_string)
     assert isinstance(obj, IoTHubConfigurationManager)
def iothub_configuration_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_configuration_manager = IoTHubConfigurationManager(connection_string)
    return iothub_configuration_manager
Example #5
0
    def test_token_credential_auth(self, mocker):
        mock_azure_identity_TokenCredential = mocker.MagicMock()

        client = IoTHubConfigurationManager.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
Example #6
0
    def test_iot_hub_configuration_manager(self):
        try:
            iothub_configuration = IoTHubConfigurationManager(
                iothub_connection_str)

            # Create configuration
            config_id = "e2e_test_config-" + str(uuid.uuid4())

            config = Configuration()
            config.id = config_id

            content = ConfigurationContent(
                device_content={
                    "properties.desired.chiller-water":
                    {"temperature: 68, pressure:28"}
                })
            config.content = content

            metrics = ConfigurationMetrics(
                queries={
                    "waterSettingPending":
                    "SELECT deviceId FROM devices WHERE properties.reported.chillerWaterSettings.status='pending'"
                })
            config.metrics = metrics

            # Create configuration
            new_config = iothub_configuration.create_configuration(config)

            # Verify result
            assert new_config.id == config_id

            # Get configuration
            get_config = iothub_configuration.get_configuration(config_id)

            # Verify result
            assert get_config.id == config_id

            # Get all configurations
            all_configurations = iothub_configuration.get_configurations()

            # Verify result
            assert get_config in all_configurations

            # Delete configuration
            iothub_configuration.delete_configuration(config_id)

            # Get all configurations
            all_configurations = iothub_configuration.get_configurations()

            # # Verify result
            assert get_config not in all_configurations

        except Exception as e:
            logging.exception(e)
 def test_instantiates_with_empty_connection_string(self):
     with pytest.raises(ValueError):
         IoTHubConfigurationManager.from_connection_string("")