@@ -728,10 +728,133 @@ def test_port_with_include(self,mock_connect,mock_path):
728
728
729
729
mock_connect .assert_has_calls (expected_calls_made , any_order = True )
730
730
731
-
732
-
733
-
731
+ @patch ('argparse.ArgumentParser.exit' )
732
+ @patch ('jnpr.jsnapy.jsnapy.sys.exit' )
733
+ @patch ('jnpr.jsnapy.SnapAdmin.login' )
734
+ @patch ('jnpr.jsnapy.jsnapy.logging.getLogger' )
735
+ def test_check_arguments_test_file_1 (self , mock_log , mock_login , mock_sys , mock_arg ):
736
+ js = SnapAdmin ()
737
+ js .args .snap = False
738
+ js .args .file = None
739
+ js .args .testfiles = os .path .join (os .path .dirname (__file__ ),
740
+ 'configs' , 'test_diff.yml' )
741
+ js .args .check = True
742
+ js .args .snapcheck = False
743
+ js .args .diff = False
744
+ js .args .login = "abc"
745
+ js .args .hostname = "10.216.193.114"
746
+ js .args .passwd = "xyz"
747
+ js .args .post_snapfile = "mock_snap2"
748
+ js .args .pre_snapfile = "mock_snap"
749
+ with patch ('argparse.ArgumentParser.print_help' ) as mock_parser :
750
+ js .check_arguments ()
751
+ js .get_hosts ()
752
+ self .assertTrue (js .main_file )
753
+ self .assertEqual (js .main_file ['hosts' ][0 ]['device' ],"10.216.193.114" )
754
+ self .assertEqual (js .main_file ['hosts' ][0 ]['username' ],"abc" )
755
+ self .assertEqual (js .main_file ['hosts' ][0 ]['passwd' ],"xyz" )
756
+ self .assertEqual (js .main_file ['tests' ][0 ],js .args .testfiles [0 ])
734
757
758
+ @patch ('argparse.ArgumentParser.exit' )
759
+ @patch ('jnpr.jsnapy.jsnapy.sys.exit' )
760
+ @patch ('jnpr.jsnapy.SnapAdmin.login' )
761
+ @patch ('jnpr.jsnapy.jsnapy.logging.getLogger' )
762
+ def test_check_arguments_test_file_2 (self , mock_log , mock_login , mock_sys , mock_arg ):
763
+ js = SnapAdmin ()
764
+ js .args .snap = True
765
+ js .args .file = None
766
+ js .args .testfiles = os .path .join (os .path .dirname (__file__ ),
767
+ 'configs' , 'test_diff.yml' )
768
+ js .args .check = False
769
+ js .args .snapcheck = False
770
+ js .args .diff = False
771
+ js .args .login = "abc"
772
+ js .args .hostname = "10.216.193.114"
773
+ js .args .passwd = "xyz"
774
+ js .args .post_snapfile = None
775
+ js .args .pre_snapfile = "mock_snap"
776
+ with patch ('argparse.ArgumentParser.print_help' ) as mock_parser :
777
+ js .check_arguments ()
778
+ js .get_hosts ()
779
+ self .assertTrue (js .main_file )
780
+ self .assertEqual (js .main_file ['hosts' ][0 ]['device' ],"10.216.193.114" )
781
+ self .assertEqual (js .main_file ['hosts' ][0 ]['username' ],"abc" )
782
+ self .assertEqual (js .main_file ['hosts' ][0 ]['passwd' ],"xyz" )
783
+ self .assertEqual (js .main_file ['tests' ][0 ],js .args .testfiles [0 ])
784
+
785
+ @patch ('argparse.ArgumentParser.exit' )
786
+ @patch ('jnpr.jsnapy.jsnapy.sys.exit' )
787
+ @patch ('jnpr.jsnapy.SnapAdmin.login' )
788
+ @patch ('jnpr.jsnapy.jsnapy.logging.getLogger' )
789
+ def test_check_arguments_test_file_3 (self , mock_log , mock_login , mock_sys , mock_arg ):
790
+ js = SnapAdmin ()
791
+ js .args .snap = False
792
+ js .args .file = None
793
+ js .args .testfiles = [os .path .join (os .path .dirname (__file__ ),
794
+ 'configs' , 'test_diff.yml' ),os .path .join (os .path .dirname (__file__ ),
795
+ 'configs' , 'tests.yml' )]
796
+ js .args .check = False
797
+ js .args .snapcheck = True
798
+ js .args .diff = False
799
+ js .args .login = "abc"
800
+ js .args .hostname = "10.216.193.114"
801
+ js .args .passwd = "xyz"
802
+ js .args .post_snapfile = "mock_snap2"
803
+ js .args .pre_snapfile = "mock_snap"
804
+ with patch ('argparse.ArgumentParser.print_help' ) as mock_parser :
805
+ js .check_arguments ()
806
+ js .get_hosts ()
807
+ self .assertTrue (js .main_file )
808
+ self .assertEqual (js .main_file ['hosts' ][0 ]['device' ],"10.216.193.114" )
809
+ self .assertEqual (js .main_file ['hosts' ][0 ]['username' ],"abc" )
810
+ self .assertEqual (js .main_file ['hosts' ][0 ]['passwd' ],"xyz" )
811
+ self .assertEqual (js .main_file ['tests' ][0 ],js .args .testfiles [0 ])
812
+ self .assertEqual (js .main_file ['tests' ][1 ],js .args .testfiles [1 ])
813
+
814
+ @patch ('argparse.ArgumentParser.exit' )
815
+ @patch ('jnpr.jsnapy.SnapAdmin.get_hosts' )
816
+ @patch ('jnpr.jsnapy.jsnapy.sys.exit' )
817
+ @patch ('jnpr.jsnapy.jsnapy.logging.getLogger' )
818
+ def test_check_arguments_test_file_4 (self , mock_log ,mock_sys , mock_get_hosts , mock_arg ):
819
+ js = SnapAdmin ()
820
+ js .args .snap = False
821
+ js .args .file = None
822
+ js .args .testfiles = os .path .join (os .path .dirname (__file__ ),
823
+ 'configs' , 'test_diff.yml' )
824
+ js .args .check = False
825
+ js .args .snapcheck = False
826
+ js .args .diff = True
827
+ js .args .login = "abc"
828
+ js .args .hostname = "10.216.193.114"
829
+ js .args .passwd = "xyz"
830
+ js .args .post_snapfile = "mock_snap2"
831
+ js .args .pre_snapfile = "mock_snap"
832
+ with patch ('argparse.ArgumentParser.print_help' ) as mock_parser :
833
+ js .check_arguments ()
834
+ self .assertFalse (mock_get_hosts .called )
835
+
836
+ @patch ('argparse.ArgumentParser.exit' )
837
+ @patch ('jnpr.jsnapy.SnapAdmin.get_hosts' )
838
+ @patch ('jnpr.jsnapy.jsnapy.sys.exit' )
839
+ @patch ('jnpr.jsnapy.jsnapy.logging.getLogger' )
840
+ def test_check_arguments_test_file_5 (self , mock_log , mock_sys , mock_get_hosts , mock_arg ):
841
+ js = SnapAdmin ()
842
+ js .args .snap = False
843
+ js .args .file = None
844
+ js .args .testfiles = None
845
+ js .args .check = True
846
+ js .args .snapcheck = False
847
+ js .args .diff = False
848
+ js .args .login = None
849
+ js .args .hostname = "10.216.193.114"
850
+ js .args .passwd = "xyz"
851
+ js .args .post_snapfile = "mock_snap2"
852
+ js .args .pre_snapfile = "mock_snap"
853
+ with patch ('argparse.ArgumentParser.print_help' ) as mock_parser :
854
+ js .check_arguments ()
855
+ self .assertFalse (mock_get_hosts .called )
856
+ mock_sys .assert_called_with (1 )
857
+ mock_parser .assert_called_with ()
735
858
736
859
with nested (
737
860
patch ('sys.exit' ),
0 commit comments