
    Ei(                     8	   d Z ddlZddlmc mZ ddlZddl	Z	ddl
mZ ddlmZmZ  ee      j                   j                   Zej$                  j'                  dedz        Zg ZdZeeuZeZerej2                  ZdZeeuZeZesB ej:                  defdeef      d	 ej<                         v s ej>                  e      r ej@                  e      nd	 ej@                  e      d
z  Z!dde!iz  Z"ejG                  e"       er ej:                  defdeef      d	 ej<                         v s ej>                  e      r ej@                  e      nd	 ej@                  e       ej@                  e      dz  Z$dde$iz  Z%ejG                  e%        ejL                  ed      i z  Z'dde'iz  Z( e) ejT                  e(            dxZxZxZxZxZxZZej$                  jW                  e      Z,e,e	jZ                  d<   ej2                  j]                  e,       dZ/ e       Z0e,e0_,        e0e	jZ                  e/<   ej$                  j'                  e/ dedz  g       Z1g ZdZe1euZeZere1j2                  ZdZeeuZeZesB ej:                  defde1ef      d ej<                         v s ej>                  e1      r ej@                  e1      nd ej@                  e      d
z  Z!dde!iz  Z"ejG                  e"       er ej:                  defdeef      d ej<                         v s ej>                  e1      r ej@                  e1      nd ej@                  e       ej@                  e      dz  Z$dde$iz  Z%ejG                  e%        ejL                  ed      i z  Z'dde'iz  Z( e) ejT                  e(            dxZxZxZxZxZxZZej$                  jW                  e1      Z2e/e2_3        e,e	jZ                  e/ d<   e2e	jZ                  d<   e1j2                  j]                  e2       e2jh                  Z4e2jj                  Z5e2jl                  Z6e2jn                  Z7e2jp                  Z8 G d d      Z9 G d d      Z: G d d      Z; G d  d!      Z< G d" d#      Z=y)$u    auto_approve.py 단위 테스트    N)Path)	MagicMockpatchhook_scorerzhook_scorer.pyis not)z%(py2)s is not %(py5)sspec_hs)py2py5z%(py7)spy7)z5%(py11)s
{%(py11)s = %(py9)s.loader
} is not %(py14)s)py9py11py14z%(py16)spy16zassert %(py19)spy19content_pipeline_pkgz.auto_approvezauto_approve.py)submodule_search_locationsspec_aaz.hook_scorerauto_approvec                       e Zd Zd Zd Zd Zy)TestCheckCopyrightSafec                    d}t        |      }d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  t               rt        j                  t               ndt        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}x}x}}y	)
u   '자체 작성' → True   자체 작성Tisz0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} is %(py7)scheck_copyright_safepy0r
   py4r   assert %(py9)sr   N	r   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationself@py_assert1@py_assert3@py_assert6@py_assert5@py_format8@py_format10s          ?/home/jay/workspace/content-pipeline/tests/test_auto_approve.pytest_check_copyright_safe_passz5TestCheckCopyrightSafe.test_check_copyright_safe_pass2   s    $3<#O4<<4<<<<4<<<<<<#<<<#<<<O<<<4<<<<<<<<<<    c                    d}t        |      }d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  t               rt        j                  t               ndt        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}x}x}}y	)
u   '블로그 복사' → Falseu   블로그 복사Fr   r   r   r   r!   r   Nr"   r+   s          r3   test_check_copyright_safe_failz5TestCheckCopyrightSafe.test_check_copyright_safe_fail6   s    $6@#$67@5@75@@@@75@@@@@@#@@@#@@@$6@@@7@@@5@@@@@@@r5   c                    d}t        |      }d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  t               rt        j                  t               ndt        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}x}x}}y	)
u!   '금융감독원 공시' → Trueu   금융감독원 공시Tr   r   r   r   r!   r   Nr"   r+   s          r3   test_check_copyright_safe_govz4TestCheckCopyrightSafe.test_check_copyright_safe_gov:   s    $<E#$<=EE=EEEE=EEEEEE#EEE#EEE$<EEE=EEEEEEEEEEr5   N)__name__
__module____qualname__r4   r7   r9    r5   r3   r   r   1   s    =AFr5   r   c                       e Zd Zd Zd Zy)TestCheckBlacklistc                    d}t        |      \  }}d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}}g }||k(  }|st        j                  d
|fd||f      dt        j                         v st        j
                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}}y	)u0   정상 텍스트 → 통과(True), 위반 없음u1   수수료 구조가 바뀐다는 소식입니다.Tr   z%(py0)s is %(py3)spassedr   py3assert %(py5)sr   N)==)z%(py0)s == %(py3)s
