@@ -466,21 +466,27 @@ async def test_generate_datasource_charges_empty_daily_expenses(
466466 daily_expenses = {},
467467 )
468468 assert isinstance (response [0 ], str )
469- assert (
470- response [0 ] == '{"externalIds": {"vendor": "34654563456-01", "invoice": "-", '
471- '"reference": "1234"}, "search": {"subscription": '
472- '{"criteria": "subscription.externalIds.vendor", "value": "FORG-4801-6958-2949"}, '
473- '"item": {"criteria": "item.externalIds.vendor", "value": ""}}, '
474- '"period": {"start": "2025-06-01T00:00:00+00:00", "end": "2025-06-30T23:59:59+00:00"}, '
475- '"price": {"unitPP": "0.0000", "PPx1": "0.0000"}, '
476- '"quantity": 1, "description": {"value1": "Amazon Web Services datasource with '
477- 'name Test and id 1234", '
478- '"value2": "No charges available for this datasource."}, "segment": "COM"}\n '
479- )
480- assert (
481- json .loads (response [0 ]).get ("description" ).get ("value2" )
482- == "No charges available for this datasource."
483- )
469+ line = json .loads (response [0 ])
470+ assert line == {
471+ "externalIds" : {"vendor" : "34654563456-01" , "invoice" : "-" , "reference" : "1234" },
472+ "search" : {
473+ "source" : {
474+ "type" : "Subscription" ,
475+ "criteria" : "externalIds.vendor" ,
476+ "value" : "FORG-4801-6958-2949" ,
477+ },
478+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
479+ },
480+ "period" : {"start" : "2025-06-01T00:00:00+00:00" , "end" : "2025-06-30T23:59:59+00:00" },
481+ "price" : {"unitPP" : "0.0000" , "PPx1" : "0.0000" },
482+ "quantity" : 1 ,
483+ "description" : {
484+ "value1" : "Amazon Web Services datasource with name Test and id 1234" ,
485+ "value2" : "No charges available for this datasource." ,
486+ },
487+ "segment" : "COM" ,
488+ }
489+ assert line .get ("description" ).get ("value2" ) == "No charges available for this datasource."
484490
485491
486492@pytest .mark .parametrize ("billing_process_instance" , [{"month" : 9 }], indirect = True )
@@ -565,47 +571,71 @@ async def test_generate_datasource_charges_with_daily_expenses_active_trial_term
565571 daily_expenses = daily_expenses ,
566572 )
567573 assert isinstance (response [0 ], str )
568- assert (
569- response [0 ] == '{"externalIds": {"vendor": "34654563456-01", "invoice": "-", '
570- '"reference": "34654563488"}, "search": {"subscription": '
571- '{"criteria": "subscription.externalIds.vendor", "value": '
572- '"FORG-4801-6958-2949"}, "item": {"criteria": '
573- '"item.externalIds.vendor", "value": ""}}, "period": '
574- '{"start": "2025-09-01T00:00:00+00:00", "end": "2025-09-30T23:59:59+00:00"}, '
575- '"price": {"unitPP": "183.9829", "PPx1": "183.9829"},'
576- ' "quantity": 1, "description": {"value1": "Amazon Web Services datasource with name Test'
577- ' and id 34654563488", "value2": ""},'
578- ' "segment": "COM"}\n '
579- )
580- assert (
581- response [1 ] == '{"externalIds": {"vendor": "34654563456-02", "invoice": "-", '
582- '"reference": "34654563488"}, '
583- '"search": {"subscription": {"criteria": "subscription.externalIds.vendor",'
584- ' "value": "FORG-4801-6958-2949"}, "item": {"criteria": "item.externalIds.vendor",'
585- ' "value": ""}}, "period": {"start": "2025-09-01T00:00:00+00:00", '
586- '"end": "2025-09-15T23:59:59+00:00"},'
587- ' "price": {"unitPP": "-39.1447", "PPx1": "-39.1447"}, "quantity": 1, '
588- '"description": {"value1": "Amazon Web Services datasource with name Test '
589- 'and id 34654563488", "value2": "Refund due to trial period '
590- '(from 27 Aug 2025 to 15 Sep 2025)"}, "segment": "COM"}\n '
591- )
592- assert (
593- response [2 ] == '{"externalIds": {"vendor": "34654563456-03", "invoice": "-", '
594- '"reference": "34654563488"}, "search": {"subscription": '
595- '{"criteria": "subscription.externalIds.vendor", "value": "FORG-4801-6958-2949"},'
596- ' "item": {"criteria": "item.externalIds.vendor", "value": ""}}, '
597- '"period": {"start": "2025-09-16T00:00:00+00:00", "end": "2025-09-28T23:59:59+00:00"},'
598- ' "price": {"unitPP": "-137.9294", "PPx1": "-137.9294"}, '
599- '"quantity": 1, "description": {"value1": "Amazon Web Services datasource with name Test '
600- 'and id 34654563488", "value2": '
601- '"Refund due to active entitlement FENT-9763-4488-4624"}, "segment": "COM"}\n '
602- )
574+ lines = [json .loads (r ) for r in response ]
575+ assert lines [0 ] == {
576+ "externalIds" : {"vendor" : "34654563456-01" , "invoice" : "-" , "reference" : "34654563488" },
577+ "search" : {
578+ "source" : {
579+ "type" : "Subscription" ,
580+ "criteria" : "externalIds.vendor" ,
581+ "value" : "FORG-4801-6958-2949" ,
582+ },
583+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
584+ },
585+ "period" : {"start" : "2025-09-01T00:00:00+00:00" , "end" : "2025-09-30T23:59:59+00:00" },
586+ "price" : {"unitPP" : "183.9829" , "PPx1" : "183.9829" },
587+ "quantity" : 1 ,
588+ "description" : {
589+ "value1" : "Amazon Web Services datasource with name Test and id 34654563488" ,
590+ "value2" : "" ,
591+ },
592+ "segment" : "COM" ,
593+ }
594+ assert lines [1 ] == {
595+ "externalIds" : {"vendor" : "34654563456-02" , "invoice" : "-" , "reference" : "34654563488" },
596+ "search" : {
597+ "source" : {
598+ "type" : "Subscription" ,
599+ "criteria" : "externalIds.vendor" ,
600+ "value" : "FORG-4801-6958-2949" ,
601+ },
602+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
603+ },
604+ "period" : {"start" : "2025-09-01T00:00:00+00:00" , "end" : "2025-09-15T23:59:59+00:00" },
605+ "price" : {"unitPP" : "-39.1447" , "PPx1" : "-39.1447" },
606+ "quantity" : 1 ,
607+ "description" : {
608+ "value1" : "Amazon Web Services datasource with name Test and id 34654563488" ,
609+ "value2" : "Refund due to trial period (from 27 Aug 2025 to 15 Sep 2025)" ,
610+ },
611+ "segment" : "COM" ,
612+ }
613+ assert lines [2 ] == {
614+ "externalIds" : {"vendor" : "34654563456-03" , "invoice" : "-" , "reference" : "34654563488" },
615+ "search" : {
616+ "source" : {
617+ "type" : "Subscription" ,
618+ "criteria" : "externalIds.vendor" ,
619+ "value" : "FORG-4801-6958-2949" ,
620+ },
621+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
622+ },
623+ "period" : {"start" : "2025-09-16T00:00:00+00:00" , "end" : "2025-09-28T23:59:59+00:00" },
624+ "price" : {"unitPP" : "-137.9294" , "PPx1" : "-137.9294" },
625+ "quantity" : 1 ,
626+ "description" : {
627+ "value1" : "Amazon Web Services datasource with name Test and id 34654563488" ,
628+ "value2" : "Refund due to active entitlement FENT-9763-4488-4624" ,
629+ },
630+ "segment" : "COM" ,
631+ }
603632 assert (
604633 "[AUT-5305-9928] : organization_id='FORG-4801-6958-2949'"
605634 " linked_datasource_id='34654563456' datasource_name='Test' - "
606635 "amount=Decimal('5326.0458') billing_percentage=Decimal('4') "
607636 "price_in_source_currency=Decimal('213.0418') "
608637 "exchange_rate=Decimal('0.8636') price_in_target_currency=Decimal('183.98289848')\n "
638+ in caplog .text
609639 )
610640
611641
@@ -687,30 +717,45 @@ async def test_generate_datasource_charges_with_daily_expenses_active_trial_and_
687717 daily_expenses = daily_expenses ,
688718 )
689719 assert isinstance (response [0 ], str )
690- assert (
691- response [0 ] == '{"externalIds": {"vendor": "34654563456-01", "invoice": "-", "reference": '
692- '"34654563488"}, "search": {"subscription": {"criteria": '
693- '"subscription.externalIds.vendor", "value": "FORG-4801-6958-2949"}, "item": '
694- '{"criteria": "item.externalIds.vendor", "value": ""}}, "period": {"start": '
695- '"2025-09-01T00:00:00+00:00", "end": "2025-09-30T23:59:59+00:00"}, '
696- '"price": {"unitPP": "183.9829", "PPx1": '
697- '"183.9829"}, "quantity": 1, "description": {"value1": "Amazon Web Services datasource '
698- 'with name Test and id 34654563488", "value2": ""}, '
699- '"segment": "COM"}\n '
700- )
701- assert (
702- response [1 ] == '{"externalIds": {"vendor": "34654563456-02", "invoice": "-",'
703- ' "reference": "34654563488"}, "search": {"subscription": '
704- '{"criteria": "subscription.externalIds.vendor", '
705- '"value": "FORG-4801-6958-2949"}, "item": '
706- '{"criteria": "item.externalIds.vendor", "value": ""}},'
707- ' "period": {"start": "2025-09-01T00:00:00+00:00", "end": "2025-09-26T23:59:59+00:00"}, '
708- '"price": {"unitPP": "-153.1250", "PPx1": "-153.1250"}, '
709- '"quantity": 1, "description": {"value1": "Amazon Web Services datasource with name Test '
710- 'and id 34654563488", "value2": '
711- '"Refund due to trial period (from 27 Aug 2025 to 26 Sep 2025)"},'
712- ' "segment": "COM"}\n '
713- )
720+ lines = [json .loads (r ) for r in response ]
721+ assert lines [0 ] == {
722+ "externalIds" : {"vendor" : "34654563456-01" , "invoice" : "-" , "reference" : "34654563488" },
723+ "search" : {
724+ "source" : {
725+ "type" : "Subscription" ,
726+ "criteria" : "externalIds.vendor" ,
727+ "value" : "FORG-4801-6958-2949" ,
728+ },
729+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
730+ },
731+ "period" : {"start" : "2025-09-01T00:00:00+00:00" , "end" : "2025-09-30T23:59:59+00:00" },
732+ "price" : {"unitPP" : "183.9829" , "PPx1" : "183.9829" },
733+ "quantity" : 1 ,
734+ "description" : {
735+ "value1" : "Amazon Web Services datasource with name Test and id 34654563488" ,
736+ "value2" : "" ,
737+ },
738+ "segment" : "COM" ,
739+ }
740+ assert lines [1 ] == {
741+ "externalIds" : {"vendor" : "34654563456-02" , "invoice" : "-" , "reference" : "34654563488" },
742+ "search" : {
743+ "source" : {
744+ "type" : "Subscription" ,
745+ "criteria" : "externalIds.vendor" ,
746+ "value" : "FORG-4801-6958-2949" ,
747+ },
748+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
749+ },
750+ "period" : {"start" : "2025-09-01T00:00:00+00:00" , "end" : "2025-09-26T23:59:59+00:00" },
751+ "price" : {"unitPP" : "-153.1250" , "PPx1" : "-153.1250" },
752+ "quantity" : 1 ,
753+ "description" : {
754+ "value1" : "Amazon Web Services datasource with name Test and id 34654563488" ,
755+ "value2" : "Refund due to trial period (from 27 Aug 2025 to 26 Sep 2025)" ,
756+ },
757+ "segment" : "COM" ,
758+ }
714759 assert (
715760 "[AUT-5305-9928] : organization_id='FORG-4801-6958-2949' "
716761 "linked_datasource_id='34654563456' datasource_name='Test' - "
@@ -763,18 +808,27 @@ async def test_generate_datasource_charges_with_price_in_source_currency_eq_0(
763808 daily_expenses = daily_expenses ,
764809 )
765810 assert isinstance (response [0 ], str )
766- assert (
767- response [0 ] == '{"externalIds": {"vendor": "34654563456-01", "invoice": "-", '
768- '"reference": "34654563488"}, '
769- '"search": {"subscription": {"criteria": "subscription.externalIds.vendor", '
770- '"value": "FORG-4801-6958-2949"}, '
771- '"item": {"criteria": "item.externalIds.vendor", "value": ""}}, '
772- '"period": {"start": "2025-06-01T00:00:00+00:00", "end": "2025-06-30T23:59:59+00:00"}, '
773- '"price": {"unitPP": "0.0000", "PPx1": "0.0000"}, "quantity": 1,'
774- ' "description": {"value1": "Amazon Web Services datasource with name Test '
775- 'and id 34654563488", "value2": ""}, "segment": "COM"}\n '
776- )
777- assert json .loads (response [0 ]).get ("price" ).get ("unitPP" ) == "0.0000"
811+ line = json .loads (response [0 ])
812+ assert line == {
813+ "externalIds" : {"vendor" : "34654563456-01" , "invoice" : "-" , "reference" : "34654563488" },
814+ "search" : {
815+ "source" : {
816+ "type" : "Subscription" ,
817+ "criteria" : "externalIds.vendor" ,
818+ "value" : "FORG-4801-6958-2949" ,
819+ },
820+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
821+ },
822+ "period" : {"start" : "2025-06-01T00:00:00+00:00" , "end" : "2025-06-30T23:59:59+00:00" },
823+ "price" : {"unitPP" : "0.0000" , "PPx1" : "0.0000" },
824+ "quantity" : 1 ,
825+ "description" : {
826+ "value1" : "Amazon Web Services datasource with name Test and id 34654563488" ,
827+ "value2" : "" ,
828+ },
829+ "segment" : "COM" ,
830+ }
831+ assert line .get ("price" ).get ("unitPP" ) == "0.0000"
778832
779833
780834@pytest .mark .asyncio ()
@@ -806,29 +860,45 @@ async def test_generate_datasource_charges_with_no_entitlement(
806860 daily_expenses = daily_expenses ,
807861 )
808862 assert isinstance (response [0 ], str )
809- assert (
810- response [0 ] == '{"externalIds": {"vendor": "34654563456-01", "invoice": "-", '
811- '"reference": "34654563488"}, '
812- '"search": {"subscription": {"criteria": "subscription.externalIds.vendor", '
813- '"value": "FORG-4801-6958-2949"}, '
814- '"item": {"criteria": "item.externalIds.vendor", "value": ""}}, '
815- '"period": {"start": "2025-06-01T00:00:00+00:00", "end": "2025-06-30T23:59:59+00:00"}, '
816- '"price": {"unitPP": "183.9829", "PPx1": "183.9829"}, '
817- '"quantity": 1, "description": {"value1": "Amazon Web Services datasource with name Test'
818- ' and id 34654563488", "value2": ""}, "segment": "COM"}\n '
819- )
820- assert (
821- response [1 ] == '{"externalIds": {"vendor": "34654563456-02", "invoice": "-", "reference": '
822- '"34654563488"}, "search": {"subscription": {"criteria": '
823- '"subscription.externalIds.vendor", "value": "FORG-4801-6958-2949"}, "item": '
824- '{"criteria": "item.externalIds.vendor", "value": ""}}, "period": {"start": '
825- '"2025-06-01T00:00:00+00:00", "end": "2025-06-15T23:59:59+00:00"},'
826- ' "price": {"unitPP": "-39.1447", "PPx1": '
827- '"-39.1447"}, "quantity": 1, "description": {"value1": "Amazon Web Services datasource'
828- ' with name Test and id 34654563488", "value2": '
829- '"Refund due to trial period (from 01 Jun 2025 to 15 Jun 2025)"}, '
830- '"segment": "COM"}\n '
831- )
863+ lines = [json .loads (r ) for r in response ]
864+ assert lines [0 ] == {
865+ "externalIds" : {"vendor" : "34654563456-01" , "invoice" : "-" , "reference" : "34654563488" },
866+ "search" : {
867+ "source" : {
868+ "type" : "Subscription" ,
869+ "criteria" : "externalIds.vendor" ,
870+ "value" : "FORG-4801-6958-2949" ,
871+ },
872+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
873+ },
874+ "period" : {"start" : "2025-06-01T00:00:00+00:00" , "end" : "2025-06-30T23:59:59+00:00" },
875+ "price" : {"unitPP" : "183.9829" , "PPx1" : "183.9829" },
876+ "quantity" : 1 ,
877+ "description" : {
878+ "value1" : "Amazon Web Services datasource with name Test and id 34654563488" ,
879+ "value2" : "" ,
880+ },
881+ "segment" : "COM" ,
882+ }
883+ assert lines [1 ] == {
884+ "externalIds" : {"vendor" : "34654563456-02" , "invoice" : "-" , "reference" : "34654563488" },
885+ "search" : {
886+ "source" : {
887+ "type" : "Subscription" ,
888+ "criteria" : "externalIds.vendor" ,
889+ "value" : "FORG-4801-6958-2949" ,
890+ },
891+ "item" : {"criteria" : "item.externalIds.vendor" , "value" : "" },
892+ },
893+ "period" : {"start" : "2025-06-01T00:00:00+00:00" , "end" : "2025-06-15T23:59:59+00:00" },
894+ "price" : {"unitPP" : "-39.1447" , "PPx1" : "-39.1447" },
895+ "quantity" : 1 ,
896+ "description" : {
897+ "value1" : "Amazon Web Services datasource with name Test and id 34654563488" ,
898+ "value2" : "Refund due to trial period (from 01 Jun 2025 to 15 Jun 2025)" ,
899+ },
900+ "segment" : "COM" ,
901+ }
832902
833903
834904# ------------------------------------------------------------------------------------
0 commit comments