def run_scenario_individual_enrollment(): psc = ProvisioningServiceClient.create_from_connection_string(CONNECTION_STRING) att = AttestationMechanism.create_with_tpm(ENDORSEMENT_KEY) ie = IndividualEnrollment.create(REGISTRATION_ID, att) #create ret_ie = psc.create_or_update(ie) assert ret_ie.registration_id == REGISTRATION_ID #update twin = InitialTwin.create(TAGS, DESIRED_PROPERTIES) ret_ie.initial_twin = twin ret_ie = psc.create_or_update(ret_ie) assert ret_ie.registration_id == REGISTRATION_ID assert ret_ie.initial_twin.tags == TAGS assert ret_ie.initial_twin.desired_properties == DESIRED_PROPERTIES #get ret_ie = psc.get_individual_enrollment(REGISTRATION_ID) assert ret_ie.registration_id == REGISTRATION_ID assert ret_ie.initial_twin.tags == TAGS assert ret_ie.initial_twin.desired_properties == DESIRED_PROPERTIES #delete psc.delete(ret_ie) try: ret_ie = psc.get_individual_enrollment(REGISTRATION_ID) except ProvisioningServiceError: pass else: raise AssertionError #bulk enrollment enrollments = [] for i in range(BULK_SIZE): new = IndividualEnrollment.create(REGISTRATION_ID + str(i), att) enrollments.append(new) bulk_op = BulkEnrollmentOperation(CREATE, enrollments) res = psc.run_bulk_operation(bulk_op) assert res.is_successful #query qs = QuerySpecification("*") q = psc.create_individual_enrollment_query(qs) q_results = q.next() assert len(q_results) == BULK_SIZE #cleanup bulk_op = BulkEnrollmentOperation(DELETE, enrollments) res = psc.run_bulk_operation(bulk_op) assert res.is_successful
def run_scenario_enrollment_group(): psc = ProvisioningServiceClient.create_from_connection_string( CONNECTION_STRING) att = AttestationMechanism.create_with_x509_signing_certs( SIGNING_CERTIFICATE) eg = EnrollmentGroup.create(GROUP_ID, att) #create ret_eg = psc.create_or_update(eg) assert ret_eg.enrollment_group_id == GROUP_ID #update twin = InitialTwin.create(TAGS, DESIRED_PROPERTIES) ret_eg.initial_twin = twin ret_eg = psc.create_or_update(ret_eg) assert ret_eg.enrollment_group_id == GROUP_ID assert ret_eg.initial_twin.tags == TAGS assert ret_eg.initial_twin.desired_properties == DESIRED_PROPERTIES #get ret_eg = psc.get_enrollment_group(GROUP_ID) assert ret_eg.enrollment_group_id == GROUP_ID assert ret_eg.initial_twin.tags == TAGS assert ret_eg.initial_twin.desired_properties == DESIRED_PROPERTIES #query qs = QuerySpecification("*") q = psc.create_enrollment_group_query(qs) q_results = q.next() assert len(q_results) == 1 #delete psc.delete(ret_eg) try: ret_eg = psc.get_enrollment_group(GROUP_ID) except ProvisioningServiceError: pass else: raise AssertionError
def test_ie_create_full_model(self): att = AttestationMechanism.create_with_tpm(TEST_EK) ts = InitialTwin.create() capabilities = DeviceCapabilities.create() ret = IndividualEnrollment.create(TEST_REG_ID, att, TEST_DEV_ID, TEST_HOST_NAME, ts, \ PROV_STATUS_ENABLED, capabilities) internal = ret._internal self.assertIsInstance(ret, IndividualEnrollment) self.assertEqual(internal.registration_id, TEST_REG_ID) self.assertEqual(internal.device_id, TEST_DEV_ID) self.assertEqual(internal.iot_hub_host_name, TEST_HOST_NAME) self.assertEqual(internal.provisioning_status, PROV_STATUS_ENABLED) self.assertEqual(internal.attestation, att._internal) self.assertIs(ret._att_wrapper, att) self.assertEqual(internal.initial_twin, ts._internal) self.assertIs(ret._twin_wrapper, ts) self.assertIsNone(internal.registration_state) self.assertIsNone(ret._drs_wrapper) self.assertEqual(internal.capabilities, capabilities._internal) self.assertIs(ret._capabilities_wrapper, capabilities) self.assertIsNone(internal.etag) self.assertIsNone(internal.created_date_time_utc) self.assertIsNone(internal.last_updated_date_time_utc)
def run_scenario_enrollment_group(): psc = ProvisioningServiceClient.create_from_connection_string(CONNECTION_STRING) att = AttestationMechanism.create_with_x509_signing_certs(SIGNING_CERTIFICATE) eg = EnrollmentGroup.create(GROUP_ID, att) #create ret_eg = psc.create_or_update(eg) assert ret_eg.enrollment_group_id == GROUP_ID #update twin = InitialTwin.create(TAGS, DESIRED_PROPERTIES) ret_eg.initial_twin = twin ret_eg = psc.create_or_update(ret_eg) assert ret_eg.enrollment_group_id == GROUP_ID assert ret_eg.initial_twin.tags == TAGS assert ret_eg.initial_twin.desired_properties == DESIRED_PROPERTIES #get ret_eg = psc.get_enrollment_group(GROUP_ID) assert ret_eg.enrollment_group_id == GROUP_ID assert ret_eg.initial_twin.tags == TAGS assert ret_eg.initial_twin.desired_properties == DESIRED_PROPERTIES #query qs = QuerySpecification("*") q = psc.create_enrollment_group_query(qs) q_results = q.next() assert len(q_results) == 1 #delete psc.delete(ret_eg) try: ret_eg = psc.get_enrollment_group(GROUP_ID) except ProvisioningServiceError: pass else: raise AssertionError
def setUp(self): tags_tc = genmodels.TwinCollection(TEST_TAGS) desired_properties_tc = genmodels.TwinCollection(TEST_PROPERTIES) properties = genmodels.InitialTwinProperties(desired_properties_tc) gen_twin = genmodels.InitialTwin(tags_tc, properties) self.twin = InitialTwin(gen_twin)
def test_ts_create_empty(self): res = InitialTwin.create() self.assertIsNone(res._internal.tags.additional_properties) self.assertIsNone( res._internal.properties.desired.additional_properties)
def test_ts_create_full(self): res = InitialTwin.create(TEST_TAGS, TEST_PROPERTIES) self.assertIs(res._internal.tags.additional_properties, TEST_TAGS) self.assertIs(res._internal.properties.desired.additional_properties, TEST_PROPERTIES)
def test_eg_set_initial_twin(self): ts = InitialTwin.create() self.eg.initial_twin = ts self.assertIs(self.eg._internal.initial_twin, ts._internal) self.assertIs(self.eg._twin_wrapper, ts)