示例#1
0
    def test_params(self):
        """Parameters should be set correctly inside the class using all parameters."""
        client = Client(
            base_url=self.cfixt.base_url, login_uri=self.cfixt.login_uri, username=self.cfixt.username,
            password=self.cfixt.password, cert_auth=True, user_crt_file=self.cfixt.user_crt_file,
            user_key_file=self.cfixt.user_key_file,
        )

        # Use the hackity object mangling when dealing with double-underscore values in an object
        self.assertEqual(client._Client__base_url, self.cfixt.base_url)
        self.assertEqual(client._Client__login_uri, self.cfixt.login_uri)
        self.assertEqual(client._Client__username, self.cfixt.username)
        self.assertEqual(client._Client__cert_auth, True)
        self.assertEqual(client._Client__user_crt_file, self.cfixt.user_crt_file)
        self.assertEqual(client._Client__user_key_file, self.cfixt.user_key_file)
        self.assertEqual(client._Client__session.cert, (self.cfixt.user_crt_file, self.cfixt.user_key_file))

        # Make sure all the headers make their way into the internal requests.Session object
        for head in self.cfixt.headers:
            self.assertTrue(head in client._Client__session.headers)
            self.assertEqual(self.cfixt.headers[head], client._Client__session.headers[head])

        # If cert_auth is True, make sure a password header does not exist
        self.assertFalse("password" in client._Client__session.headers)