| 651 | assert Connection("a-host", port=1) < Connection("a-host", port=2) |
| 652 | |
| 653 | class open: |
| 654 | def has_no_required_args_and_returns_value_of_connect(self, client): |
| 655 | retval = Connection("host").open() |
| 656 | assert retval is client.connect.return_value |
| 657 | |
| 658 | def calls_SSHClient_connect(self, client): |
| 659 | "calls paramiko.SSHClient.connect() with correct args" |
| 660 | Connection("host").open() |
| 661 | client.connect.assert_called_with( |
| 662 | username=get_local_user(), hostname="host", port=22 |
| 663 | ) |
| 664 | |
| 665 | def passes_through_connect_kwargs(self, client): |
| 666 | Connection("host", connect_kwargs={"foobar": "bizbaz"}).open() |
| 667 | client.connect.assert_called_with( |
| 668 | username=get_local_user(), |
| 669 | hostname="host", |
| 670 | port=22, |
| 671 | foobar="bizbaz", |
| 672 | ) |
| 673 | |
| 674 | def refuses_to_overwrite_connect_kwargs_with_others(self, client): |
| 675 | for key, value, kwargs in ( |
| 676 | # Core connection args should definitely not get overwritten! |
| 677 | # NOTE: recall that these keys are the SSHClient.connect() |
| 678 | # kwarg names, NOT our own config/kwarg names! |
| 679 | ("hostname", "nothost", {}), |
| 680 | ("port", 17, {}), |
| 681 | ("username", "zerocool", {}), |
| 682 | # These might arguably still be allowed to work, but let's head |
| 683 | # off confusion anyways. |
| 684 | ("timeout", 100, {"connect_timeout": 25}), |
| 685 | ): |
| 686 | try: |
| 687 | Connection( |
| 688 | "host", connect_kwargs={key: value}, **kwargs |
| 689 | ).open() |
| 690 | except ValueError as e: |
| 691 | err = "Refusing to be ambiguous: connect() kwarg '{}' was given both via regular arg and via connect_kwargs!" # noqa |
| 692 | assert str(e) == err.format(key) |
| 693 | else: |
| 694 | assert False, "Did not raise ValueError!" |
| 695 | |
| 696 | def connect_kwargs_protection_not_tripped_by_defaults(self, client): |
| 697 | Connection("host", connect_kwargs={"timeout": 300}).open() |
| 698 | client.connect.assert_called_with( |
| 699 | username=get_local_user(), |
| 700 | hostname="host", |
| 701 | port=22, |
| 702 | timeout=300, |
| 703 | ) |
| 704 | |
| 705 | def submits_connect_timeout(self, client): |
| 706 | Connection("host", connect_timeout=27).open() |
| 707 | client.connect.assert_called_with( |
| 708 | username=get_local_user(), hostname="host", port=22, timeout=27 |
| 709 | ) |
| 710 |
no outgoing calls
no test coverage detected