diff --git a/CHANGELOG.md b/CHANGELOG.md index 94f4bc0..2faa20b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,3 +22,4 @@ * Added server errors handling * Added workload description and external link to docs * 0.3.2: Backend dependencies are bumped +* 0.3.3: Removed limit of returned DB objects in DB List API diff --git a/Dockerfile b/Dockerfile index 20f024d..1300040 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM cloudblueconnect/connect-extension-runner:27.19 +FROM cloudblueconnect/connect-extension-runner:27.21 COPY pyproject.toml /install_temp/. COPY poetry.* /install_temp/. diff --git a/dbaas/extension.json b/dbaas/extension.json index 3e84016..8cedeb5 100644 --- a/dbaas/extension.json +++ b/dbaas/extension.json @@ -1,9 +1,9 @@ { "name": "DBaaS", "description": "On-demand provisioning of cloud-based database storages as a service.", - "version": "0.3.2", + "version": "0.3.3", "audience": ["reseller", "distributor", "vendor"], - "readme_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.2/README.md", - "changelog_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.2/CHANGELOG.md", + "readme_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.3/README.md", + "changelog_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.3/CHANGELOG.md", "icon": "googleExtensionBaseline" } diff --git a/dbaas/services.py b/dbaas/services.py index 9e40747..aa62566 100644 --- a/dbaas/services.py +++ b/dbaas/services.py @@ -34,6 +34,7 @@ class DB: COLLECTION = Collections.DB MAX_ID_GENERATION_RETRIES = 3 + LIST_STEP_LENGTH = 20 @classmethod async def list(cls, db: AsyncIOMotorDatabase, context: Context) -> list[dict]: @@ -43,9 +44,14 @@ async def list(cls, db: AsyncIOMotorDatabase, context: Context) -> list[dict]: ).sort('events.created.at', pymongo.DESCENDING) results = [] - for db_document in await cursor.to_list(length=20): - doc = cls._db_document_repr(db_document) - results.append(doc) + + docs = await cursor.to_list(length=cls.LIST_STEP_LENGTH) + while docs: + for db_document in docs: + doc = cls._db_document_repr(db_document) + results.append(doc) + + docs = await cursor.to_list(length=cls.LIST_STEP_LENGTH) return results diff --git a/poetry.lock b/poetry.lock index f678dae..9151569 100644 --- a/poetry.lock +++ b/poetry.lock @@ -68,22 +68,22 @@ tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] [[package]] name = "attrs" -version = "22.2.0" +version = "23.1.0" description = "Classes Without Boilerplate" category = "dev" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "attrs-22.2.0-py3-none-any.whl", hash = "sha256:29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836"}, - {file = "attrs-22.2.0.tar.gz", hash = "sha256:c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99"}, + {file = "attrs-23.1.0-py3-none-any.whl", hash = "sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04"}, + {file = "attrs-23.1.0.tar.gz", hash = "sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015"}, ] [package.extras] -cov = ["attrs[tests]", "coverage-enable-subprocess", "coverage[toml] (>=5.3)"] -dev = ["attrs[docs,tests]"] -docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope.interface"] -tests = ["attrs[tests-no-zope]", "zope.interface"] -tests-no-zope = ["cloudpickle", "cloudpickle", "hypothesis", "hypothesis", "mypy (>=0.971,<0.990)", "mypy (>=0.971,<0.990)", "pympler", "pympler", "pytest (>=4.3.0)", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-mypy-plugins", "pytest-xdist[psutil]", "pytest-xdist[psutil]"] +cov = ["attrs[tests]", "coverage[toml] (>=5.3)"] +dev = ["attrs[docs,tests]", "pre-commit"] +docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope-interface"] +tests = ["attrs[tests-no-zope]", "zope-interface"] +tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] [[package]] name = "certifi" @@ -302,14 +302,14 @@ test = ["flake8 (==3.7.8)", "hypothesis (==3.55.3)"] [[package]] name = "connect-eaas-core" -version = "27.13" +version = "27.14" description = "Connect Eaas Core" category = "main" optional = false python-versions = ">=3.8,<4" files = [ - {file = "connect_eaas_core-27.13-py3-none-any.whl", hash = "sha256:c41368e01bb32415c716b0b5977280292fc50ebac4c425264a22360d6dc6ef2d"}, - {file = "connect_eaas_core-27.13.tar.gz", hash = "sha256:7cfe1553fc99718998652b41af34d6c000c4fda89d5f2bf86bf1c280f0ce14da"}, + {file = "connect_eaas_core-27.14-py3-none-any.whl", hash = "sha256:cd8cd60001c08d9aaae8ab4309fc123d1e0a50d80aace8ba3ec432d5fc043dd3"}, + {file = "connect_eaas_core-27.14.tar.gz", hash = "sha256:83af0497064f7b5a244564313ac6b182af1ffc40871a0493f590a785319c3bd1"}, ] [package.dependencies] @@ -1283,14 +1283,14 @@ zstd = ["zstandard"] [[package]] name = "pytest" -version = "7.3.0" +version = "7.3.1" description = "pytest: simple powerful testing with Python" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "pytest-7.3.0-py3-none-any.whl", hash = "sha256:933051fa1bfbd38a21e73c3960cebdad4cf59483ddba7696c48509727e17f201"}, - {file = "pytest-7.3.0.tar.gz", hash = "sha256:58ecc27ebf0ea643ebfdf7fb1249335da761a00c9f955bcd922349bcb68ee57d"}, + {file = "pytest-7.3.1-py3-none-any.whl", hash = "sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362"}, + {file = "pytest-7.3.1.tar.gz", hash = "sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3"}, ] [package.dependencies] diff --git a/tests/services/test_db.py b/tests/services/test_db.py index d23fd32..9b0a47f 100644 --- a/tests/services/test_db.py +++ b/tests/services/test_db.py @@ -101,6 +101,18 @@ async def test_list_several_account_dbs(db, admin_context): assert [r['id'] for r in results] == [db['id'] for db in (db3, db2, other_account_db, db1)] +@pytest.mark.asyncio +async def test_list_number_of_dbs_gt_than_cursor_length(db): + account_id = 'PA-456' + + dbs = DBFactory.create_batch(size=25, account_id=account_id) + await db[Collections.DB].insert_many(dbs) + + results = await DB.list(db, Context(account_id=account_id)) + assert len(results) == 25 + assert len({r['id'] for r in results}) == 25 + + @pytest.mark.asyncio async def test_retrieve_is_empty(db): result = await DB.retrieve('any', db, Context(account_id='VA-123-456'))