
    (<i)                         d Z ddlZddlZddlmZ ddlZej                  j                  dd       ddlm	Z	  G d d      Z
 G d d	      Z G d
 d      Z G d d      Zy)u[   
Tests for generate_org_details.py utility module
하누만 (Hanuman), tester on dev4 team
    N)Pathz /home/jay/workspace/teams/shared)generate_all_sub_team_detailsc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)TestGenerateAllSubTeamDetailsz5Test suite for generate_all_sub_team_details functionc                 "   t        |      }|D cg c]  }d|v sd|v s| }}t        |      dk(  sJ dt        |              t        dd      D ]5  }|d| dz  }|j                         sJ d| d	       t	        |      |v r5J  y
c c}w )z
        Test that generate_all_sub_team_details() creates files for all 8 dev teams
        (dev1-team.json through dev8-team.json)
        
output_dirdev	team.json   zExpected 8 dev team files, got    	   
-team.jsonz-team.json not createdN)r   lenrangeexistsstr)selftmp_path	generatedf	dev_filesiexpected_files          [/home/jay/workspace/.worktrees/task-2057-dev2/teams/dev4/tests/test_generate_org_details.py#test_generate_creates_all_sub_teamszATestGenerateAllSubTeamDetails.test_generate_creates_all_sub_teams   s    
 2XF	 !*M1UaZK1<LQM	M9~"V&Ec)nEU$VV" q! 	3A$QCz'::M '')JS3I+JJ)}%222	3	 Ns   	BBBc                    t        |       h d}t        dd      D ]  }|d| dz  }t        |dd	      5 }t        j                  |      }d
d
d
       t        j                               }||z
  }|rJ d| d|        |d   dk(  sJ d| d       t        |d   t              rJ d| d        y
# 1 sw Y   jxY w)z
        Test that each generated file has all required keys:
        team_id, team_name, extracted_from, status, type, lead, members_detail
        r   >   leadtypestatusteam_id	team_nameextracted_frommembers_detailr   r   r
   r   rutf-8encodingNz-team.json missing keys: r#   zorganization-structure.jsonz)-team.json has wrong extracted_from valuer$   z'-team.json members_detail is not a dict)	r   r   openjsonloadsetkeys
isinstancedict)	r   r   required_keysr   	file_pathr   dataactual_keysmissing_keyss	            r   test_output_formatz0TestGenerateAllSubTeamDetails.test_output_format%   s   
 	&:
 q! 	@A S:#66Iiw7 $1yy|$ diik*K(;6L @QC0?@ 
 %&*GGBQC@ABG %& @QC>?@ %	@$ $s   B66B?	c                    t        |      }|D cg c]  }d|v sd|v s| }}t        |      }t        d      }t        |dd      5 }t	        j
                  |      }ddd       d}d	   d
   d   D ]  }	|	d   dk(  s|	} n |J d       t        |j                  dg             }
||
k(  sJ d|
 d|        yc c}w # 1 sw Y   cxY w)z
        Test that the function reads sub_teams dynamically
        The count of dev team files should match the count of sub_teams in org structure
        r   r
   r   z6/home/jay/workspace/memory/organization-structure.jsonr%   r&   r'   N	structurecolumnsteamsr!   zdevelopment-officez-development-office not found in org structure	sub_teamsz	Expected z' dev teams based on org structure, got )r   r   r   r)   r*   r+   get)r   r   r   r   r   dev_team_countorg_fileorg_data
dev_officeteamexpected_sub_teamss              r   test_dynamic_no_hardcodingz8TestGenerateAllSubTeamDetails.test_dynamic_no_hardcodingM   s   
 2XF	 !*M1UaZK1<LQM	MY PQ(C'2 	$ayy|H	$ 
[))4W= 	DI"66!
	
 %V'VV% R!@A 00	c)**QR`Qab	c0% N
	$ 	$s   	B=B=B=
