File manager - Edit - /usr/local/CyberPanel/lib/python3.10/site-packages/django/test/__pycache__/testcases.cpython-310.pyc
Back
o �h � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m Z d dlmZ d dl m Z mZ d dl mZ d dlmZ d dlmZ d dlmZ d d lmZmZmZmZmZmZmZ d d lmZ d dl m!Z!m"Z" d dl#m$Z$ d d l%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9 d dl:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZFmGZG d dlHmIZI d dlJmKZKmLZL d dlMmNZNmOZO d dlPmQZQ d dlRmSZSmTZTmUZUmVZVmWZW d d lXmYZYmZZZ d d!l[m\Z\ d d"l]m^Z^ d d#l_m`Z` e�ad$�Zbd%Zcd&d'� Zdd(d)� ZeG d*d+� d+eS�ZfG d,d-� d-�ZgG d.d/� d/eg�ZhG d0d1� d1ei�ZjG d2d3� d3�ZkG d4d5� d5�ZlG d6d7� d7ejm�ZnG d8d9� d9en�ZodXd:d;�ZpG d<d=� d=�ZqG d>d?� d?eo�ZmG d@dA� dA�ZrdBdC� ZsdDdE� ZtdFdG� ZudHdI� ZvG dJdK� dKe9�ZwG dLdM� dMe/�ZxG dNdO� dOex�ZyG dPdQ� dQex�ZzG dRdS� dSej{�Z|G dTdU� dUeo�Z}G dVdW� dW�Z~dS )Y� N)�Counter)�contextmanager)�copy�deepcopy)�get_close_matches��wraps)�_DebugResult)� safe_repr)� parse_qsl�unquote� urlencode�urljoin�urlparse�urlsplit� urlunparse)�url2pathname)� async_to_sync�iscoroutinefunction)�apps)�settings)�mail)�ImproperlyConfigured�ValidationError)�locks)�WSGIHandler� get_path_info)�call_command)�no_style)�emit_post_migrate_signal)�ThreadedWSGIServer�WSGIRequestHandler)�setting_changed)�DEFAULT_DB_ALIAS� connection�connections�transaction)� CharField)� QueryDict)�split_domain_port� validate_host)�HttpResponseBase)�AsyncClient�Client)�HTMLParseError� parse_html)�template_rendered)�CaptureQueriesContext�ContextList�compare_xml�modify_settings�override_settings)�RemovedInDjango50Warning�RemovedInDjango51Warning)� classproperty)�PY310)�servezdjango.test)�TestCase�TransactionTestCase�SimpleTestCase�skipIfDBFeature�skipUnlessDBFeaturec C s t | t�s| g} | S )z.Put value into a list if it's not already one.)� isinstance�list)�value� rC �K/usr/local/CyberPanel/lib/python3.10/site-packages/django/test/testcases.py�to_listH s rE c C sT zt |�}W |S ty) } zd||f }| �| �||�� W Y d }~|S d }~ww )Nz%s %s)r/ r. �fail�_formatMessage)�self�html�user_msg�msg�dom�e�standardMsgrC rC rD �assert_and_parse_htmlO s ���rO c s( e Zd Z� fdd�Z� fdd�Z� ZS )�_AssertNumQueriesContextc s || _ || _t� �|� d S �N)� test_case�num�super�__init__)rH rR rS r$ �� __class__rC rD rU Y s z!_AssertNumQueriesContext.__init__c s` t � �|||� |d urd S t| �}| j�|| jd|| jd�dd� t| jdd�D ��f � d S )Nz:%d queries executed, %d expected Captured queries were: %s� c s s$ � | ] \}}d ||d f V qdS )z%d. %s�sqlNrC )�.0�i�queryrC rC rD � <genexpr>j s � � �z4_AssertNumQueriesContext.__exit__.<locals>.<genexpr>� )�start) rT �__exit__�lenrR �assertEqualrS �join� enumerate�captured_queries)rH �exc_type� exc_value� traceback�executedrV rC rD r` ^ s ����z!_AssertNumQueriesContext.__exit__)�__name__� __module__�__qualname__rU r` � __classcell__rC rC rV rD rP X s rP c @ s6 e Zd Zd dd�Zdd� Zdd� Zd d � Zdd� ZdS )�_AssertTemplateUsedContext� Nc C s0 || _ || _|| _|| _g | _g | _t� | _d S rQ )rR � template_name� msg_prefix�count�rendered_templates�rendered_template_namesr2 �context)rH rR rp rq rr rC rC rD rU s s z#_AssertTemplateUsedContext.__init__c K s. | j �|� | j�|j� | j�t|�� d S rQ )rs �appendrt �nameru r )rH �sender�signal�templateru �kwargsrC rC rD �on_template_render} s z-_AssertTemplateUsedContext.on_template_renderc C s | j �| j| j| j| j� d S rQ )rR �_assert_template_usedrp rt rq rr �rH rC rC rD �test� s �z_AssertTemplateUsedContext.testc C s t �| j� | S rQ )r0 �connectr| r~ rC rC rD � __enter__� s z$_AssertTemplateUsedContext.__enter__c C s$ t �| j� |d urd S | �� d S rQ )r0 � disconnectr| r )rH rf rg rh rC rC rD r` � s z#_AssertTemplateUsedContext.__exit__)ro N)rj rk rl rU r| r r� r` rC rC rC rD rn r s rn c @ s e Zd Zdd� ZdS )�_AssertTemplateNotUsedContextc C s* | j �| j| jv | j� d| j� d�� d S )Nz Template 'z1' was used unexpectedly in rendering the response)rR �assertFalserp rt rq r~ rC rC rD r � s �z"_AssertTemplateNotUsedContext.testN)rj rk rl r rC rC rC rD r� � s r� c @ s e Zd ZdS )�DatabaseOperationForbiddenN)rj rk rl rC rC rC rD r� � s r� c @ s e Zd Zdd� Zdd� ZdS )�_DatabaseFailurec C � || _ || _d S rQ )�wrapped�message)rH r� r� rC rC rD rU � � z_DatabaseFailure.__init__c C s t | j��rQ )r� r� r~ rC rC rD �__call__� � z_DatabaseFailure.__call__N)rj rk rl rU r� rC rC rC rD r� � s r� c @ s6 e Zd Zed dd��Ze d dd��Zedd� �ZdS ) �!_AssertFormErrorDeprecationHelperro c C s� d|�d|�d�}t j|tdd� |r|� d�nd}|jdur$t|j�ng }|s0| �|� d �� d } t|�D ]\} }||vr?q6d} | j|| |||d� q6| s\| �|� d |� d�� dS dS )a< Search through all the rendered contexts of the `response` for a form named `form` then dispatch to the new assertFormError() using that instance. If multiple contexts contain the form, they're all checked in order and any failure will abort (this matches the old behavior). ztPassing response to assertFormError() is deprecated. Use the form object directly: assertFormError(response.context[�], �, ...)� �� stacklevel�: ro N�8Response did not use any contexts to render the responseFT)rq z The form '�%' was not used to render the response)�warnings�warnr6 ru rE rF rd �assertFormError)rH �response�form�field�errorsrq �warning_msg�full_msg_prefix�contexts� found_formr[ ru rC rC rD r� � s0 ������z1_AssertFormErrorDeprecationHelper.assertFormErrorc C s� d|�d|�d�}t j|tdd� |r|� d�nd}|jdur$t|j�ng } | s0| �|� d �� d } t| �D ]\}}||vsEt|| d�sFq6d} | �|| ||||� q6| sc| �|� d |� d�� dS dS )a Search for a formset named "formset" in the "response" and dispatch to the new assertFormSetError() using that instance. If the name is found in multiple contexts they're all checked in order and any failure will abort the test. z}Passing response to assertFormSetError() is deprecated. Use the formset object directly: assertFormSetError(response.context[r� r� r� r� r� ro Nr� F�formsTz The formset 'r� ) r� r� r6 ru rE rF rd �hasattr�assertFormSetError) rH r� �formset� form_indexr� r� rq r� r� r� � found_formsetr[ ru rC rC rD r� � s4 �������z4_AssertFormErrorDeprecationHelper.assertFormSetErrorc s t ��� �fdd��}|S )z� Replace the decorated method with a new one that inspects the passed args/kwargs and dispatch to the old implementation (with deprecation warning) when it detects the old signature. c s t � �j�}t�|�}z|j| g|�R i |��}W n ty- �| g|�R i |�� Y S w t���}z|j| g|�R i |��}W n tyU || g|�R i |�� Y S w |jd |jd ksbJ �t|jd d�ru|| g|�R i |��S t|jd t �r�t |j� d����| g|�R i |��S )Nr^ ru �D() is only usable on responses fetched using the Django test Client.)�getattrrj �inspect� signature�bind� TypeError�argsr� r@ r+ � ValueError)rH r� r{ � old_method� old_signature�old_bound_args� new_signature�new_bound_args��cls� new_methodrC rD �patched_method� s. � � � �zI_AssertFormErrorDeprecationHelper.patch_signature.<locals>.patched_methodr )r� r� r� rC r� rD �patch_signature� s #z1_AssertFormErrorDeprecationHelper.patch_signatureN�ro )rj rk rl �staticmethodr� r� �classmethodr� rC rC rC rD r� � s !�%r� c s� e Zd ZeZeZdZdZe � Z dZg d�Ze � fdd��Ze dd� �Ze dd � �Ze d d� �ZdUdd �Zdd� ZdV� fdd� Zdd� Zdd� Zdd� Zdd� Z dWdd �ZdXd!d"�Zd#d$� Z dYd%d&�Z dZd'd(�Zd)d*� Zd+d,� Ze j!dXd-d.��Z"d/d0� Z#e j!dXd1d2��Z$d3d4� Z%d5d6� Z& d[d7d8�Z'd\d9d:�Z(e)d;d<� �Z*d=d>� Z+d?d@� Z,dAdB� Z-e.s�e)dUdCdD��Z/ d\dEdF�Z0dUdGdH�Z1dUdIdJ�Z2d]dKdL�Z3dUdMdN�Z4dUdOdP�Z5dUdQdR�Z6dUdSdT�Z7� Z8S )^r= Nz�Database %(operation)s to %(alias)r are not allowed in SimpleTestCase subclasses. Either subclass TestCase or TransactionTestCase to ensure proper test isolation or add %(alias)r to %(test)s.databases to silence this failure.))r� r% )�temporary_connectionr% )�cursor�queries)�chunked_cursorr� c s| t � �� | jrtdi | j��| _| j�� | �| jj� | jr2t | j�| _ | j �� | �| j j� | �� | �| j� d S )NrC ) rT � setUpClass�_overridden_settingsr5 �_cls_overridden_context�enable�addClassCleanup�disable�_modified_settingsr4 �_cls_modified_context�_add_databases_failures�_remove_databases_failures�r� rV rC rD r� : s zSimpleTestCase.setUpClassc C sl | j dkr tt�S | j D ]$}|tvr0d| j| j|f }t|tt��}|r,|d|d 7 }t|��qt| j �S )N�__all__zH%s.%s.databases refers to %r which is not defined in settings.DATABASES.z Did you mean %r?r )� databases� frozensetr% rk rl r rA r )r� �aliasr� � close_matchesrC rC rD �_validate_databasesH s"