@patch('requests.post')
    def test_refresh(self, r_post):
        r_post.return_value = Mock(
            status_code=200,
            text='oauth_token=token2&oauth_token_secret=token_secret2&oauth_session_handle=session'
        )

        credentials = PartnerCredentials(
            consumer_key='key',
            consumer_secret='secret',
            rsa_key="key",
            client_cert=None,
            oauth_token='token',
            oauth_token_secret='token_secret',
            verified=True
        )

        credentials.refresh()

        # Expiry times should be calculated
        state = credentials.state
        self.assertIsNotNone(state.pop("oauth_authorization_expires_at"))
        self.assertIsNotNone(state.pop("oauth_expires_at"))

        self.assertEqual(state, {
            'consumer_key': 'key',
            'consumer_secret': 'secret',
            'oauth_token': 'token2',
            'oauth_token_secret': 'token_secret2',
            'oauth_session_handle': 'session',
            'verified': True
        })
Refresh function gets a new token
dataset/ETHPy150Open freakboy3742/pyxero/tests/auth.py/PartnerCredentialsTest.test_refresh