def test_success_with_write_func(self, session, client):
        token = {'token': 'yes'}

        token_read_func = MagicMock()
        token_read_func.return_value = token

        token_write_func = MagicMock()

        client.return_value = 'returned client'
        self.assertEqual(
            'returned client',
            auth.client_from_access_functions('*****@*****.**',
                                              token_read_func,
                                              token_write_func))

        session.assert_called_once_with('*****@*****.**',
                                        token=token,
                                        auto_refresh_url=_,
                                        auto_refresh_kwargs=_,
                                        token_updater=_)
        token_read_func.assert_called_once()

        # Verify that the write function is called when the updater is called
        session_call = session.mock_calls[0]
        token_updater = session_call.kwargs['token_updater']
        token_write_func.assert_not_called()
        token_updater()
        token_write_func.assert_called_once()
示例#2
0
    def test_success_with_write_func_metadata_aware_token(
            self, session, client):
        token = {'creation_timestamp': MOCK_NOW, 'token': {'token': 'yes'}}

        token_read_func = MagicMock()
        token_read_func.return_value = token

        token_writes = []

        def token_write_func(token):
            token_writes.append(token)

        client.return_value = 'returned client'
        self.assertEqual(
            'returned client',
            auth.client_from_access_functions('*****@*****.**',
                                              token_read_func,
                                              token_write_func))

        session.assert_called_once_with('*****@*****.**',
                                        token=token['token'],
                                        token_endpoint=_,
                                        update_token=_)
        token_read_func.assert_called_once()

        # Verify that the write function is called when the updater is called
        session_call = session.mock_calls[0]
        update_token = session_call[2]['update_token']

        update_token(token['token'])
        self.assertEqual([token], token_writes)
示例#3
0
    def test_success_with_write_func(self, session, client):
        token = {'token': 'yes'}

        token_read_func = MagicMock()
        token_read_func.return_value = token

        token_write_func = MagicMock()

        client.return_value = 'returned client'
        self.assertEqual(
            'returned client',
            auth.client_from_access_functions('*****@*****.**',
                                              token_read_func,
                                              token_write_func))

        session.assert_called_once_with('*****@*****.**',
                                        token=token,
                                        token_endpoint=_,
                                        update_token=_)
        token_read_func.assert_called_once()

        # Verify that the write function is called when the updater is called
        session_call = session.mock_calls[0]
        update_token = session_call[2]['update_token']
        token_write_func.assert_not_called()
        update_token()
        token_write_func.assert_called_once()
示例#4
0
    def test_success_no_write_func(self, session, client):
        token = {'token': 'yes'}

        token_read_func = MagicMock()
        token_read_func.return_value = token

        client.return_value = 'returned client'
        self.assertEqual(
            'returned client',
            auth.client_from_access_functions('*****@*****.**',
                                              token_read_func))

        session.assert_called_once_with('*****@*****.**',
                                        token=token,
                                        token_endpoint=_)
        token_read_func.assert_called_once()
示例#5
0
    def test_success_with_enforce_enums_enabled(self, async_session,
                                                sync_session, client):
        token = {'token': 'yes'}

        token_read_func = MagicMock()
        token_read_func.return_value = token

        token_writes = []

        def token_write_func(token):
            token_writes.append(token)

        client.return_value = 'returned client'
        self.assertEqual(
            'returned client',
            auth.client_from_access_functions('*****@*****.**',
                                              token_read_func,
                                              token_write_func))

        client.assert_called_once_with('*****@*****.**',
                                       _,
                                       token_metadata=_,
                                       enforce_enums=True)