@@ -447,3 +447,117 @@ def test_retrieve_invoice(self, mock_requests):
447447 self .assertTrue (isinstance (result , Invoice ))
448448
449449 self .assertEqual (result .uuid , "inv_22910fc6-c931-48e7-ac12-90d2cb5f0059" )
450+
451+ @requests_mock .mock ()
452+ def test_retrieve_invoice_with_validation_type (self , mock_requests ):
453+ mock_requests .register_uri (
454+ "GET" ,
455+ ("https://api.chartmogul.com/v1/invoices/inv_22910fc6-c931-48e7-ac12-90d2cb5f0059"
456+ "?validation_type=all" ),
457+ request_headers = {"Authorization" : "Basic dG9rZW46" },
458+ headers = {"Content-Type" : "application/json" },
459+ status_code = 200 ,
460+ json = retrieveInvoiceExample ,
461+ )
462+
463+ config = Config ("token" ) # is actually checked in mock
464+ result = Invoice .retrieve (
465+ config ,
466+ uuid = "inv_22910fc6-c931-48e7-ac12-90d2cb5f0059" ,
467+ validation_type = "all"
468+ ).get ()
469+
470+ self .assertEqual (mock_requests .call_count , 1 , "expected call" )
471+ vt = []
472+ vt .append ("all" )
473+ self .assertEqual (mock_requests .last_request .qs , {"validation_type" : vt })
474+
475+ # Struct too complex to do 1:1 comparison
476+ self .assertTrue (isinstance (result , Invoice ))
477+
478+ self .assertEqual (result .uuid , "inv_22910fc6-c931-48e7-ac12-90d2cb5f0059" )
479+
480+ @requests_mock .mock ()
481+ def test_retrieve_invoice_with_all_params (self , mock_requests ):
482+ mock_requests .register_uri (
483+ "GET" ,
484+ ("https://api.chartmogul.com/v1/invoices/inv_22910fc6-c931-48e7-ac12-90d2cb5f0059"
485+ "?validation_type=invalid&include_edit_histories=true&with_disabled=false" ),
486+ request_headers = {"Authorization" : "Basic dG9rZW46" },
487+ headers = {"Content-Type" : "application/json" },
488+ status_code = 200 ,
489+ json = retrieveInvoiceExample ,
490+ )
491+
492+ config = Config ("token" ) # is actually checked in mock
493+ result = Invoice .retrieve (
494+ config ,
495+ uuid = "inv_22910fc6-c931-48e7-ac12-90d2cb5f0059" ,
496+ validation_type = "invalid" ,
497+ include_edit_histories = True ,
498+ with_disabled = False
499+ ).get ()
500+
501+ self .assertEqual (mock_requests .call_count , 1 , "expected call" )
502+ qs = mock_requests .last_request .qs
503+ self .assertEqual (qs ["validation_type" ], ["invalid" ])
504+ self .assertEqual (qs ["include_edit_histories" ], ["true" ])
505+ self .assertEqual (qs ["with_disabled" ], ["false" ])
506+
507+ # Struct too complex to do 1:1 comparison
508+ self .assertTrue (isinstance (result , Invoice ))
509+
510+ self .assertEqual (result .uuid , "inv_22910fc6-c931-48e7-ac12-90d2cb5f0059" )
511+
512+ @requests_mock .mock ()
513+ def test_all_invoices_with_validation_type (self , mock_requests ):
514+ mock_requests .register_uri (
515+ "GET" ,
516+ "https://api.chartmogul.com/v1/invoices?validation_type=all" ,
517+ request_headers = {"Authorization" : "Basic dG9rZW46" },
518+ headers = {"Content-Type" : "application/json" },
519+ status_code = 200 ,
520+ json = invoiceListExample ,
521+ )
522+
523+ config = Config ("token" ) # is actually checked in mock
524+ result = Invoice .all (config , validation_type = "all" ).get ()
525+
526+ self .assertEqual (mock_requests .call_count , 1 , "expected call" )
527+ vt = []
528+ vt .append ("all" )
529+ self .assertEqual (mock_requests .last_request .qs , {"validation_type" : vt })
530+
531+ # Struct too complex to do 1:1 comparison
532+ self .assertTrue (isinstance (result , Invoice ._many ))
533+ self .assertEqual (len (result .invoices ), 1 )
534+
535+ @requests_mock .mock ()
536+ def test_all_invoices_with_all_params (self , mock_requests ):
537+ mock_requests .register_uri (
538+ "GET" ,
539+ ("https://api.chartmogul.com/v1/invoices"
540+ "?validation_type=valid&include_edit_histories=true&with_disabled=true" ),
541+ request_headers = {"Authorization" : "Basic dG9rZW46" },
542+ headers = {"Content-Type" : "application/json" },
543+ status_code = 200 ,
544+ json = invoiceListExample ,
545+ )
546+
547+ config = Config ("token" ) # is actually checked in mock
548+ result = Invoice .all (
549+ config ,
550+ validation_type = "valid" ,
551+ include_edit_histories = True ,
552+ with_disabled = True
553+ ).get ()
554+
555+ self .assertEqual (mock_requests .call_count , 1 , "expected call" )
556+ qs = mock_requests .last_request .qs
557+ self .assertEqual (qs ["validation_type" ], ["valid" ])
558+ self .assertEqual (qs ["include_edit_histories" ], ["true" ])
559+ self .assertEqual (qs ["with_disabled" ], ["true" ])
560+
561+ # Struct too complex to do 1:1 comparison
562+ self .assertTrue (isinstance (result , Invoice ._many ))
563+ self .assertEqual (len (result .invoices ), 1 )
0 commit comments