Beispiel #1
0
    def test_get_connection_incorrect_network_api(self, connection):
        """ Test get_connection with incorrect network_api response
        """
        socket_path = "little red riding hood"
        module = MagicMock(spec=[
            'fail_json',
        ])
        module._socket_path = socket_path
        module.fail_json.side_effect = TypeError

        connection().get_capabilities.return_value = '{"network_api": "nope"}'

        with self.assertRaises(TypeError):
            nos.get_connection(module)
Beispiel #2
0
    def test_get_connection_new(self, connection):
        """ Test get_connection with new connection
        """
        socket_path = "little red riding hood"
        module = MagicMock(spec=[
            'fail_json',
        ])
        module._socket_path = socket_path

        connection(
        ).get_capabilities.return_value = '{"network_api": "cliconf"}'
        returned_connection = nos.get_connection(module)
        connection.assert_called_with(socket_path)
        self.assertEqual(returned_connection, module.nos_connection)
Beispiel #3
0
 def test_get_connection_established(self):
     """ Test get_connection with established connection
     """
     module = MagicMock()
     connection = nos.get_connection(module)
     self.assertEqual(connection, module.nos_connection)