Skip to content

Commit 721288c

Browse files
committed
add test and minor updates
1 parent 7975682 commit 721288c

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
=======
44

5-
# 1.7.4 (2022-07-08)
5+
# 1.7.4 (2022-07-13)
66
- validates source id for correct syntax when `upload-source` command to resolve `Connection reset by peer error`
77

88
# 1.7.3 (2022-03-14)

tests/test_cli_sources.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,40 @@ def side_effect(fields):
190190
)
191191

192192

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+
193227
@pytest.mark.usefixtures("token_environ")
194228
def validate_source_id(self):
195229
self.assertRaises(

0 commit comments

Comments
 (0)