Skip to content

Commit 0fce53b

Browse files
authored
Merge pull request #246 from cloudblue/LITE-33042-support-monthly-trial-billing-period
LITE-33042 Support monthly_trial billing period
2 parents 2f774dd + 5fce86c commit 0fce53b

3 files changed

Lines changed: 145 additions & 3 deletions

File tree

connect/cli/plugins/product/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
BILLING_PERIOD = (
2525
'onetime',
2626
'monthly',
27+
'monthly_trial',
2728
'yearly',
2829
'2 years',
2930
'3 years',
@@ -35,6 +36,7 @@
3536

3637
ALLOWED_COMMITMENTS = {
3738
'monthly': COMMITMENT,
39+
'monthly_trial': ('-',),
3840
'yearly': COMMITMENT,
3941
'2 years': ('-', '4 years', '6 years'),
4042
'3 years': ('-', '6 years'),

connect/cli/plugins/product/sync/items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def _get_commitment_count(data):
270270

271271
@staticmethod
272272
def _get_billing_period(data):
273-
if data.billing_period in ('onetime', 'monthly', 'yearly'):
273+
if data.billing_period in ('onetime', 'monthly', 'monthly_trial', 'yearly'):
274274
return data.billing_period
275275
count, _ = data.billing_period.split()
276276
return f'years_{count}'

tests/plugins/product/sync/test_items.py

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,49 @@ def test_validate_wrong_period_reservation(mocker, fs, get_sync_items_env):
404404
}
405405
assert stats['Items']._row_errors == {
406406
2: [
407-
'the item `Billing period` must be one between `onetime`, `monthly`, `yearly`, '
408-
'`2 years`, `3 years`, `4 years`, `5 years`, `6 years`, not `century`.',
407+
'the item `Billing period` must be one between `onetime`, `monthly`, `monthly_trial`, '
408+
'`yearly`, `2 years`, `3 years`, `4 years`, `5 years`, `6 years`, not `century`.',
409+
],
410+
}
411+
412+
413+
def test_validate_monthly_trial_period_wrong_commitment(
414+
mocker,
415+
fs,
416+
get_sync_items_env,
417+
):
418+
get_sync_items_env['Items']['A2'].value = None
419+
get_sync_items_env['Items']['C2'].value = 'create'
420+
get_sync_items_env['Items']['F2'].value = 'reservation'
421+
get_sync_items_env['Items']['I2'].value = 'monthly_trial'
422+
get_sync_items_env['Items']['J2'].value = '1 year'
423+
get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
424+
425+
stats = SynchronizerStats()
426+
synchronizer = ItemSynchronizer(
427+
client=ConnectClient(
428+
use_specs=False,
429+
api_key='ApiKey SU:123',
430+
endpoint='https://localhost/public/v1',
431+
),
432+
progress=mocker.MagicMock(),
433+
stats=stats,
434+
)
435+
436+
synchronizer.open(f'{fs.root_path}/test.xlsx', 'Items')
437+
synchronizer.sync()
438+
439+
assert stats['Items'].get_counts_as_dict() == {
440+
'processed': 1,
441+
'created': 0,
442+
'updated': 0,
443+
'deleted': 0,
444+
'skipped': 0,
445+
'errors': 1,
446+
}
447+
assert stats['Items']._row_errors == {
448+
2: [
449+
'for a `monthly_trial` billing period the commitment must be one of `-`, not `1 year`.',
409450
],
410451
}
411452

@@ -605,6 +646,105 @@ def test_create_item_one_time(
605646
}
606647

607648

649+
def test_create_item_monthly_trial(
650+
mocker,
651+
fs,
652+
get_sync_items_env,
653+
mocked_responses,
654+
mocked_items_response,
655+
):
656+
get_sync_items_env['Items']['A2'].value = None
657+
get_sync_items_env['Items']['C2'].value = 'create'
658+
get_sync_items_env['Items']['I2'].value = 'monthly_trial'
659+
660+
get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
661+
mocked_responses.add(
662+
method='GET',
663+
url='https://localhost/public/v1/products/PRD-276-377-545/items?eq(mpn,'
664+
'MPN-R-001)&limit=1&offset=0',
665+
json=[],
666+
)
667+
668+
mocked_responses.add(
669+
method='POST',
670+
url='https://localhost/public/v1/products/PRD-276-377-545/items',
671+
json=mocked_items_response[0],
672+
)
673+
674+
stats = SynchronizerStats()
675+
synchronizer = ItemSynchronizer(
676+
client=ConnectClient(
677+
use_specs=False,
678+
api_key='ApiKey SU:123',
679+
endpoint='https://localhost/public/v1',
680+
),
681+
progress=mocker.MagicMock(),
682+
stats=stats,
683+
)
684+
685+
synchronizer.open(f'{fs.root_path}/test.xlsx', 'Items')
686+
synchronizer.sync()
687+
688+
assert stats['Items'].get_counts_as_dict() == {
689+
'processed': 1,
690+
'created': 1,
691+
'updated': 0,
692+
'deleted': 0,
693+
'skipped': 0,
694+
'errors': 0,
695+
}
696+
697+
698+
def test_create_item_multi_year(
699+
mocker,
700+
fs,
701+
get_sync_items_env,
702+
mocked_responses,
703+
mocked_items_response,
704+
):
705+
get_sync_items_env['Items']['A2'].value = None
706+
get_sync_items_env['Items']['C2'].value = 'create'
707+
get_sync_items_env['Items']['I2'].value = '2 years'
708+
get_sync_items_env['Items']['J2'].value = '-'
709+
710+
get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
711+
mocked_responses.add(
712+
method='GET',
713+
url='https://localhost/public/v1/products/PRD-276-377-545/items?eq(mpn,'
714+
'MPN-R-001)&limit=1&offset=0',
715+
json=[],
716+
)
717+
718+
mocked_responses.add(
719+
method='POST',
720+
url='https://localhost/public/v1/products/PRD-276-377-545/items',
721+
json=mocked_items_response[0],
722+
)
723+
724+
stats = SynchronizerStats()
725+
synchronizer = ItemSynchronizer(
726+
client=ConnectClient(
727+
use_specs=False,
728+
api_key='ApiKey SU:123',
729+
endpoint='https://localhost/public/v1',
730+
),
731+
progress=mocker.MagicMock(),
732+
stats=stats,
733+
)
734+
735+
synchronizer.open(f'{fs.root_path}/test.xlsx', 'Items')
736+
synchronizer.sync()
737+
738+
assert stats['Items'].get_counts_as_dict() == {
739+
'processed': 1,
740+
'created': 1,
741+
'updated': 0,
742+
'deleted': 0,
743+
'skipped': 0,
744+
'errors': 0,
745+
}
746+
747+
608748
def test_create_item_yearly(
609749
mocker,
610750
fs,

0 commit comments

Comments
 (0)