|
|
@@ -23,6 +23,7 @@ class PaginationTest(base.CoriolisIntegrationTestBase):
|
|
|
|
|
|
TRANSFER_COUNT = 5
|
|
|
EXECUTIONS_PER_TRANSFER = 5
|
|
|
+ DEPLOYMENTS_PER_TRANSFER = 5
|
|
|
|
|
|
@classmethod
|
|
|
def setUpClass(cls):
|
|
|
@@ -84,6 +85,23 @@ class PaginationTest(base.CoriolisIntegrationTestBase):
|
|
|
db_api.add_endpoint(cls._admin_ctx, endpoint)
|
|
|
return endpoint
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def _create_deployment(
|
|
|
+ cls,
|
|
|
+ transfer_id,
|
|
|
+ origin_endpoint_id: str,
|
|
|
+ destination_endpoint_id: str,
|
|
|
+ **kwargs,
|
|
|
+ ) -> models.Deployment:
|
|
|
+ kwargs["id"] = kwargs.get("id", str(uuid.uuid4()))
|
|
|
+ kwargs["transfer_id"] = transfer_id
|
|
|
+ kwargs["origin_endpoint_id"] = origin_endpoint_id
|
|
|
+ kwargs["destination_endpoint_id"] = destination_endpoint_id
|
|
|
+ deployment = models.Deployment(
|
|
|
+ **kwargs)
|
|
|
+ db_api.add_deployment(cls._admin_ctx, deployment)
|
|
|
+ return deployment
|
|
|
+
|
|
|
@classmethod
|
|
|
def _setup_mocks(cls):
|
|
|
cls._src_endpoint = cls._create_endpoint()
|
|
|
@@ -91,6 +109,8 @@ class PaginationTest(base.CoriolisIntegrationTestBase):
|
|
|
|
|
|
cls._transfers = []
|
|
|
cls._executions = {}
|
|
|
+ cls._deployments = {}
|
|
|
+ cls._all_deployments = []
|
|
|
for transfer_idx in range(cls.TRANSFER_COUNT):
|
|
|
# For testing purposes, we'll set the "created_at" field
|
|
|
# explicitly, adding a small time delta between records.
|
|
|
@@ -109,6 +129,17 @@ class PaginationTest(base.CoriolisIntegrationTestBase):
|
|
|
seconds=execution_idx))
|
|
|
cls._executions[transfer.id].append(execution)
|
|
|
|
|
|
+ cls._deployments[transfer.id] = []
|
|
|
+ for deployment_idx in range(cls.DEPLOYMENTS_PER_TRANSFER):
|
|
|
+ deployment = cls._create_deployment(
|
|
|
+ transfer_id=transfer.id,
|
|
|
+ origin_endpoint_id=cls._src_endpoint.id,
|
|
|
+ destination_endpoint_id=cls._dst_endpoint.id,
|
|
|
+ created_at=timeutils.utcnow() + datetime.timedelta(
|
|
|
+ seconds=deployment_idx))
|
|
|
+ cls._deployments[transfer.id].append(deployment)
|
|
|
+ cls._all_deployments.append(deployment)
|
|
|
+
|
|
|
@staticmethod
|
|
|
def _get_record_summary(record):
|
|
|
# Extract a few fields from the db records and entries returned by
|
|
|
@@ -170,4 +201,41 @@ class PaginationTest(base.CoriolisIntegrationTestBase):
|
|
|
|
|
|
exp_sorted_exec_summary = [
|
|
|
self._get_record_summary(e) for e in sorted_exp_exec][2:4]
|
|
|
- self.assertEqual(exp_sorted_exec_summary, ret_exec_summary)
|
|
|
+ self.assertEqual(exp_sorted_exec_summary, ret_exec_summary)
|
|
|
+
|
|
|
+ def test_deployment_list(self):
|
|
|
+ deployments = self._client.deployments.list()
|
|
|
+ ret_depl_summary = [self._get_record_summary(d) for d in deployments]
|
|
|
+
|
|
|
+ exp_sorted_depl_summary = [
|
|
|
+ self._get_record_summary(d) for d in self._all_deployments]
|
|
|
+ exp_sorted_depl_summary = sorted(
|
|
|
+ exp_sorted_depl_summary,
|
|
|
+ key=lambda x: (x["created_at"], x["id"]),
|
|
|
+ reverse=True)
|
|
|
+ self.assertEqual(exp_sorted_depl_summary, ret_depl_summary)
|
|
|
+
|
|
|
+ def test_deployment_list_pagination(self):
|
|
|
+ # Get the first 2 entries, sorted by ID in ascending order.
|
|
|
+ deployments = self._client.deployments.list(
|
|
|
+ limit=2,
|
|
|
+ sort_keys=['id'],
|
|
|
+ sort_dirs=['asc'])
|
|
|
+ ret_depl_summary = [self._get_record_summary(d) for d in deployments]
|
|
|
+
|
|
|
+ exp_sorted_depl_summary = [
|
|
|
+ self._get_record_summary(d) for d in self._all_deployments]
|
|
|
+ exp_sorted_depl_summary = sorted(
|
|
|
+ exp_sorted_depl_summary,
|
|
|
+ key=lambda x: x["id"])
|
|
|
+ self.assertEqual(exp_sorted_depl_summary[:2], ret_depl_summary)
|
|
|
+
|
|
|
+ # Get the next 2 entries.
|
|
|
+ deployments = self._client.deployments.list(
|
|
|
+ limit=2,
|
|
|
+ sort_keys=['id'],
|
|
|
+ sort_dirs=['asc'],
|
|
|
+ marker=ret_depl_summary[-1]["id"],
|
|
|
+ )
|
|
|
+ ret_depl_summary = [self._get_record_summary(d) for d in deployments]
|
|
|
+ self.assertEqual(exp_sorted_depl_summary[2:4], ret_depl_summary)
|