CCc                 n   |dz  }t        ||      }|D cg c]  }d|v sd|v s| }}t        |      dk(  sJ d       t        dd      D ]U  }|d| d	z  }|j                         sJ t	        |d
d      5 }t        j                  |      }ddd       dv sJ d|v rUJ  yc c}w # 1 sw Y   xY w)z
        Test that when backup_file points to non-existent path,
        the function still generates files using main data
        znon_existent_backup.json)backup_filer	   r
   r   r   z2Failed to generate files when backup doesn't existr   r   r   r%   r&   r'   Nr!   r$   )r   r   r   r   r)   r*   r+   )	r   r   non_existent_backupr   r   r   r   r1   r2   s	            r   test_fallback_to_main_filez8TestGenerateAllSubTeamDetails.test_fallback_to_main_filej   s     ')CC1+
	
 !*M1UaZK1<LQM	M9~"X$XX" q! 	,A S:#66I##%%%iw7 $1yy|$$$$#t+++	,	 N$ $s   	B&B&B&9B++B4	c                     |dz  }t        j                  t              5 }t        ||       ddd       dt	        j
                        v s#t	        |      t	        |j
                        v sJ yy# 1 sw Y   DxY w)zp
        Test that calling with org_file pointing to non-existent path
        raises FileNotFoundError
        znon_existent_org.jsonr=   r	   Nu/   메인 조직 파일을 찾을 수 없습니다)pytestraisesFileNotFoundErrorr   r   value)r   r   non_existent_orgexc_infos       r   test_missing_org_file_raisesz:TestGenerateAllSubTeamDetails.test_missing_org_file_raises   s    
 $&==]],- 	))h	
 ACDWW[^\
 \! 	! ! \!W	 	s   A00A9N)	__name__
__module____qualname____doc__r   r5   rB   rF   rO        r   r   r      s!    ?3"&@Pc:,2!rU   r   c                   "    e Zd ZdZd Zd Zd Zy)TestSubTeamDetailsz4Additional tests for specific sub-team file contentsc                 t   t        |       |dz  }t        |dd      5 }t        j                  |      }ddd       d   dk(  sJ |d	   d
k(  sJ |d   dk(  sJ |d   dk(  sJ d|v sJ t	        |d   t
              sJ |d   j                  d      dk(  sJ t        |d         dkD  sJ y# 1 sw Y   yxY w)z;Test that dev1-team.json has expected structure and membersr   dev1-team.jsonr%   r&   r'   Nr!   z	dev1-teamr"   u
   개발1팀r    activer   physicalr   idhermesr$   r   )r   r)   r*   r+   r.   r/   r;   r   )r   r   r1   r   r2   s        r   test_dev1_team_structurez+TestSubTeamDetails.test_dev1_team_structure   s    %://	)S73 	 q99Q<D	  I+---K L000H~)))F|z))) ~~$v,---F|%111 4()*Q...	  	    B..B7c                 t   t        |       |dz  }t        |dd      5 }t        j                  |      }ddd       d   }t	        |t
              sJ t        |      dkD  sJ |j                         D ]5  \  }}t	        |t              sJ t	        |t
              sJ d	|v r/|d
k7  r5J  y# 1 sw Y   yxY w)z.Test that members_detail has correct structurer   rY   r%   r&   r'   Nr$   r   r\   unknown)	r   r)   r*   r+   r.   r/   r   itemsr   )r   r   r1   r   r2   members	member_idmember_datas           r   test_members_detail_structurez0TestSubTeamDetails.test_members_detail_structure   s    %://	)S73 	 q99Q<D	  '('4(((7|a '.mmo 	A"I{i---k4000;&)y*@@@		A	  	 r_   c                     t        |      }t        |      dkD  sJ d       |D cg c]  }d|v s|j                  d      s| }}t        |      dk(  sJ d       yc c}w )zt
        Test that generated file count matches expected output
        (8 dev teams + other teams/centers)
        r   r   z/Expected more than 8 files (dev teams + others)r
   r   z!Expected exactly 8 dev team filesN)r   r   endswith)r   r   r   r   	dev_teamss        r   test_file_count_consistencyz.TestSubTeamDetails.test_file_count_consistency   sl    
 2XF	 9~!T#TT! !*T1UaZAJJ{<SQT	T9~"G$GG" Us   	AAAN)rP   rQ   rR   rS   r^   rf   rj   rT   rU   r   rW   rW      s    >/,A(HrU   rW   c                   "    e Zd ZdZd Zd Zd Zy)TestErrorHandlingz"Test error handling and edge casesc                     |dz  }|j                  d       	 t        ||dz        }t        |t              sJ y# t        t
        f$ r Y yw xY w)zTest with malformed org filezbad_org.jsonz{"invalid": "structure"}outrH   N)
