From 39d5a664ec805eb82081110299437b61c3b08da2 Mon Sep 17 00:00:00 2001 From: Felix Sargent Date: Thu, 30 Aug 2018 12:20:06 -0400 Subject: [PATCH] Add Logout method. --- terminalone/connection.py | 5 +++++ tests/test_oauth2.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/terminalone/connection.py b/terminalone/connection.py index d0d14c8..4ece411 100644 --- a/terminalone/connection.py +++ b/terminalone/connection.py @@ -106,6 +106,11 @@ def _auth_session_id(self, session_id, api_key, expires=None): ) self._check_session() + def logout(self): + """Remove all session information.""" + self.session.headers['Authorization'] = None + self.session.cookies['adama_session'] = None + def fetch_resource_owner_password_token(self, username, password, client_id, client_secret): """Authenticate using OAuth2. diff --git a/tests/test_oauth2.py b/tests/test_oauth2.py index 7d2e975..79f07e1 100644 --- a/tests/test_oauth2.py +++ b/tests/test_oauth2.py @@ -34,3 +34,10 @@ def setUp(self): def test_minimum_creds_for_oauth2(self): """Test Minimum Credentials.""" self.assertEqual(self.t1.auth_params['method'], 'oauth2-resourceowner') + + @responses.activate + def test_logout(self): + """Test if logout removes credentials.""" + self.assertIsNotNone(self.t1.session.headers['Authorization']) + self.t1.logout() + self.assertIsNone(self.t1.session.headers['Authorization'])