def test_resources_get_paging_prev_option_start_in_middle(self): """Covers getting a list of resources and using the next reference.""" number_of_resources = 150 test_model = self.create_model() filter = self._set_filter_field(test_model) self.create_resources(count=number_of_resources, model=test_model) # First set of resources limit = number_of_resources // 10 offset = number_of_resources // 2 resp, resources, next_ref, prev_ref = self.get_resources( limit=limit, offset=offset, filter=filter) self.assertEqual(200, resp.status_code) self._validate_resource_group(resources=resources, next_ref=next_ref, prev_ref=prev_ref, expected_size=limit, next_ref_should_be_none=False, prev_ref_should_be_none=False) limit, offset = utils.get_limit_and_offset_from_ref(prev_ref) # Previous set of resources resp, resources, next_ref, prev_ref = self.get_resources( limit=limit, offset=offset, filter=filter) self._validate_resource_group(resources=resources, next_ref=next_ref, prev_ref=prev_ref, expected_size=int(limit), next_ref_should_be_none=False, prev_ref_should_be_none=False)
def delete_all_secrets_for_user(self, user_name): '''Delete all of the secrets for the specified user''' response, secrets, next_ref, prev_ref = self.get_secrets( user_name=user_name) secret_refs_to_delete = [] while len(secrets) > 0: for secret in secrets: secret_refs_to_delete.append(secret.secret_ref) if next_ref: limit, offset = utils.get_limit_and_offset_from_ref(next_ref) response, secrets, next_ref, prev = self.get_secrets( limit=limit, offset=offset, user_name=user_name) else: break for secret_ref in secret_refs_to_delete: self.delete_secret(secret_ref=secret_ref, user_name=user_name)
def delete_all_containers_for_user(self, user_name): '''Delete all of the containers for the specified user''' response, containers, next_ref, prev_ref = self.get_containers( user_name=user_name) container_refs_to_delete = [] while len(containers) > 0: for container in containers: container_refs_to_delete.append(container.container_ref) if next_ref: limit, offset = utils.get_limit_and_offset_from_ref(next_ref) response, containers, next_ref, prev = self.get_containers( limit=limit, offset=offset, user_name=user_name) else: break for container_ref in container_refs_to_delete: self.delete_container(container_ref=container_ref, user_name=user_name)
def test_paging_exceeding_paging_max_limit(self): """Covers case of listing resources with a limit that exceeds max. Create a number of resources over the max paging limit, then try to get them all in one call. It should only return the max, with a next link to get the rest. """ max_allowable_limit = 100 number_of_resources = max_allowable_limit + 10 test_model = self.create_model() filter = self._set_filter_field(test_model) self.create_resources(count=number_of_resources, model=test_model) resp, resources, next_ref, prev_ref = self.get_resources(limit=number_of_resources, offset=0, filter=filter) self.assertEqual(200, resp.status_code) self._validate_resource_group( resources=resources, next_ref=next_ref, prev_ref=prev_ref, expected_size=max_allowable_limit, next_ref_should_be_none=False, prev_ref_should_be_none=True, ) limit, offset = utils.get_limit_and_offset_from_ref(next_ref) # new offset and limit should both be the same as the max limit self.assertEqual(str(max_allowable_limit), limit) self.assertEqual(str(max_allowable_limit), offset) # now get the rest resp, resources, next_ref, prev_ref = self.get_resources(limit=limit, offset=offset, filter=filter) self.assertEqual(200, resp.status_code) expected_size = number_of_resources - max_allowable_limit self._validate_resource_group( resources=resources, next_ref=next_ref, prev_ref=prev_ref, expected_size=expected_size, next_ref_should_be_none=True, prev_ref_should_be_none=False, )
def test_paging_exceeding_paging_max_limit(self): """Covers case of listing resources with a limit that exceeds max. Create a number of resources over the max paging limit, then try to get them all in one call. It should only return the max, with a next link to get the rest. """ max_allowable_limit = 100 number_of_resources = max_allowable_limit + 10 test_model = self.create_model() filter = self._set_filter_field(test_model) self.create_resources(count=number_of_resources, model=test_model) resp, resources, next_ref, prev_ref = self.get_resources( limit=number_of_resources, offset=0, filter=filter) self.assertEqual(200, resp.status_code) self._validate_resource_group(resources=resources, next_ref=next_ref, prev_ref=prev_ref, expected_size=max_allowable_limit, next_ref_should_be_none=False, prev_ref_should_be_none=True) limit, offset = utils.get_limit_and_offset_from_ref(next_ref) # new offset and limit should both be the same as the max limit self.assertEqual(str(max_allowable_limit), limit) self.assertEqual(str(max_allowable_limit), offset) # now get the rest resp, resources, next_ref, prev_ref = self.get_resources(limit=limit, offset=offset, filter=filter) self.assertEqual(200, resp.status_code) expected_size = number_of_resources - max_allowable_limit self._validate_resource_group(resources=resources, next_ref=next_ref, prev_ref=prev_ref, expected_size=expected_size, next_ref_should_be_none=True, prev_ref_should_be_none=False)