|
1 | 1 | # Copyright (c) 2021-2023, Crate.io Inc.
|
2 | 2 | # Distributed under the terms of the AGPLv3 license, see LICENSE.
|
| 3 | +import json |
| 4 | + |
3 | 5 | import pytest
|
4 | 6 | import responses
|
5 | 7 |
|
@@ -86,38 +88,106 @@ def cratedb(cratedb_service):
|
86 | 88 |
|
87 | 89 |
|
88 | 90 | @pytest.fixture
|
89 |
| -def cloud_cluster_mock(): |
| 91 | +def mock_cloud_cluster_exists(cratedb): |
| 92 | + """ |
| 93 | + Mock a CrateDB Cloud API conversation, pretending a cluster exists. |
| 94 | + """ |
| 95 | + responses.add_passthru("http+docker://localhost/") |
90 | 96 | responses.add(
|
91 |
| - responses.Response( |
92 |
| - method="GET", |
93 |
| - url="https://console.cratedb.cloud/api/v2/clusters/e1e38d92-a650-48f1-8a70-8133f2d5c400/", |
94 |
| - json={ |
95 |
| - "url": "https://testdrive.example.org:4200/", |
| 97 | + method="GET", |
| 98 | + url="https://console.cratedb.cloud/api/v2/clusters/", |
| 99 | + json=[ |
| 100 | + { |
| 101 | + "id": "e1e38d92-a650-48f1-8a70-8133f2d5c400", |
| 102 | + "url": cratedb.get_connection_url(), |
96 | 103 | "project_id": "3b6b7c82-d0ab-458c-ae6f-88f8346765ee",
|
97 | 104 | "name": "testcluster",
|
98 |
| - }, |
99 |
| - ) |
| 105 | + } |
| 106 | + ], |
100 | 107 | )
|
| 108 | + |
| 109 | + |
| 110 | +@pytest.fixture |
| 111 | +def mock_cloud_cluster_deploy(cratedb): |
| 112 | + """ |
| 113 | + Mock a CrateDB Cloud API conversation, for exercising a full deployment process. |
| 114 | + """ |
| 115 | + responses.add_passthru("http+docker://localhost/") |
| 116 | + |
| 117 | + callcount = 0 |
| 118 | + |
| 119 | + def cluster_list_callback(request): |
| 120 | + nonlocal callcount |
| 121 | + callcount += 1 |
| 122 | + headers = {} |
| 123 | + if callcount == 1: |
| 124 | + data = [] |
| 125 | + else: |
| 126 | + data = [ |
| 127 | + { |
| 128 | + "id": "e1e38d92-a650-48f1-8a70-8133f2d5c400", |
| 129 | + "url": cratedb.get_connection_url(), |
| 130 | + "project_id": "3b6b7c82-d0ab-458c-ae6f-88f8346765ee", |
| 131 | + "name": "testcluster", |
| 132 | + } |
| 133 | + ] |
| 134 | + return 200, headers, json.dumps(data) |
| 135 | + |
| 136 | + responses.add_callback( |
| 137 | + method="GET", |
| 138 | + url="https://console.cratedb.cloud/api/v2/clusters/", |
| 139 | + callback=cluster_list_callback, |
| 140 | + ) |
| 141 | + |
101 | 142 | responses.add(
|
102 |
| - responses.Response( |
103 |
| - method="POST", |
104 |
| - url="https://console.cratedb.cloud/api/v2/clusters/e1e38d92-a650-48f1-8a70-8133f2d5c400/import-jobs/", |
105 |
| - json={"id": "testdrive-job-id", "status": "REGISTERED"}, |
106 |
| - ) |
| 143 | + method="GET", |
| 144 | + url="https://console.cratedb.cloud/api/v2/projects/", |
| 145 | + json=[], |
107 | 146 | )
|
| 147 | + |
108 | 148 | responses.add(
|
109 |
| - responses.Response( |
110 |
| - method="GET", |
111 |
| - url="https://console.cratedb.cloud/api/v2/clusters/e1e38d92-a650-48f1-8a70-8133f2d5c400/import-jobs/", |
112 |
| - json=[ |
113 |
| - { |
114 |
| - "id": "testdrive-job-id", |
115 |
| - "status": "SUCCEEDED", |
116 |
| - "progress": {"message": "Import succeeded"}, |
117 |
| - "destination": {"table": "basic"}, |
118 |
| - } |
119 |
| - ], |
120 |
| - ) |
| 149 | + method="POST", |
| 150 | + url="https://console.cratedb.cloud/api/v2/projects/", |
| 151 | + json={"id": "3b6b7c82-d0ab-458c-ae6f-88f8346765ee"}, |
| 152 | + ) |
| 153 | + |
| 154 | + responses.add( |
| 155 | + method="GET", |
| 156 | + url="https://console.cratedb.cloud/api/v2/projects/3b6b7c82-d0ab-458c-ae6f-88f8346765ee/", |
| 157 | + json={}, |
| 158 | + ) |
| 159 | + |
| 160 | + |
| 161 | +@pytest.fixture |
| 162 | +def mock_cloud_import(): |
| 163 | + """ |
| 164 | + Mock a CrateDB Cloud API conversation, pretending to run a successful data import. |
| 165 | + """ |
| 166 | + responses.add( |
| 167 | + method="GET", |
| 168 | + url="https://console.cratedb.cloud/api/v2/clusters/e1e38d92-a650-48f1-8a70-8133f2d5c400/", |
| 169 | + json={ |
| 170 | + "url": "https://testdrive.example.org:4200/", |
| 171 | + "project_id": "3b6b7c82-d0ab-458c-ae6f-88f8346765ee", |
| 172 | + "name": "testcluster", |
| 173 | + }, |
| 174 | + ) |
| 175 | + responses.add( |
| 176 | + method="POST", |
| 177 | + url="https://console.cratedb.cloud/api/v2/clusters/e1e38d92-a650-48f1-8a70-8133f2d5c400/import-jobs/", |
| 178 | + json={"id": "testdrive-job-id", "status": "REGISTERED"}, |
| 179 | + ) |
| 180 | + responses.add( |
| 181 | + method="GET", |
| 182 | + url="https://console.cratedb.cloud/api/v2/clusters/e1e38d92-a650-48f1-8a70-8133f2d5c400/import-jobs/", |
| 183 | + json=[ |
| 184 | + { |
| 185 | + "id": "testdrive-job-id", |
| 186 | + "status": "SUCCEEDED", |
| 187 | + "progress": {"message": "Import succeeded"}, |
| 188 | + "destination": {"table": "basic"}, |
| 189 | + } |
| 190 | + ], |
121 | 191 | )
|
122 | 192 |
|
123 | 193 |
|
|
0 commit comments