Add tests for user-agent with odd sys.argv

There was no test that verified that when sys.argv is an empty
list or when sys.argv[0] is an empty string that the default
user-agent value is constructed as expected.

Change-Id: Iacf1557b6dbf48bf6bfb59d7cfbfec14e4fa8e56
Related-Bug: 1611426
This commit is contained in:
Brant Knudson 2016-08-09 10:43:16 -05:00
parent 80ad3bc11f
commit c9ae7067bd
1 changed files with 17 additions and 0 deletions

View File

@ -13,6 +13,7 @@
import itertools
import json
import logging
import sys
import uuid
import mock
@ -133,6 +134,22 @@ class SessionTests(utils.TestCase):
self.assertTrue(resp.ok)
self.assertRequestHeaderEqual('User-Agent', 'overrides-agent')
# If sys.argv is an empty list, then doesn't fail.
with mock.patch.object(sys, 'argv', []):
session = client_session.Session()
resp = session.get(self.TEST_URL)
self.assertTrue(resp.ok)
self.assertRequestHeaderEqual(
'User-Agent',
client_session.DEFAULT_USER_AGENT)
# If sys.argv[0] is an empty string, then doesn't fail.
with mock.patch.object(sys, 'argv', ['']):
session = client_session.Session()
# NOTE(blk-u): This isn't working right, see bug 1611426
self.assertRaises(exceptions.UnknownConnectionError, session.get,
self.TEST_URL)
def test_http_session_opts(self):
session = client_session.Session(cert='cert.pem', timeout=5,
verify='certs')