
    $g3#                     f   d dl Z d dlZd dlmZ d dlmZmZ ddlmZ ddl	m
Z
 ddlmZ  G d	 d
          Zd Ze j                            dddg          d             Zd Ze j                            dddg          d             Ze j                            dddg          d             Zd ZdS )    N)Node)DjangoConnectionFieldDjangoObjectType   )Reporter   )DjangoDebugMiddleware)DjangoDebugc                       e Zd ZdS )contextN)__name__
__module____qualname__     f/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/graphene_django/debug/tests/test_query.pyr   r      s        Dr   r   c                  4   t          d          } |                                  t          d          }|                                  G d dt                     G fddt          j                  }d}d	did
dt          t           j                            d          d d         j                  igid}t          j	        |          }|
                    |t                      t                      g          }|j        rJ |j        |k    sJ d S )NABA	last_nameGriffinc                   (    e Zd Z G d d          ZdS )-test_should_query_field.<locals>.ReporterTypec                       e Zd ZeZefZdZdS )2test_should_query_field.<locals>.ReporterType.Meta__all__Nr   r   r   r   modelr   
interfacesfieldsr   r   r   Metar              EJFFFr   r!   Nr   r   r   r!   r   r   r   ReporterTyper      <        	 	 	 	 	 	 	 	 	 	r   r$   c                   Z    e Zd Z ej                   Z ej        ed          Zd ZdS )&test_should_query_field.<locals>.Query_debugnamec                 >    t           j                                        S Nr   objectsfirstselfinfoargss      r   resolve_reporterz7test_should_query_field.<locals>.Query.resolve_reporter        #))+++r   N	r   r   r   grapheneFieldreporterr
   debugr4   r$   s   r   Queryr'      K        !8>,//{:::	, 	, 	, 	, 	,r   r<   z
        query ReporterQuery {
          reporter {
            lastName
          }
          _debug {
            sql {
              rawSql
            }
          }
        }
    lastNamesqlrawSqlpk   )r9   r(   querycontext_value
middleware)r   saver   r7   
ObjectTypestrr.   order_byrD   Schemaexecuter   r	   errorsdatar1r2r<   rD   expectedschemaresultr$   s          @r   test_should_query_fieldrV      s[   	E	"	"	"BGGIII	I	&	&	&BGGIII    '   , , , , , , ,# , , ,E  'Hc(*:*C*CD*I*I"1"*M*S&T&TUVW H _5)))F^^WYY4I4K4K3L   F };(""""""r   	max_limitd   c           	        	 || _         t          d          }|                                 t          d          }|                                 |j                            |           |j                            |            G d dt
                    	 G 	fddt          j                  }d}d	dd
ddd
dddiigidigidi}t          j        |          }|	                    |t                      t                      g          }|j        rJ t          t          j                            d          d d         j                  }|j        d         d         d         d         |k    sJ d|j        d         d         d         d         v sJ d|j        d         d         d         d         v sJ d|j        d         d         d         d         v sJ d|j        d         d         d         d         v sJ t%          |j        d         d                   dk    sJ |j        d	         |d	         k    sJ d S )Nr   r   r   c                   (    e Zd Z G d d          ZdS )4test_should_query_nested_field.<locals>.ReporterTypec                       e Zd ZeZefZdZdS )9test_should_query_nested_field.<locals>.ReporterType.Metar   Nr   r   r   r   r!   r]   G   r"   r   r!   Nr#   r   r   r   r$   r[   F   r%   r   r$   c                   Z    e Zd Z ej                   Z ej        ed          Zd ZdS )-test_should_query_nested_field.<locals>.Queryr(   r)   c                 >    t           j                                        S r,   r-   r0   s      r   r4   z>test_should_query_nested_field.<locals>.Query.resolve_reporterP   r5   r   Nr6   r;   s   r   r<   r_   L   r=   r   r<   a5  
        query ReporterQuery {
          reporter {
            lastName
            pets { edges { node {
              lastName
              pets { edges { node { lastName } } }
            } } }
          }
          _debug {
            sql {
              rawSql
            }
          }
        }
    r9   edgesnoder>   )r>   petsrC   rE   rA   rB   r(   r?   r   r@   COUNTtests_reporter_petsr   r         )RELAY_CONNECTION_MAX_LIMITr   rH   rc   addr   r7   rI   rL   rM   r   r	   rN   rJ   r.   rK   rD   rO   len
graphene_settingsrW   rQ   rR   r<   rD   rS   rT   rU   r$   s
            @r   test_should_query_nested_fieldrm   ;   s   3<0	E	"	"	"BGGIII	I	&	&	&BGGIIIGKKOOOGKKOOO    '   , , , , , , ,# , , ,E" 	(1%,U8K/L.M$N! !	
 
H _5)))F^^WYY4I4K4K3L   F } ))$//39::E;x '*84====fk(+E215h????? FK$9%$@$CH$MMMMMfk(+E215h????? FK$9%$@$CH$MMMMMv{8$U+,,1111;z"hz&:::::::r   c                  *   t          d          } |                                  t          d          }|                                  G d dt                     G fddt          j                  }d}d	did	digd
dt          t           j                                        j                  igid}t          j	        |          }|
                    |t                      t                      g          }|j        rJ |j        |k    sJ d S )Nr   r   r   c                   (    e Zd Z G d d          ZdS ),test_should_query_list.<locals>.ReporterTypec                       e Zd ZeZefZdZdS )1test_should_query_list.<locals>.ReporterType.Metar   Nr   r   r   r   r!   rr      r"   r   r!   Nr#   r   r   r   r$   rp      r%   r   r$   c                   Z    e Zd Z ej                   Z ej        ed          Zd Z	dS )%test_should_query_list.<locals>.Queryr(   r)   c                 >    t           j                                        S r,   r   r.   allr0   s      r   resolve_all_reportersz;test_should_query_list.<locals>.Query.resolve_all_reporters       #'')))r   N)
r   r   r   r7   Listall_reportersr8   r
   r:   rx   r;   s   r   r<   rt      sK        %l33{:::	* 	* 	* 	* 	*r   r<   z
        query ReporterQuery {
          allReporters {
            lastName
          }
          _debug {
            sql {
              rawSql
            }
          }
        }
    r>   r?   r@   )allReportersr(   rC   rE   )r   rH   r   r7   rI   rJ   r.   rw   rD   rL   rM   r   r	   rN   rO   rP   s          @r   test_should_query_listr}      sZ   	E	"	"	"BGGIII	I	&	&	&BGGIII    '   * * * * * * *# * * *E %e,z9.EFHc(*:*>*>*@*@*F&G&GHIJ H _5)))F^^WYY4I4K4K3L   F };(""""""r   c                 6  	 || _         t          d          }|                                 t          d          }|                                  G d dt                    	 G 	fddt          j                  }d}d	d
dddiigii}t	          j        |          }|                    |t                      t                      g          }|j
        rJ |j        d	         |d	         k    sJ t          |j        d         d                   dk    sJ d|j        d         d         d         d         v sJ t          t          j                                        d d         j                  }|j        d         d         d         d         |k    sJ d S )Nr   r   r   c                   (    e Zd Z G d d          ZdS )2test_should_query_connection.<locals>.ReporterTypec                       e Zd ZeZefZdZdS )7test_should_query_connection.<locals>.ReporterType.Metar   Nr   r   r   r   r!   r      r"   r   r!   Nr#   r   r   r   r$   r      r%   r   r$   c                   P    e Zd Z e           Z ej        ed          Zd Z	dS )+test_should_query_connection.<locals>.Queryr(   r)   c                 >    t           j                                        S r,   rv   r0   s      r   rx   zAtest_should_query_connection.<locals>.Query.resolve_all_reporters   ry   r   N)
r   r   r   r   r{   r7   r8   r
   r:   rx   r;   s   r   r<   r      sJ        --l;;{:::	* 	* 	* 	* 	*r   r<     
        query ReporterQuery {
          allReporters(first:1) {
            edges {
              node {
                lastName
              }
            }
          }
          _debug {
            sql {
              rawSql
            }
          }
        }
    r|   ra   rb   r>   rC   rE   r(   r?   r   rd   r   r@   rB   )rh   r   rH   r   r7   rI   rL   rM   r   r	   rN   rO   rj   rJ   r.   rw   rD   rk   s
            @r   test_should_query_connectionr      s   3<0	E	"	"	"BGGIII	I	&	&	&BGGIII    '   * * * * * * *# * * *E  FZ4G+H*I JKH_5)))F^^WYY4I4K4K3L   F };~&(>*BBBBBv{8$U+,,1111fk(+E215h????? $$&&rr*011E;x '*84======r   c                 F  	
 || _         ddlm	 t          d          }|                                 t          d          }|                                  G d dt
                    
 G 	
fdd	t          j                  }d
}dddddiigii}t          j        |          }|	                    |t                      t                      g          }|j        rJ |j        d         |d         k    sJ t          |j        d         d                   dk    sJ d|j        d         d         d         d         v sJ t          t          j                                        d d         j                  }|j        d         d         d         d         |k    sJ d S )Nr   )DjangoFilterConnectionFieldr   r   r   c                   (    e Zd Z G d d          ZdS )8test_should_query_connectionfilter.<locals>.ReporterTypec                       e Zd ZeZefZdZdS )=test_should_query_connectionfilter.<locals>.ReporterType.Metar   Nr   r   r   r   r!   r      r"   r   r!   Nr#   r   r   r   r$   r      r%   r   r$   c                   z    e Zd Z  dg          Z ej        d           Z ej        ed          Z	d Z
dS )	1test_should_query_connectionfilter.<locals>.Queryr   )r    c                      dS )NSr   )_s    r   <lambda>z:test_should_query_connectionfilter.<locals>.Query.<lambda>   s     r   )resolverr(   r)   c                 >    t           j                                        S r,   rv   r0   s      r   rx   zGtest_should_query_connectionfilter.<locals>.Query.resolve_all_reporters   ry   r   N)r   r   r   r{   r7   Stringsr8   r
   r:   rx   )r   r$   s   r   r<   r      sg        33L+WWWHO^^444{:::	* 	* 	* 	* 	*r   r<   r   r|   ra   rb   r>   rC   rE   r(   r?   r   rd   r   r@   rB   )rh   filterr   r   rH   r   r7   rI   rL   rM   r   r	   rN   rO   rj   rJ   r.   rw   rD   )rl   rW   rQ   rR   r<   rD   rS   rT   rU   r   r$   s            @@r   "test_should_query_connectionfilterr      s   3<0555555	E	"	"	"BGGIII	I	&	&	&BGGIII    '   * * * * * * * *# * * *E  FZ4G+H*I JKH_5)))F^^WYY4I4K4K3L   F };~&(>*BBBBBv{8$U+,,1111fk(+E215h????? $$&&rr*011E;x '*84======r   c                      G d dt                      G fddt          j                  } d}t          j        |           }|                    |t                      t                      g          }|j        sJ t          |j	        d         d	                   sJ |j	        d         d	         d
         }|d         
                    d          dk    sJ d|d         v sJ |d         dk    sJ d S )Nc                   (    e Zd Z G d d          ZdS )3test_should_query_stack_trace.<locals>.ReporterTypec                       e Zd ZeZefZdZdS )8test_should_query_stack_trace.<locals>.ReporterType.Metar   Nr   r   r   r   r!   r     r"   r   r!   Nr#   r   r   r   r$   r     r%   r   r$   c                   Z    e Zd Z ej                   Z ej        ed          Zd ZdS ),test_should_query_stack_trace.<locals>.Queryr(   r)   c                      t          d          )Ncaught stack trace)	Exceptionr0   s      r   r4   z=test_should_query_stack_trace.<locals>.Query.resolve_reporter!  s    0111r   Nr6   r;   s   r   r<   r     sK        !8>,//{:::	2 	2 	2 	2 	2r   r<   z
        query ReporterQuery {
          reporter {
            lastName
          }
          _debug {
            exceptions {
              message
              stack
            }
          }
        }
    rC   rE   r(   
exceptionsr   stack
rB   ztest_query.pymessager   )r   r7   rI   rL   rM   r   r	   rN   rj   rO   count)r<   rD   rT   rU   debug_exceptionr$   s        @r   test_should_query_stack_tracer     sJ       '   2 2 2 2 2 2 2# 2 2 2E _5)))F^^WYY4I4K4K3L   F =v{8$\233333k(+L9!<O7#))$//!3333og666669%)=======r   )pytestr7   graphene.relayr   graphene_djangor   r   tests.modelsr   rG   r	   typesr
   r   rV   markparametrizerm   r}   r   r   r   r   r   r   <module>r      st           C C C C C C C C $ $ $ $ $ $ . . . . . .      	 	 	 	 	 	 	 	(# (# (#V tSk22C; C; 32C;L(# (# (#V tSk22/> /> 32/>d tSk222> 2> 322>j$> $> $> $> $>r   