def test_reordered_cs_args(self): cs = "SharedAccessKey=dGVzdGluZyBhIHNhc3Rva2Vu;HostName=test-uri.azure-devices-provisioning.net;SharedAccessKeyName=provisioningserviceowner" psc = ProvisioningServiceClient.create_from_connection_string(cs) self.assertEqual(psc.host_name, "test-uri.azure-devices-provisioning.net") self.assertEqual(psc.shared_access_key_name, "provisioningserviceowner") self.assertEqual(psc.shared_access_key, "dGVzdGluZyBhIHNhc3Rva2Vu")
def test_create_w_params(self): psc = ProvisioningServiceClient("test-uri.azure-devices-provisioning.net", \ "provisioningserviceowner", "dGVzdGluZyBhIHNhc3Rva2Vu") self.assertEqual(psc.host_name, "test-uri.azure-devices-provisioning.net") self.assertEqual(psc.shared_access_key_name, "provisioningserviceowner") self.assertEqual(psc.shared_access_key, "dGVzdGluZyBhIHNhc3Rva2Vu")
def test_basic_cs(self): cs = "HostName=test-uri.azure-devices-provisioning.net;SharedAccessKeyName=provisioningserviceowner;SharedAccessKey=dGVzdGluZyBhIHNhc3Rva2Vu" psc = ProvisioningServiceClient.create_from_connection_string(cs) self.assertEqual(psc.host_name, "test-uri.azure-devices-provisioning.net") self.assertEqual(psc.shared_access_key_name, "provisioningserviceowner") self.assertEqual(psc.shared_access_key, "dGVzdGluZyBhIHNhc3Rva2Vu") self.assertIsInstance(psc._runtime_client, GeneratedProvisioningServiceClient)
def test_fail_missing_cs_args(self): #HostName is missing cs = "SharedAccessKeyName=provisioningserviceowner;SharedAccessKey=dGVzdGluZyBhIHNhc3Rva2Vu" with self.assertRaises(ValueError): psc = ProvisioningServiceClient.create_from_connection_string(cs)
def test_fail_too_many_cs_args(self): #ExtraVal additional cs val cs = "ExtraVal=testingValue;HostName=test-uri.azure-devices-provisioning.net;SharedAccessKeyName=provisioningserviceowner;SharedAccessKey=dGVzdGluZyBhIHNhc3Rva2Vu" with self.assertRaises(ValueError): psc = ProvisioningServiceClient.create_from_connection_string(cs)
def setUpClass(cls): cs = "HostName=test-uri.azure-devices-provisioning.net;SharedAccessKeyName=provisioningserviceowner;SharedAccessKey=dGVzdGluZyBhIHNhc3Rva2Vu" cls.psc = ProvisioningServiceClient.create_from_connection_string(cs)
def test_fail_invalid_cs(self): cs = "not_a_connection_string" with self.assertRaises(ValueError): psc = ProvisioningServiceClient.create_from_connection_string(cs)
def test_fail_duplicate_cs_args(self): #SharedAccessKeyName defined twice cs = "SharedAccessKeyName=provisioningserviceowner;SharedAccessKey=dGVzdGluZyBhIHNhc3Rva2Vu;SharedAccessKeyName=duplicatevalue" with self.assertRaises(UnboundLocalError): psc = ProvisioningServiceClient.create_from_connection_string(cs)
def test_fail_replaced_cs_args(self): #ExtraVal replaces HostName in cs cs = "ExtraVal=testingValue;SharedAccessKeyName=provisioningserviceowner;SharedAccessKey=dGVzdGluZyBhIHNhc3Rva2Vu" with self.assertRaises(ValueError): psc = ProvisioningServiceClient.create_from_connection_string(cs)