PK APOCALYPSE V1

APOCALYPSE V1

Current Path : /opt/hc_python/lib/python3.12/site-packages/pyone/__pycache__/
Upload File :
Current File : //opt/hc_python/lib/python3.12/site-packages/pyone/__pycache__/tester.cpython-312.pyc

�

���g����ddlmZddlmZmZddlmZmZddl	mZm
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZej4�d�Zd�ZGd�de�Zy)�)�md5)�load�dumps)�	b64decode�	b64encode)r�loads)�path�)�	OneServer)�pickling_support)�exc_info)�reraise)�OrderedDict)�open)�environc�T�t|d�}t|�}|j�|S)N�rt)rr�close)�fixture_file�f�rets   �;/opt/hc_python/lib/python3.12/site-packages/pyone/tester.py�read_fixture_filer s%���\�4� �A�
�q�'�C��G�G�I��J�c��t|d�}|jt|�j��|j	�y)N�wb)r�write�
json_dumps�encoder)r�objrs   r�write_fixture_filer!'s0���\�4� �A��G�G�J�s�O�"�"�$�%��G�G�Irc�N�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
y)�OneServerTesteraQ
    This class extends the OneServer to facilitate unit testing
    The idea is to be able to "record" fixtures while testing with a live OpenNebula platform.
    Those recordings can later be use in "replay" mode to simulate an OpenNebula platform.
    XMLAPI method calls are recorded as test_base/unit_test/method_signature_instance
    The signature is generated as the md5 of the parameters
    if several calls with the same signature are doing during the same unit test, instance is incremented.
    The order in which calls happen within the same unit_test must be deterministic.
    Nc��|�tjdd�}|�&tjdd�j�dv}|�tjdd�}tj|�rt|�|_nt�|_||_||_	|j|�tj||||fi|��y)N�PYONE_TEST_FIXTURE_FILE�PYONE_TEST_FIXTURE_REPLAY�True)�1�yes�true�PYONE_TEST_FIXTURE_UNIT�init)
r�get�lowerr	�isfiler�	_fixtures�dict�_fixture_replay�
_fixture_file�set_fixture_unit_testr�__init__)�self�uri�sessionr�fixture_unit�timeout�fixture_replay�optionss        rr5zOneServerTester.__init__6s�����"�;�;�'@�$�G�L��!�%�k�k�*E�v�N�T�T�V�Zn�n�N���"�;�;�'@�&�I�L��;�;�|�$�.�|�<�D�N�!�V�D�N� .���)����"�"�<�0����4��g�w�B�'�Brc�v�||jvrt�|j|<|j||_y)z�
        Set the name of the unit test. creates an entry in the fixture tree if it does not exist.
        :param name:
        :return:
        N)r0r1�_fixture_unit_test)r6�names  rr4z%OneServerTester.set_fixture_unit_testPs1���t�~�~�%�#'�6�D�N�N�4� �"&�.�.��"6��rc��t�}t|d��j�}|j|�|j	�S)NT)�	sort_keys)rrr�update�	hexdigest)r6�
methodname�params�
signature_md5�sparmss     r�_fixture_signaturez"OneServerTester._fixture_signature\s;����
��&�4�0�7�7�9�����V�$��&�&�(�(rc��|j||j||�jd�}|std��|S)z�
        returns the next fixture for a given call.
        :param methodname: XMlRPC method
        :param params: the paramters passed
        :return: file name were to store to or read from the fixture data
        rzHCould not read fixture, if the tests changed you must re-record fixtures)r>rH�pop�	Exception)r6rDrErs    r�_get_fixturezOneServerTester._get_fixturebsG���%�%�j�1�$�2I�2I�*�U[�2\�]�a�a�bc�d����f�g�g��
rc��|j||�}||jvrt�|j|<||j|vrg|j||<|j||j|�y)z}
        Will create the fixture for a given call
        :param methodname:
        :param params:
        :return:
        N)rHr>r1�append)r6rDrE�object�	signatures     r�_set_fixturezOneServerTester._set_fixtureqs|���+�+�J�v�>�	��T�4�4�4�04��D�#�#�J�/��D�3�3�J�?�?�;=�D�#�#�J�/�	�:����
�+�I�6�=�=�f�Erc��d}|jr5|j||�}d|vrttt	|d���|S	tj|||�}	|j|||�|S#t$r4}dttt�d��j�i}|�d}~wwxYw#|j|||�wxYw)z�
        Intercepts requests.
        In record mode they are recorded before being returned.
        In replay mode they are read from fixtures instead
        Exceptions are also captured and reraised
        N�	exception�)
r2rLrrrr�_do_requestrKrrr
�decoderQ)r6�methodrErrSs     rrUzOneServerTester._do_request�s���������#�#�F�6�2�C��c�!���y��[�)9�:�;�<��
�
5��+�+�D�&�&�A���!�!�&���4��
���
 ���5���Q�+?�!@�!G�!G�!I��� ���	
 ���!�!�&���4�s$�A2�2	B/�;/B*�*B/�/B2�2Cc��t|�}t|�D]*\}}t|t�s�|j	|�||<�,tj||�S)a�
        Parameters will be used to generate the signature of the method, an md5.
        So we need signatures to be deterministic. There are two sources of randomness
        - Python version, in particular differences in dealing with encodings
        - Unsorted sets.
        This method will add casting transformations to fix those, only required for testing.

        :param params:
        :return: a list of parameters that should generate a deterministic md5 signature.
        )�list�	enumerate�
isinstancer1�_to_ordered_dictr�_cast_parms)r6rE�lparams�i�params     rr]zOneServerTester._cast_parms�sS���v�,��!�'�*�H�A�u��%��&�!�2�2�5�9���
�+��%�%�d�G�4�4rc���t|t�r_tt|j	���}|j	�D]*\}}t|t�s�|j|�||<�,|S)zQ
        deep orders a dictionary
        :param param:
        :return:
        )r[r1r�sorted�itemsr\)r6r`�key�values    rr\z OneServerTester._to_ordered_dict�s\���e�D�!���u�{�{�}� 5�6�E�#�k�k�m�
��U��e�T�*�!%�!6�!6�u�!=�E�#�J�,��rc��y)Ng{�G�z�?��r6s r�server_retry_intervalz%OneServerTester.server_retry_interval�s��rc�^�|js!t|j|j�yy)zQ
        Unpdates the fixture data if we are recording.
        :return:
        N)r2r!r3r0rhs r�server_closezOneServerTester.server_close�s&��
�#�#��t�1�1�4�>�>�B�$r)NNNN)�__name__�
__module__�__qualname__�__doc__r5r4rHrLrQrUr]r\rirkrgrrr#r#,s<���C�4
7�)�
�F�$�45�&� �Crr#N)�hashlibr�jsonrrr�base64rr�pickler�osr	�r�tblibr�sysr
�sixr�collectionsr�gziprr�installrr!r#rgrr�<module>r|sT�� �*�'����"���#����������
]C�i�]Cr

if you don't want to be vaporized in a nuclear explosion, i simply have to become nuclear myself… i am atomic