|
1 | 1 | from click.testing import CliRunner |
2 | 2 | import json |
3 | 3 | import os |
| 4 | +import click |
4 | 5 | from unittest import mock |
5 | 6 |
|
6 | 7 | import pytest |
@@ -42,10 +43,9 @@ def side_effect(fields): |
42 | 43 | add_source, ["test-user", "hello-world", "tests/fixtures/valid.ldgeojson"] |
43 | 44 | ) |
44 | 45 | assert validated_result.exit_code == 0 |
45 | | - |
46 | 46 | assert ( |
47 | 47 | validated_result.output |
48 | | - == """{"id": "mapbox://tileset-source/test-user/hello-world"}\n""" |
| 48 | + == """upload progress\n{"id": "mapbox://tileset-source/test-user/hello-world"}\n""" |
49 | 49 | ) |
50 | 50 |
|
51 | 51 |
|
@@ -149,10 +149,9 @@ def side_effect(fields): |
149 | 149 | ["test-user", "hello-world", "tests/fixtures/valid.ldgeojson", "--replace"], |
150 | 150 | ) |
151 | 151 | assert validated_result.exit_code == 0 |
152 | | - |
153 | 152 | assert ( |
154 | 153 | validated_result.output |
155 | | - == """{"id": "mapbox://tileset-source/test-user/hello-world"}\n""" |
| 154 | + == """upload progress\n{"id": "mapbox://tileset-source/test-user/hello-world"}\n""" |
156 | 155 | ) |
157 | 156 |
|
158 | 157 |
|
@@ -187,8 +186,53 @@ def side_effect(fields): |
187 | 186 |
|
188 | 187 | assert ( |
189 | 188 | validated_result.output |
190 | | - == """{"id": "mapbox://tileset-source/test-user/hello-world"}\n""" |
| 189 | + == """upload progress\n{"id": "mapbox://tileset-source/test-user/hello-world"}\n""" |
| 190 | + ) |
| 191 | + |
| 192 | + |
| 193 | +@pytest.mark.usefixtures("token_environ") |
| 194 | +@mock.patch("mapbox_tilesets.scripts.cli.MultipartEncoder") |
| 195 | +@mock.patch("mapbox_tilesets.scripts.cli.MultipartEncoderMonitor") |
| 196 | +@mock.patch("requests.Session.post") |
| 197 | +def test_cli_upload_source( |
| 198 | + mock_request_post, |
| 199 | + mock_multipart_encoder_monitor, |
| 200 | + mock_multipart_encoder, |
| 201 | + MockResponse, |
| 202 | + MockMultipartEncoding, |
| 203 | +): |
| 204 | + okay_response = {"id": "mapbox://tileset-source/test-user/populated-places-source"} |
| 205 | + mock_request_post.return_value = MockResponse(okay_response, status_code=200) |
| 206 | + |
| 207 | + expected_json = b'{"type":"Feature","geometry":{"type":"Point","coordinates":[125.6,10.1]},"properties":{"name":"Dinagat Islands"}}\n' |
| 208 | + |
| 209 | + def side_effect(fields): |
| 210 | + assert fields["file"][1].read() == expected_json |
| 211 | + return MockMultipartEncoding() |
| 212 | + |
| 213 | + mock_multipart_encoder.side_effect = side_effect |
| 214 | + |
| 215 | + runner = CliRunner() |
| 216 | + validated_result = runner.invoke( |
| 217 | + upload_source, |
| 218 | + ["test-user", "populated-places-source", "tests/fixtures/valid.ldgeojson"], |
| 219 | + ) |
| 220 | + assert validated_result.exit_code == 0 |
| 221 | + assert ( |
| 222 | + validated_result.output |
| 223 | + == """upload progress\n{"id": "mapbox://tileset-source/test-user/populated-places-source"}\n""" |
| 224 | + ) |
| 225 | + |
| 226 | + |
| 227 | +@pytest.mark.usefixtures("token_environ") |
| 228 | +def validate_source_id(self): |
| 229 | + self.assertRaises( |
| 230 | + click.BadParameter, |
| 231 | + value="mapbox://tileset-source/test-user/hello-world", |
| 232 | + param=None, |
| 233 | + ctx=None, |
191 | 234 | ) |
| 235 | + self.assertEqual("hello-world", value="hello-world", param=None, ctx=None) |
192 | 236 |
|
193 | 237 |
|
194 | 238 | @pytest.mark.usefixtures("token_environ") |
|
0 commit comments