violations)	check_blacklistr#   r$   r%   r&   r'   r(   r)   r*   )r,   textrB   rG   @py_assert2r-   @py_format4@py_format6s           r3   test_check_blacklist_clearz-TestCheckBlacklist.test_check_blacklist_clearB   s    B,T2
v~vvvzRzRzzRr5   c                    d}t        |      \  }}d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}}t        |      }d
}||kD  }	|	st        j                  d|	fd||f      dt        j                         v st        j
                  t              rt        j                  t              nddt        j                         v st        j
                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }
dd|
iz  }t        t        j                  |            d	x}x}	}y	)uE   블랙리스트 키워드('삼성생명') 포함 → 미통과(False)u#   삼성생명 상품이 최악이다Fr   rA   rB   rC   rE   r   Nr   )>)z/%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} > %(py6)slenrG   )r   py1rD   py6zassert %(py8)spy8)
rH   r#   r$   r%   r&   r'   r(   r)   r*   rP   )r,   rI   rB   rG   rJ   r-   rK   rL   r0   @py_assert4@py_format7@py_format9s               r3   test_check_blacklist_violationz1TestCheckBlacklist.test_check_blacklist_violationI   s    4,T2
vvvv:""""""""""""s"""s"""""":""":"""""""""""""r5   N)r:   r;   r<   rM   rW   r=   r5   r3   r?   r?   A   s     #r5   r?   c                       e Zd Zd Zd Zy)TestCheckTemplateMatchc                    d}t        |      \  }}d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}}d	}||u}|st        j                  d
|fd||f      dt        j                         v st        j
                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}}y	)uI   tpl-01 required_keywords('수수료', '변화') 포함 텍스트 → Trueu;   수수료 구조의 변화가 업계를 강타하고 있다Tr   rA   matchedrC   rE   r   Nr   )z%(py0)s is not %(py3)stpl_id	check_template_matchr#   r$   r%   r&   r'   r(   r)   r*   r,   rI   r[   r\   rJ   r-   rK   rL   s           r3   test_check_template_matchz0TestCheckTemplateMatch.test_check_template_matchT   s    L.t4w$w$ww$!!vT!!!!vT!!!!!!v!!!v!!!T!!!!!!!r5   c                    d}t        |      \  }}d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}}d	}||u }|st        j                  d|fd||f      d
t        j                         v st        j
                  |      rt        j                  |      nd
