def test_valid_env_device_connectionstring(): load_dotenv(".env") env_device_connectionstring = os.getenv("DEVICE_CONNECTION_STRING") connectionstring = DeviceConnectionString(env_device_connectionstring) assert connectionstring.HostName assert connectionstring.HubName assert connectionstring.SharedAccessKey assert connectionstring.DeviceId
def test_valid_env_device_connectionstring(): envvars.load_dotenv() env_device_connectionstring = os.getenv("DEVICE_CONNECTION_STRING") connectionstring = DeviceConnectionString(env_device_connectionstring) assert connectionstring.iothub_host.name assert connectionstring.iothub_host.hub_name assert connectionstring.shared_access_key assert connectionstring.device_id
def test_iothub_deploy_and_add_tags_retry_after_invalid_tag(): # GIVEN: `iothub deploy` run fails # WHEN: Device tag has an invalid format # THEN: Rerunning the command will lead to a failed deploy part, # as the deployment already exists from the previous run, # but it will succeed in adding the new and correct device tags. # Leaving the iothub and device in the initially desired end state again. # Arrange tags1 = 'invalid_tag' tags2 = '{"environment":"dev","building":"9"}' deployment_name = f'test-{uuid.uuid4()}' os.chdir(test_solution_shared_lib_dir) # Act result = runner_invoke([ 'build', '-f', "layered_deployment.flattened_props.template.json", '-P', get_platform_type() ]) result = runner_invoke([ 'iothub', 'deploy', '-f', 'config/layered_deployment.flattened_props.json', '-n', deployment_name, '-p', '10', '-t', "tags.environment='dev'", '-dt', tags1 ]) result_retry = runner_invoke([ 'iothub', 'deploy', '-f', 'config/layered_deployment.flattened_props.json', '-n', deployment_name, '-p', '10', '-t', "tags.environment='dev'", '-dt', tags2 ]) # Assert assert 'DEPLOYMENT COMPLETE' in result.output assert 'TAG UPDATE COMPLETE' not in result.output assert f"ERROR: Failed to add tag: '{tags1}' to device" in result.output assert 'DEPLOYMENT COMPLETE' not in result_retry.output assert 'TAG UPDATE COMPLETE' in result_retry.output assert tags2 in result_retry.output assert 'ERROR: Failed to deploy' in result_retry.output assert f'Message\': "ErrorCode:ConfigurationAlreadyExists;Configuration with id \'{deployment_name}\' already exist on IotHub.' in result_retry.output # Cleanup azure_cli = AzureCli(output, envvars) assert azure_cli.invoke_az_cli_outproc([ "iot", "edge", "deployment", "delete", "-d", deployment_name, "-l", envvars.get_envvar("IOTHUB_CONNECTION_STRING") ]) assert azure_cli.invoke_az_cli_outproc([ "iot", "hub", "device-twin", "replace", "-d", DeviceConnectionString( envvars.get_envvar("DEVICE_CONNECTION_STRING")).device_id, "-l", envvars.get_envvar("IOTHUB_CONNECTION_STRING"), "--json", "{}" ])
def test_valid_env_device_connectionstring(): """Test for loading data of env file""" env_device_connectionstring = os.getenv("DEVICE_CONNECTION_STRING") connectionstring = DeviceConnectionString(env_device_connectionstring) assert connectionstring.iothub_host.name assert connectionstring.iothub_host.hub_name assert connectionstring.shared_access_key assert connectionstring.device_id
def test_iothub_deploy_and_add_tags(): # Arrange tags = '{"environment":"dev","building":"9"}' deployment_name = f'test-{uuid.uuid4()}' os.chdir(test_solution_shared_lib_dir) # Act result = runner_invoke([ 'build', '-f', "layered_deployment.flattened_props.template.json", '-P', get_platform_type() ]) result = runner_invoke([ 'iothub', 'deploy', '-f', 'config/layered_deployment.flattened_props.json', '-n', deployment_name, '-p', '10', '-t', "tags.environment='dev'", '-dt', tags ]) # Assert assert 'DEPLOYMENT COMPLETE' in result.output assert 'TAG UPDATE COMPLETE' in result.output assert tags in result.output assert 'ERROR' not in result.output # Cleanup azure_cli = AzureCli(output, envvars) assert azure_cli.invoke_az_cli_outproc([ "iot", "edge", "deployment", "delete", "-d", deployment_name, "-l", envvars.get_envvar("IOTHUB_CONNECTION_STRING") ]) assert azure_cli.invoke_az_cli_outproc([ "iot", "hub", "device-twin", "replace", "-d", DeviceConnectionString( envvars.get_envvar("DEVICE_CONNECTION_STRING")).device_id, "-l", envvars.get_envvar("IOTHUB_CONNECTION_STRING"), "--json", "{}" ])
def test_invalid_devicehub_connectionstring(): connectionstring = DeviceConnectionString(invalid_device_connectionstring) assert connectionstring.HostName == "testhub.azure-devices.net" assert connectionstring.HubName == "testhub" assert not connectionstring.DeviceId assert connectionstring.SharedAccessKey == "othergibberish"
def test_empty_device_connectionstring(): connectionstring = DeviceConnectionString(emptystring) assert not connectionstring.data
def test_invalid_devicehub_connectionstring(): connectionstring = DeviceConnectionString(invalid_device_connectionstring) assert connectionstring.iothub_host.name == "testhub.azure-devices.net" assert connectionstring.iothub_host.hub_name == "testhub" assert not connectionstring.device_id assert connectionstring.shared_access_key == "othergibberish"
def test_default_tag_from_env(): # Arrange os.chdir(test_solution_shared_lib_dir) # Act result = runner_invoke(['solution', 'tag']) # Assert assert 'TAG UPDATE COMPLETE' in result.output assert '{"environment":"dev","building":"9"}' in result.output assert 'ERROR' not in result.output # Cleanup azure_cli = AzureCli(output, envvars) assert azure_cli.invoke_az_cli_outproc(["iot", "hub", "device-twin", "replace", "-d", DeviceConnectionString(envvars.get_envvar("DEVICE_CONNECTION_STRING")).device_id, "-l", envvars.get_envvar("IOTHUB_CONNECTION_STRING"), "--json", "{}"])