def setUp(self): self.listener = ExecutionListener({}) self.response = Response() self.response.cookies.update({'username': '******', 'sessionid': 'abcd'}) self.context = Context('http://localhost') self.context.headers['Cookie'] = 'name="John Doe"; sessionid=xyz'
def setUp(self): self.listener = ExecutionListener({}) self.response = Response() self.response.cookies.update({ 'username': '******', 'sessionid': 'abcd' }) self.context = Context('http://localhost') self.context.headers['Cookie'] = 'name="John Doe"; sessionid=xyz'
class TestExecutionListenerSetCookies(unittest.TestCase): def setUp(self): self.listener = ExecutionListener({}) self.response = Response() self.response.cookies.update({ 'username': '******', 'sessionid': 'abcd' }) self.context = Context('http://localhost') self.context.headers['Cookie'] = 'name="John Doe"; sessionid=xyz' def test_auto(self): self.listener.cfg['set_cookies'] = 'auto' self.listener.response_returned(self.context, self.response) self.assertEqual(self.context.headers['Cookie'], 'name="John Doe"; sessionid=abcd; username=john') @patch('http_prompt.cli.click.confirm') def test_ask_and_yes(self, confirm_mock): confirm_mock.return_value = True self.listener.cfg['set_cookies'] = 'ask' self.listener.response_returned(self.context, self.response) self.assertEqual(self.context.headers['Cookie'], 'name="John Doe"; sessionid=abcd; username=john') @patch('http_prompt.cli.click.confirm') def test_ask_and_no(self, confirm_mock): confirm_mock.return_value = False self.listener.cfg['set_cookies'] = 'ask' self.listener.response_returned(self.context, self.response) self.assertEqual(self.context.headers['Cookie'], 'name="John Doe"; sessionid=xyz') def test_off(self): self.listener.cfg['set_cookies'] = 'off' self.listener.response_returned(self.context, self.response) self.assertEqual(self.context.headers['Cookie'], 'name="John Doe"; sessionid=xyz')