1818
1919from compliance .config import ComplianceConfig
2020from compliance .fetch import ComplianceFetcher
21+ from compliance .utils .http import BaseSession
22+
23+ import requests
2124
2225
2326class ComplianceFetchTest (unittest .TestCase ):
@@ -30,9 +33,31 @@ def setUp(self):
3033 # unittest.TestCase, we must pass a method in the
3134 # constructor (otherwise, we will get a ValueError). Since we
3235 # don't need this method, passing ``__doc__`` is enough for
33- # building a ComplianceCheck object successfully.
34- self .check = ComplianceFetcher ('__doc__' )
36+ # building a ComplianceFetcher object successfully.
37+ ComplianceFetcher .config = ComplianceConfig ()
38+ self .fetcher = ComplianceFetcher ('__doc__' )
39+ self .fetcher .config .load ()
3540
3641 def test_config (self ):
3742 """Check that the config property returns a ComplianceConfig object."""
38- self .assertIsInstance (self .check .config , ComplianceConfig )
43+ self .assertIsInstance (self .fetcher .config , ComplianceConfig )
44+
45+ def test_session (self ):
46+ """Ensure that a session is constructed correctly."""
47+ # Create a requests.Session
48+ self .assertIsInstance (self .fetcher .session (), requests .Session )
49+ # Recycle session, create a BaseSession and persist it
50+ self .assertIsInstance (
51+ self .fetcher .session (
52+ 'https://foo.bar.com' , ('foo' , 'bar' ), foo = 'FOO' , bar = 'BAR'
53+ ),
54+ BaseSession
55+ )
56+ self .assertEqual (self .fetcher .session ().baseurl , 'https://foo.bar.com' )
57+ self .assertEqual (self .fetcher .session ().auth , ('foo' , 'bar' ))
58+ self .assertEqual (
59+ self .fetcher .session ().headers ['User-Agent' ],
60+ 'your_org-compliance-checks'
61+ )
62+ self .assertEqual (self .fetcher .session ().headers ['foo' ], 'FOO' )
63+ self .assertEqual (self .fetcher .session ().headers ['bar' ], 'BAR' )
0 commit comments