Skip to content

Commit 90074cd

Browse files
committed
LITE-28260 Fix errors
1 parent d26a544 commit 90074cd

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

connect/cli/plugins/commerce/utils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def export_stream(
280280
data={
281281
'Stream ID': stream_id,
282282
'Stream Name': response['name'],
283-
'Stream Description': response['description'],
283+
'Stream Description': response.get('description'),
284284
'Stream Type': stream_type,
285285
'Stream Category': 'Inbound'
286286
if response['owner']['id'] != active_account_id
@@ -883,9 +883,17 @@ def update_general_information(
883883
'context',
884884
'samples',
885885
'sources',
886+
'validation',
886887
)
887888
.first()
888889
)
890+
891+
if stream['status'] == 'active' or stream.get('validation', {}).get('status') == 'processing':
892+
raise ClickException(
893+
f'Stream {stream_id} cannot be updated because it is in "active" status '
894+
f'or validation is processing.',
895+
)
896+
889897
body = {'context': {}}
890898
updated = 0
891899
errors_on_update = 0
@@ -894,7 +902,7 @@ def update_general_information(
894902
if h.value == 'Stream Name' and stream['name'] != v.value:
895903
body['name'] = v.value
896904
updated += 1
897-
elif h.value == 'Stream Description' and stream['description'] != v.value:
905+
elif h.value == 'Stream Description' and stream.get('description') != v.value:
898906
body['description'] = v.value
899907
updated += 1
900908
elif (
@@ -963,9 +971,7 @@ def update_transformations(
963971
to_update = {}
964972
if origin_trf['settings'] != json.loads(settings.value):
965973
to_update['settings'] = json.loads(settings.value)
966-
if descr.value and (
967-
'description' not in origin_trf or origin_trf['description'] != descr.value
968-
):
974+
if origin_trf.get('description') != descr.value:
969975
to_update['description'] = descr.value
970976
if int(origin_trf['position']) != position.value:
971977
to_update['position'] = int(position.value)

tests/plugins/commerce/test_commands.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,10 @@ def test_sync_stream(
847847

848848
with open('./tests/fixtures/commerce/stream_retrieve_response.json') as content:
849849
response = json.load(content)[0]
850+
response['status'] = 'configuring'
850851
mocked_responses.add(
851852
method='GET',
852-
url='https://localhost/public/v1/billing/streams?eq(id,STR-7748-7021-7449)&select(context,samples,sources)&limit=1&offset=0',
853+
url='https://localhost/public/v1/billing/streams?eq(id,STR-7748-7021-7449)&select(context,samples,sources,validation)&limit=1&offset=0',
853854
json=[response],
854855
)
855856
mocked_responses.add(
@@ -969,3 +970,50 @@ def test_sync_stream_no_stream(
969970

970971
assert result.exit_code == 1
971972
assert 'Stream STR-7748-7021-7449 not found for the current account VA-000.' in result.output
973+
974+
975+
def test_sync_stream_active_stream(
976+
mocker,
977+
ccli,
978+
mocked_responses,
979+
config_mocker,
980+
load_stream_sync,
981+
):
982+
mocker.patch(
983+
'connect.cli.plugins.commerce.utils.get_work_book',
984+
return_value=load_stream_sync,
985+
)
986+
mocker.patch(
987+
'connect.cli.plugins.commerce.utils.upload_attachment',
988+
return_value={'id': 'ID'},
989+
)
990+
mocked_responses.add(
991+
method='GET',
992+
url='https://localhost/public/v1/billing/streams?eq(id,STR-7748-7021-7449)&limit=0&offset=0',
993+
headers={
994+
'Content-Range': 'items 0-1/1',
995+
},
996+
)
997+
998+
with open('./tests/fixtures/commerce/stream_retrieve_response.json') as content:
999+
response = json.load(content)[0]
1000+
mocked_responses.add(
1001+
method='GET',
1002+
url='https://localhost/public/v1/billing/streams?eq(id,STR-7748-7021-7449)&select(context,samples,sources,validation)&limit=1&offset=0',
1003+
json=[response],
1004+
)
1005+
1006+
runner = CliRunner()
1007+
cmd = [
1008+
'commerce',
1009+
'stream',
1010+
'sync',
1011+
'STR-7748-7021-7449',
1012+
]
1013+
result = runner.invoke(
1014+
ccli,
1015+
cmd,
1016+
)
1017+
1018+
assert result.exit_code == 1
1019+
assert 'Stream STR-7748-7021-7449 cannot be updated because it is in "active"' in result.output

tests/plugins/commerce/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def test_update_general_information_error(sample_stream_workbook, mocker, mocked
337337
method='GET',
338338
url='https://localhost/public/v1/billing/streams?'
339339
'eq(id,STR-7755-7115-2464)&select(context,samples,sources)&limit=1&offset=0',
340-
json=[{'name': 'Name', 'description': 'Description'}],
340+
json=[{'name': 'Name', 'description': 'Description', 'status': 'configuring'}],
341341
)
342342

343343
mocked_responses.add(

0 commit comments

Comments
 (0)