def test_4_create_service_key(self, test_space): step("Check that the instance exists in summary and has no keys") summary = ServiceInstance.api_get_keys(test_space.guid, client=self.client) assert self.instance in summary, "Instance not found in summary" assert summary[self.instance] == [], "There are keys for the instance" step("Create a key for the scoring engine instance and check it") self.__class__.instance_key = ServiceKey.api_create(self.instance.guid, client=self.client) summary = ServiceInstance.api_get_keys(test_space.guid) assert self.instance_key in summary[self.instance], "Key not found"
def _create_and_delete_service_instance_and_keys(self, org_guid, space_guid, service_label, plan_guid): self.step("Create service instance") instance = ServiceInstance.api_create(org_guid=org_guid, space_guid=space_guid, service_label=service_label, service_plan_guid=plan_guid) self.step("Check that the instance was created") instance.ensure_created() service_key_exception = None try: self.step( "Check that the instance exists in summary and has no service keys" ) self.assertEqualWithinTimeout(timeout=5, expected_result=[], callable_obj=self._get_service_keys, sleep=1, instance=instance) self.step( "Create a key for the instance and check it's correctness") instance_key = ServiceKey.api_create(instance.guid) summary = ServiceInstance.api_get_keys(space_guid) self.assertEqual(summary[instance][0], instance_key) self.step("Delete key and check that it's deleted") instance_key.api_delete() summary = ServiceInstance.api_get_keys(space_guid) self.assertEqual(summary[instance], []) except AssertionError as e: service_key_exception = e try: self.step("Delete the instance") instance.api_delete() self.step("Check that the instance was deleted") instances = ServiceInstance.api_get_list(space_guid=space_guid) self.assertNotIn(instance, instances) except AssertionError as e: if service_key_exception is not None: raise service_key_exception raise e if service_key_exception is not None: raise service_key_exception
def create_instance_and_key_then_delete_key_and_instance( org_guid, space_guid, service_label, plan_guid, plan_name): step("Create instance ({} - {})".format(service_label, plan_name)) instance = ServiceInstance.api_create(org_guid=org_guid, space_guid=space_guid, service_label=service_label, service_plan_guid=plan_guid) step("Check that the instance was created ({} - {})".format( service_label, plan_name)) instance.ensure_created() service_key_exception = None try: step( "Check that the instance exists in summary and has no keys ({} - {})" .format(service_label, plan_name)) assertions.assert_equal_with_retry(expected_value=[], callableObj=get_service_keys, instance=instance) step("Create a key for the instance and check it's correct ({} - {})". format(service_label, plan_name)) instance_key = ServiceKey.api_create(instance.guid) summary = ServiceInstance.api_get_keys(space_guid) assert summary[instance][0] == instance_key step("Delete key and check that it's deleted ({} - {})".format( service_label, plan_name)) instance_key.api_delete() summary = ServiceInstance.api_get_keys(space_guid) assert summary[instance] == [] except AssertionError as e: service_key_exception = e try: step("Delete the instance ({} - {})".format(service_label, plan_name)) instance.api_delete() step("Check that the instance was deleted ({} - {})".format( service_label, plan_name)) instances = ServiceInstance.api_get_list(space_guid=space_guid) assert instance not in instances except AssertionError as e: if service_key_exception is None: service_key_exception = e if service_key_exception is not None: raise service_key_exception
def test_get_service_instance_summary_from_empty_space(self): self.step("Create a service instance in one space") service_type = next(s for s in self.marketplace if s.label == ServiceLabels.KAFKA) ServiceInstance.api_create( org_guid=TestData.test_org.guid, space_guid=TestData.test_space.guid, service_label=service_type.label, service_plan_guid=service_type.service_plan_guids[0]) test_space = Space.api_create(TestData.test_org) self.step("Get service instance summary in another space") summary = ServiceInstance.api_get_keys(test_space.guid) self.step( "Check that service instance summary is empty in the second space") self.assertEqual(summary, {})
def get_service_keys(instance): summary = ServiceInstance.api_get_keys(instance.space_guid) assert instance in summary return summary[instance]
def test_5_delete_service_key(self, test_space): step("Delete service key") self.instance_key.api_delete(client=self.client) step("Check the key is no longer in summary") summary = ServiceInstance.api_get_keys(test_space.guid, client=self.client) assert summary[self.instance] == [], "There are keys for the instance"
def _get_service_keys(self, instance): summary = ServiceInstance.api_get_keys(instance.space_guid) self.assertIn(instance, summary) return summary[instance]