
    D6i                     \    d Z ddlZ	 ddlmZ ej
                  d        Zy# e$ r dZY w xY w)a  
Flask-Dance provides a handy Pytest_ fixture named
``betamax_record_flask_dance`` that wraps Flask-Dance
sessions with Betamax_ to record and replay HTTP requests.
In order to use this fixture, you must install Betamax in your testing
environment. You must also define two other Pytest fixtures:
``app`` and ``flask_dance_sessions``. The ``app`` fixture must
return the Flask app that is being tested, and the
``flask_dance_sessions`` fixture must return the Flask-Dance
session or sessions that should be wrapped using Betamax.

For example:

.. code-block:: python

    from flask_dance.contrib.github import github
    from myapp import app as _app


    @pytest.fixture
    def app():
        return _app


    @pytest.fixture
    def flask_dance_sessions():
        return github

The ``flask_dance_sessions`` fixture can return either a single
session, or a list/tuple of sessions.

To use this fixture, it's generally easiest to decorate your test
with :func:`pytest.mark.usefixtures`, like this:

.. code-block:: python
    :emphasize-lines: 1

    @pytest.mark.usefixtures("betamax_record_flask_dance")
    def test_home_page(app):
        with app.test_client() as client:
            response = client.get("/", base_url="https://example.com")
        assert response.status_code == 200

    N)Betamaxc                     t         st        d      t        |t        t        f      r:t        |      D cg c]"  \  }}||j                  j                   d| f$ c}}n|}||j                  j                  fgg  j                  fd       |j                   fd        j                  fd       |j                   fd        S c c}}w )a>  
    Wraps the specified Flask-Dance sessions with Betamax

    This allows you to record and re-play HTTP requests from Flask-Dance
    sessions. Requires the Betamax library. You must also define a
    `flask_dance_sessions` fixture, that defines the session or sessions
    that should be wrapped with Betamax.
    zHThe `betamax_record_flask_dance` fixture depends on the `betamax` module-c                      D ]@  \  } }t        |       j                  |      }j                  |       |j                          B y N)r   use_cassetteappendstart)sessioncassette_namerecorderbetamax_setup_info	recorderss      ^/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/flask_dance/fixtures/pytest.pywrap_flask_dance_with_betamaxzAbetamax_record_flask_dance.<locals>.wrap_flask_dance_with_betamaxT   sD    &8 	"G]w'44]CHX&NN	    c                  @     j                   d    j                        S r   )before_request_funcsremove)appr   s   r   <lambda>z,betamax_record_flask_dance.<locals>.<lambda>\   s    ((.556ST r   c                 6    D ]  }|j                           | S r   )stop)responser   r   s     r   unwrapz*betamax_record_flask_dance.<locals>.unwrap_   s     ! 	HMMO	r   c                  @     j                   d    j                        S r   )after_request_funcsr   )r   r   s   r   r   z,betamax_record_flask_dance.<locals>.<lambda>e   s    !8!8!>!E!Ef!M r   )r   ImportError
isinstancelisttuple	enumeratenodenamebefore_requestaddfinalizerafter_request)	r   flask_dance_sessionsrequestindexr   r   r   r   r   s	   `    @@@@r   betamax_record_flask_dancer+   6   s     #
 	

 &u6 #,,@"A

 w <<$$%Qug.
 '&(9(9:;I  T 	 
 MNJA
s   'C)__doc__pytestbetamaxr   r   fixturer+    r   r   <module>r1      sF   +Z 
 0 0  Gs   ! ++