t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}}y	)u4   템플릿 키워드와 무관한 텍스트 → FalseuB   오늘 점심은 김치찌개를 먹었습니다. 맛있었어요.Fr   rA   r[   rC   rE   r   Nr\   r]   r_   s           r3   test_check_template_no_matchz3TestCheckTemplateMatch.test_check_template_no_match[   s    S.t4w%w%ww%v~vvvr5   N)r:   r;   r<   r`   rb   r=   r5   r3   rY   rY   S   s    "r5   rY   c                       e Zd Zd Zy)TestCheckNoDuplicatec                 ,   d}t        j                  t        dt                     5  t	        |      \  }}ddd       d}|u }|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      d	z  }d
d|iz  }t        t        j                  |            dx}}d}|u }|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      d	z  }d
d|iz  }t        t        j                  |            dx}}y# 1 sw Y   UxY w)u>   최근 기록이 없는 새 콘텐츠 → True (중복 아님)u1   완전히 새로운 고유한 콘텐츠 XYZ_99999_load_recent_hashesreturn_valueNTr   rA   rB   rC   rE   r   dup_hash)r   objectr   setcheck_no_duplicater#   r$   r%   r&   r'   r(   r)   r*   )r,   rI   rB   ri   rJ   r-   rK   rL   s           r3   test_check_no_duplicate_freshz2TestCheckNoDuplicate.test_check_no_duplicate_freshf   s    B\\,(=CER 	81$7FH	8v~vvvx4x4xx4	8 	8s   F		FN)r:   r;   r<   rm   r=   r5   r3   rd   rd   e   s     r5   rd   c                       e Zd Zd Zd Zd Zy)TestApprovec                     dddgdgS )u1   테스트용 인메모리 템플릿 목록 반환ztpl-testu	   수수료u   변화)idrequired_keywordsr=   )r,   s    r3   _make_templateszTestApprove._make_templatess   s     !&18%<
 	
r5   c                    d}t        j                  t        d| j                               5  t        j                  t        dt	                     5  t        |d      }ddd       ddd       j                  }d}||u }|st        j                  d	|fd
||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                  }d}||u }|st        j                  d	|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                   }d}||u }|st        j                  d	|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j"                  }d}||u }|st        j                  d	|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j$                  }d}||u }|st        j                  d	|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}y# 1 sw Y   xY w# 1 sw Y   xY w)u(   모든 조건 통과 → all_passed=Trueua   수수료 구조의 변화, 도대체 왜 이러는지 모르겠다. 안 하면 진짜 큰일남._load_templatesrg   rf   r   sourceNTr   )zB%(py2)s
{%(py2)s = %(py0)s.condition_2_copyright_safe
} is %(py5)sresultr   r
   r   assert %(py7)sr   )z=%(py2)s
{%(py2)s = %(py0)s.condition_3_hook_pass
} is %(py5)szC%(py2)s
{%(py2)s = %(py0)s.condition_4_blacklist_clear
} is %(py5)s)z@%(py2)s
{%(py2)s = %(py0)s.condition_5_no_duplicate
} is %(py5)sz2%(py2)s
{%(py2)s = %(py0)s.all_passed
} is %(py5)s)r   rj   r   rs   rk   approvecondition_2_copyright_safer#   r$   r%   r&   r'   r(   r)   r*   condition_3_hook_passcondition_4_blacklist_clearcondition_5_no_duplicate
all_passedr,   rI   rx   r-   rT   r.   rL   r1   s           r3   test_approve_all_passz!TestApprove.test_approve_all_pass|   s    sLL'8tG[G[G]^	;LL'<35Q	; T/:F		; 	; 008D80D88880D888888v888v8880888D8888888++3t3+t3333+t333333v333v333+333t3333333119T91T99991T999999v999v9991999T9999999..6$6.$6666.$666666v666v666.666$6666666  (D( D(((( D((((((v(((v((( (((D(((((((	; 	; 	; 	;s#   %Q!Q Q!Q	Q!!Q+c                 2   d}t        j                  t        d| j                               5  t        j                  t        dt	                     5  t        |d      }ddd       ddd       j                  }d}||u }|st        j                  d	|fd
||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                  }d}||u }|st        j                  d	|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}y# 1 sw Y   xY w# 1 sw Y   xY w)u>   블랙리스트 저촉 → all_passed=False, condition_4=Falseuh   수수료 변화: 삼성생명 관련 안내입니다. 도대체 왜 이러는지, 안 하면 큰일남.ru   rg   rf   r   rv   NFr   r{   rx   ry   rz   r   r|   )r   rj   r   rs   rk   r}   r   r#   r$   r%   r&   r'   r(   r)   r*   r   r   s           r3   test_approve_blacklist_failz'TestApprove.test_approve_blacklist_fail   sR   yLL'8tG[G[G]^	;LL'<35Q	; T/:F		; 	; 11:U:1U::::1U::::::v:::v:::1:::U:::::::  )E) E)))) E))))))v)))v))) )))E)))))))	; 	; 	; 	;s#   %HG? H?H		HHN)r:   r;   r<   rs   r   r   r=   r5   r3   ro   ro   r   s    
) 
*r5   ro   )>__doc__builtinsr%   _pytest.assertion.rewrite	assertionrewriter#   importlib.util	importlibsyspathlibr   unittest.mockr   r   __file__parentPIPELINE_DIRutilspec_from_file_locationr	   r-   rT   r.   @py_assert0loader@py_assert10@py_assert13@py_assert12r$   r&   r'   r(   rL   r1   append@py_format15@py_format17_format_boolop@py_format18@py_format20r)   r*   module_from_specr   modulesexec_module	_pkg_namepkg_mockr   r   __package__r   rH   r^   rl   r}   r   r?   rY   rd   ro   r=   r5   r3   <module>r      s3   &     
  *H~$$++ ..
0
0<"22 :d 9wd 9w~~ 9T 9~T9 9 9 9wd 9 9 9 9 9w 9 9 9w 9 9 9d 9 9 9 9 9 9 9~T 9 9 9 9 9w 9 9 9w 9 9 9~ 9 9T 9 9 9 9 9 9 9 9 9 9 9 9 9nn--g6(M    ; ' #	;" !I  ..
0
0k$$! 1 
 :d 9wd 9w~~ 9T 9~T9 9 9 9wd 9 9 9 9 9w 9 9 9w 9 9 9d 9 9 9 9 9 9 9~T 9 9 9 9 9w 9 9 9w 9 9 9~ 9 9T 9 9 9 9 9 9 9 9 9 9 9 9 9~~..w7$  +6yk& '*N    < ( $88 ..#88 !44 



F F # #$ $   $* $*r5   