|
11 | 11 | from unittest import mock |
12 | 12 |
|
13 | 13 | import pytest |
| 14 | +import requests |
14 | 15 | import responses |
15 | 16 | from requests.exceptions import HTTPError |
16 | 17 | from testtools import TestCase |
@@ -138,6 +139,24 @@ def test_versioning(self): |
138 | 139 | self.assertEqual(client.headers["User-Agent"], user_agent) |
139 | 140 | self.assertEqual(client._session.headers["User-Agent"], user_agent) |
140 | 141 |
|
| 142 | + def test_session_passed(self): |
| 143 | + """Test that a passed session is used.""" |
| 144 | + session = requests.Session() |
| 145 | + client = Client( |
| 146 | + base_url=self.cfixt.base_url, |
| 147 | + login_uri=self.cfixt.login_uri, |
| 148 | + username=self.cfixt.username, |
| 149 | + password=self.cfixt.password, |
| 150 | + session=session, |
| 151 | + ) |
| 152 | + self.assertIs(client._session, session) |
| 153 | + |
| 154 | + def test_session_created(self): |
| 155 | + """Test that a session is created if not passed.""" |
| 156 | + # The setUp method already creates a client without a session passed |
| 157 | + self.assertIsInstance(self.client._session, requests.Session) |
| 158 | + self.assertIsNotNone(self.client._session) |
| 159 | + |
141 | 160 | def test_need_crt(self): |
142 | 161 | """Raise an exception without a cert file if cert_auth=True.""" |
143 | 162 | self.assertRaises(KeyError, Client, base_url=self.cfixt.base_url, login_uri=self.cfixt.login_uri, |
|
0 commit comments