write_textr   r.   listrK   KeyError)r   r   bad_orgr   s       r   test_invalid_org_file_structurez1TestErrorHandling.test_invalid_org_file_structure   s]    ^+56	5 X-=I i...!8, 		s   "; AAc                     |dz  dz  dz  }|j                         rJ t        |       |j                         sJ d       t        |j                  d            sJ d       y)	z9Test that output directory is created if it doesn't existnestedoutputdirr   z"Output directory should be createdz*.jsonz*Output directory should contain JSON filesN)r   r   anyglob)r   r   r	   s      r   test_output_directory_creationz0TestErrorHandling.test_output_directory_creation   sn    (83e;
$$&&&%<  "H$HH"OOH%
 	87	8 
rU   c                    t        |      }|D ]m  }t        |      }|j                         s
J | d       t        |dd      5 }t	        j
                  |      }ddd       t        t              reJ | d        y# 1 sw Y   &xY w)z,Test that all generated files are valid JSONr    does not existr%   r&   r'   Nz is not a JSON object)r   r   r   r)   r*   r+   r.   r/   )r   r   r   r1   pathr   r2   s          r   test_json_is_validz$TestErrorHandling.test_json_is_valid   s    1XF	" 	OI	?D;;=?YK"??= dC'2 $ayy|$dD)Ni[8M+NN)	O
$ $s   B  B		N)rP   rQ   rR   rS   rs   rz   r~   rT   rU   r   rl   rl      s    ,"
8OrU   rl   c                       e Zd ZdZd Zd Zy)TestIntegrationz Integration tests with real datac                     t        |      }t        |t              sJ t        |      dkD  sJ |D ]&  }t	        |      j                         rJ d| d        y)z,Test with actual organization-structure.jsonr   r   zGenerated path r|   N)r   r.   rp   r   r   r   )r   r   resultr}   s       r   test_with_real_org_filez'TestIntegration.test_with_real_org_file  sc    .(C&$'''6{Q  	PD:$$&O/$(OO&	PrU   c                     t        |      }t        |t              sJ t        d |D              sJ d       t        d |D              sJ d       y)z0Test that return value contains valid file pathsr   c              3   <   K   | ]  }t        |t                y wN)r.   r   .0ps     r   	<genexpr>zBTestIntegration.test_return_value_is_file_paths.<locals>.<genexpr>  s     6!:a%6s   zAll returns should be stringsc              3      K   | ]8  }t        |      j                         xs t        |      j                          : y wr   )r   is_absoluter   r   s     r   r   zBTestIntegration.test_return_value_is_file_paths.<locals>.<genexpr>  s5      
:;DG!5T!W^^%55
s   >A zAll paths should be validN)r   r.   rp   all)r   r   r   s      r   test_return_value_is_file_pathsz/TestIntegration.test_return_value_is_file_paths  s]    .(C&$'''6v66W8WW6 
?E
 
 	'&	' 
rU   N)rP   rQ   rR   rS   r   r   rT   rU   r   r   r     s    *	P'rU   r   )rS   r*   syspathlibr   rI   r}   insertgenerate_org_detailsr   r   rW   rl   r   rT   rU   r   <module>r      s_   
  
   5 6 >@! @!F?H ?HD+O +O\' 'rU   