def test_login(self): mock_response = mock.Mock() mock_response.json.return_value = {'access_token': 'abc123'} mock_session = mock.Mock() mock_session.get.return_value = mock_response test_session = Session('client', 'client_secret', mock_session) test_session.login('user', 'user_secret') mock_session.get.assert_called_once() mock_session.headers.update.assert_called_once_with({'Authorization': 'Bearer abc123'})
def setUp(self): self.mock_response = mock.Mock() self.mock_session = mock.Mock() self.session = Session('client', 'client_secret', self.mock_session)
def test_create_empty_session(self): test_session = Session() self.assertFalse(test_session.has_oauth_details())
def test_login_empty_session(self): test_session = Session() self.assertRaises(ConnectionError, test_session.login, 'user', 'secret')
def test_create_session(self): test_session = Session('client', 'client_secret') self.assertTrue(test_session.has_oauth_details())