Example #1
0
 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 = IoTHubJobManager(connection_string)
     assert isinstance(obj, IoTHubJobManager)
Example #2
0
 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):
         IoTHubJobManager(connection_string)
 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):
         IoTHubJobManager(connection_string)
Example #4
0
def iothub_job_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_job_manager = IoTHubJobManager(connection_string)
    return iothub_job_manager
    def test_iot_hub_job_manager_export_import_jobs(self):
        try:
            iothub_job_manager = IoTHubJobManager(iothub_connection_str)

            # Create export/import job
            storage_authentication_type = "keyBased"
            properties_type = "export"
            job_properties = JobProperties()
            job_properties.storage_authentication_type = storage_authentication_type
            job_properties.type = properties_type
            job_properties.output_blob_container_uri = output_container_uri

            new_export_import_job = iothub_job_manager.create_import_export_job(
                job_properties)

            # Verify result
            assert new_export_import_job.storage_authentication_type == storage_authentication_type
            assert new_export_import_job.type == properties_type
            assert new_export_import_job.output_blob_container_uri == output_container_uri

            # Get export/import job
            get_export_import_job = iothub_job_manager.get_import_export_job(
                new_export_import_job.job_id)

            # Verify result
            assert get_export_import_job.job_id == new_export_import_job.job_id
            assert (get_export_import_job.storage_authentication_type ==
                    new_export_import_job.storage_authentication_type)
            assert get_export_import_job.type == new_export_import_job.type
            assert (get_export_import_job.output_blob_container_uri ==
                    new_export_import_job.output_blob_container_uri)

            # Get all export/import jobs
            export_import_jobs = iothub_job_manager.get_import_export_jobs()

            assert new_export_import_job in export_import_jobs

            # Cancel export_import job
            iothub_job_manager.cancel_import_export_job(
                new_export_import_job.job_id)

            # Get all export/import jobs
            export_import_jobs = iothub_job_manager.get_import_export_jobs()

            assert new_export_import_job not in export_import_jobs

        except Exception as e:
            logging.exception(e)
    def test_iot_hub_job_manager_jobs(self):
        try:
            iothub_job_manager = IoTHubJobManager(iothub_connection_str)

            # Create job request
            job_id = "sample_cloud_to_device_method"
            job_type = "cloudToDeviceMethod"
            job_execution_time_max = 60
            job_request = JobRequest()
            job_request.job_id = job_id
            job_request.type = job_type
            job_request.start_time = ""
            job_request.max_execution_time_in_seconds = job_execution_time_max
            job_request.update_twin = ""
            job_request.query_condition = ""

            new_job_response = iothub_job_manager.create_job(
                job_request.job_id, job_request)

            # Verify result
            assert new_job_response.job_id == job_type
            assert new_job_response.type == job_type
            assert new_job_response.max_execution_time_in_seconds == job_execution_time_max

            # Get job
            get_job = iothub_job_manager.get_job(new_job_response.job_id)

            # Verify result
            assert get_job.job_id == job_id
            assert get_job.type == job_type
            assert get_job.max_execution_time_in_seconds == job_execution_time_max

            # Cancel job
            iothub_job_manager.cancel_job(get_job.job_id)

        except Exception as e:
            logging.exception(e)
Example #7
0
 def test_instantiates_with_empty_connection_string(self):
     with pytest.raises(ValueError):
         IoTHubJobManager("")