Your IP : 216.73.216.249


Current Path : /opt/alt/python37/lib/python3.7/site-packages/betamax/fixtures/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/betamax/fixtures/__pycache__/unittest.cpython-37.pyc

B

�ˀX�
�@shdZddlmZyddlZWnek
r8ddlZYnXddlZddlmZdZ	Gdd�dej
�ZdS)	aMinimal :class:`unittest.TestCase` subclass adding Betamax integration.

.. autoclass:: betamax.fixtures.unittest.BetamaxTestCase
    :members:

When using Betamax with unittest, you can use the traditional style of Betamax
covered in the documentation thoroughly, or you can use your fixture methods,
:meth:`unittest.TestCase.setUp` and :meth:`unittest.TestCase.tearDown` to wrap
entire tests in Betamax.

Here's how you might use it:

.. code-block:: python

    from betamax.fixtures import unittest

    from myapi import SessionManager


    class TestMyApi(unittest.BetamaxTestCase):
        def setUp(self):
            # Call BetamaxTestCase's setUp first to get a session
            super(TestMyApi, self).setUp()

            self.manager = SessionManager(self.session)

        def test_all_users(self):
            """Retrieve all users from the API."""
            for user in self.manager:
                # Make assertions or something

Alternatively, if you are subclassing a :class:`requests.Session` to provide
extra functionality, you can do something like this:

.. code-block:: python

    from betamax.fixtures import unittest

    from myapi import Session, SessionManager


    class TestMyApi(unittest.BetamaxTestCase):
        SESSION_CLASS = Session

        # See above ...

�)�absolute_importN�)�recorder)�BetamaxTestCasecs:eZdZdZejZdd�Z�fdd�Z�fdd�Z	�Z
S)rzCBetamax integration for unittest.

    .. versionadded:: 0.5.0
    cCst|d�}|j}d�|j|�S)a!Generates a cassette name for the current test.

        The default format is "%(classname)s.%(testMethodName)s"

        To change the default cassette format, override this method in a
        subclass.

        :returns: Cassette name for the current test.
        :rtype: str
        �	__class__z{0}.{1})�getattrZ_testMethodName�format�__name__)�self�cls�test�r
�J/opt/alt/python37/lib/python3.7/site-packages/betamax/fixtures/unittest.py�generate_cassette_nameJs
z&BetamaxTestCase.generate_cassette_namecs^|�t|jtj��tt|���|��}|��|_	t
j|j	d�|_
|j
�|�|j
�
�dS)aBetamax-ified setUp fixture.

        This will call the superclass' setUp method *first* and then it will
        create a new :class:`requests.Session` and wrap that in a Betamax
        object to record it. At the end of ``setUp``, it will start recording.
        )�sessionN)Z
assertTrue�
issubclass�
SESSION_CLASS�requests�Session�superr�setUprrrZBetamaxZuse_cassette�start)r
Z
cassette_name)rr
rrYs	
zBetamaxTestCase.setUpcstt|���|j��dS)z�Betamax-ified tearDown fixture.

        This will call the superclass' tearDown method *first* and then it
        will stop recording interactions.
        N)rr�tearDownr�stop)r
)rr
rrnszBetamaxTestCase.tearDown)r	�
__module__�__qualname__�__doc__rrrrrr�
__classcell__r
r
)rrr@s
r)r�
__future__rZ	unittest2Zunittest�ImportErrorr�r�__all__ZTestCaserr
r
r
r�<module>/s