@@ -523,8 +523,8 @@ def test_get_ipv4_ssh_config(auth, pis_response, pi_info_response, pi_info_respo
523523 assert auth ._api_session .get .call_args_list [0 ][0 ][0 ] == cloud ._api_url + "servers"
524524 assert auth ._api_session .get .call_args_list [1 ][0 ][0 ] == cloud ._api_url + "servers/pi1"
525525 assert auth ._api_session .get .call_args_list [2 ][0 ][0 ] == cloud ._api_url + "servers/pi2"
526- assert ipv4_config .count ("\n " ) == 7
527526 lines = ipv4_config .splitlines ()
527+ assert len (lines ) == 8
528528 assert lines [0 ] == "Host pi1"
529529 assert lines [1 ] == " user root"
530530 assert lines [2 ] == " port 5100"
@@ -535,6 +535,52 @@ def test_get_ipv4_ssh_config(auth, pis_response, pi_info_response, pi_info_respo
535535 assert lines [7 ] == " hostname ssh.pi2.hostedpi.com"
536536
537537
538+ def test_get_ipv4_ssh_config_pi_user (auth , pis_response , pi_info_response , pi_info_response_2 ):
539+ cloud = PiCloud (auth = auth )
540+ auth ._api_session .get .side_effect = [
541+ pis_response ,
542+ pi_info_response ,
543+ pi_info_response_2 ,
544+ ]
545+ ipv4_config = cloud .get_ipv4_ssh_config (user = "pi" )
546+ assert auth ._api_session .get .call_count == 3
547+ assert auth ._api_session .get .call_args_list [0 ][0 ][0 ] == cloud ._api_url + "servers"
548+ assert auth ._api_session .get .call_args_list [1 ][0 ][0 ] == cloud ._api_url + "servers/pi1"
549+ assert auth ._api_session .get .call_args_list [2 ][0 ][0 ] == cloud ._api_url + "servers/pi2"
550+ lines = ipv4_config .splitlines ()
551+ assert len (lines ) == 8
552+ assert lines [0 ] == "Host pi1"
553+ assert lines [1 ] == " user pi"
554+ assert lines [2 ] == " port 5100"
555+ assert lines [3 ] == " hostname ssh.pi1.hostedpi.com"
556+ assert lines [4 ] == "Host pi2"
557+ assert lines [5 ] == " user pi"
558+ assert lines [6 ] == " port 5123"
559+ assert lines [7 ] == " hostname ssh.pi2.hostedpi.com"
560+
561+
562+ def test_get_ipv4_ssh_config_no_user (auth , pis_response , pi_info_response , pi_info_response_2 ):
563+ cloud = PiCloud (auth = auth )
564+ auth ._api_session .get .side_effect = [
565+ pis_response ,
566+ pi_info_response ,
567+ pi_info_response_2 ,
568+ ]
569+ ipv4_config = cloud .get_ipv4_ssh_config (user = None )
570+ assert auth ._api_session .get .call_count == 3
571+ assert auth ._api_session .get .call_args_list [0 ][0 ][0 ] == cloud ._api_url + "servers"
572+ assert auth ._api_session .get .call_args_list [1 ][0 ][0 ] == cloud ._api_url + "servers/pi1"
573+ assert auth ._api_session .get .call_args_list [2 ][0 ][0 ] == cloud ._api_url + "servers/pi2"
574+ lines = ipv4_config .splitlines ()
575+ assert len (lines ) == 6
576+ assert lines [0 ] == "Host pi1"
577+ assert lines [1 ] == " port 5100"
578+ assert lines [2 ] == " hostname ssh.pi1.hostedpi.com"
579+ assert lines [3 ] == "Host pi2"
580+ assert lines [4 ] == " port 5123"
581+ assert lines [5 ] == " hostname ssh.pi2.hostedpi.com"
582+
583+
538584def test_get_ipv6_ssh_config (auth , pis_response , pi_info_response , pi_info_response_2 ):
539585 cloud = PiCloud (auth = auth )
540586 auth ._api_session .get .side_effect = [
@@ -545,11 +591,49 @@ def test_get_ipv6_ssh_config(auth, pis_response, pi_info_response, pi_info_respo
545591 ipv6_config = cloud .ipv6_ssh_config
546592 assert auth ._api_session .get .call_count == 1
547593 assert auth ._api_session .get .call_args_list [0 ][0 ][0 ] == cloud ._api_url + "servers"
548- assert ipv6_config .count ("\n " ) == 5
549594 lines = ipv6_config .splitlines ()
595+ assert len (lines ) == 6
550596 assert lines [0 ] == "Host pi1"
551597 assert lines [1 ] == " user root"
552598 assert lines [2 ] == " hostname pi1.hostedpi.com"
553599 assert lines [3 ] == "Host pi2"
554600 assert lines [4 ] == " user root"
555601 assert lines [5 ] == " hostname pi2.hostedpi.com"
602+
603+
604+ def test_get_ipv6_ssh_config_pi_user (auth , pis_response , pi_info_response , pi_info_response_2 ):
605+ cloud = PiCloud (auth = auth )
606+ auth ._api_session .get .side_effect = [
607+ pis_response ,
608+ pi_info_response ,
609+ pi_info_response_2 ,
610+ ]
611+ ipv6_config = cloud .get_ipv6_ssh_config (user = "pi" )
612+ assert auth ._api_session .get .call_count == 1
613+ assert auth ._api_session .get .call_args_list [0 ][0 ][0 ] == cloud ._api_url + "servers"
614+ lines = ipv6_config .splitlines ()
615+ assert len (lines ) == 6
616+ assert lines [0 ] == "Host pi1"
617+ assert lines [1 ] == " user pi"
618+ assert lines [2 ] == " hostname pi1.hostedpi.com"
619+ assert lines [3 ] == "Host pi2"
620+ assert lines [4 ] == " user pi"
621+ assert lines [5 ] == " hostname pi2.hostedpi.com"
622+
623+
624+ def test_get_ipv6_ssh_config_no_user (auth , pis_response , pi_info_response , pi_info_response_2 ):
625+ cloud = PiCloud (auth = auth )
626+ auth ._api_session .get .side_effect = [
627+ pis_response ,
628+ pi_info_response ,
629+ pi_info_response_2 ,
630+ ]
631+ ipv6_config = cloud .get_ipv6_ssh_config (user = None )
632+ assert auth ._api_session .get .call_count == 1
633+ assert auth ._api_session .get .call_args_list [0 ][0 ][0 ] == cloud ._api_url + "servers"
634+ lines = ipv6_config .splitlines ()
635+ assert len (lines ) == 4
636+ assert lines [0 ] == "Host pi1"
637+ assert lines [1 ] == " hostname pi1.hostedpi.com"
638+ assert lines [2 ] == "Host pi2"
639+ assert lines [3 ] == " hostname pi2.hostedpi.com"
0 commit comments