
    U$j_                         d dl Zd dlmc mZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZ d dlmZmZ d	 Zd
 Zd Zd Zd ZdS )    N)Path)
TestClient)Session)get_settings)init_dbreset_db_for_tests)app)
VideoAssetVideoStatusc                     t                      }d|_        | dz  |_        t          |          }t	          |           ||t          t                    fS )Nz	sqlite://storage)r   database_urlstorage_rootr   r   r   r	   )tmp_pathsettingsengines      J/home/agent/projects/AutoShorts_Dashboard/backend/tests/test_api_videos.pysetup_test_dbr      sN    ~~H'H$y0HXFvVZ__,,    c                    t          |           \  }}}|                    d          }|j        }d}||k    }|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}}|                                d	         }
g }|
|k    }|slt          j        d|fd
|
|f          t          j        |
          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}
x}}d S )Nz/api/videos   ==z3%(py2)s
{%(py2)s = %(py0)s.status_code
} == %(py5)sresponsepy0py2py5assert %(py7)spy7itemsz%(py1)s == %(py4)spy1py4assert %(py6)spy6)r   getstatus_code
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationjson)r   	_settings_engineclientr   @py_assert1@py_assert4@py_assert3@py_format6@py_format8@py_assert0@py_assert2@py_format5@py_format7s                 r   test_videos_api_starts_emptyr@      s   !.x!8!8Iwzz-((H&3&3&&&&&&&&&&3&&&&&&&&&&&&8&&&&&8&&&&&&&&&&3&&&&&&&&&&&&&&&&&&&&&&&&&&&==??7#)r)#r))))))))))#r)))))#))))r)))))))))))))))))))))))))))))r   c                    t          |           \  }}}| dz  }|                                 |dz  }|                    d           |dz  }|                    d           t          |          5 }t	          dddt          |          |                                j        d	t          |          d
t          j	        	  	        }|
                    |           |                                 |                    |           |j        }	d d d            n# 1 swxY w Y   |                    d|	 d          }
|
j        }d}||k    }|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         }|j        }d} ||          }|ssdt!          j        |          t!          j        |          t!          j        |          t!          j        |          dz  }t-          t!          j        |                    d x}x}x}}|
j        d         }d}||k    }|slt!          j        d|fd||f          t!          j        |          t!          j        |          dz  }dd|iz  }t-          t!          j        |                    d x}x}}|
j        }d}||k    }|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}}d S ) Nmedia	video.mp4   not-real-video	thumb.jpg   test_thumb_existingpackage_thumb_existingprepared_packagezthumb-existing-checksumzExisting thumbnail	candidate_id
package_idsource	file_path	file_sizechecksumthumbnail_pathworking_titlestatus/api/videos/
/thumbnailr   r   r   r   r   r    r!   content-type
image/jpegLassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.startswith
}(%(py5)s)
}r%   py3r   r!   cache-controlzpublic, max-age=3600r#   r$   r'   r(   z/%(py2)s
{%(py2)s = %(py0)s.content
} == %(py5)sr   mkdirwrite_bytesr   r
   strstatst_sizer   ready_for_reviewaddcommitrefreshidr)   r*   r+   r,   r-   r.   r/   r0   r1   r2   headers
startswithcontent)r   r4   r   r6   rB   
video_path
thumb_pathsessionvideovideo_idr   r7   r8   r9   r:   r;   r<   r=   @py_assert6r>   r?   s                        r   )test_video_thumbnail_serves_existing_filerq      s    -h 7 7IvvwE	KKMMM$J,---$J.///	 G./%*oo oo''/.z??./

 

 

 	E8              " zz====>>H&3&3&&&&&&&&&&3&&&&&&&&&&&&8&&&&&8&&&&&&&&&&3&&&&&&&&&&&&&&&&&&&&&&&&&&&N+D+6D|D66|DDDDDDDD+DDDD6DDDD|DDDDDDDDDDDDDDDDDDDDDDDDDDDDO,F0FF,0FFFFFFFFFFF,0FFFFFF,FFFF0FFFFFFFFFFFFFFFFFFFFFFFFFFFF22222222222222222222222222282222282222222222222222222222222222222222222222   0BDDDc                 	   t          |           \  }}}| dz  dz  }t          |          5 }t          dddt          |          dddt          j        	          }|                    |           |                                 |                    |           |j	        }d d d            n# 1 swxY w Y   |
                    d
| d          }|j        }	d}
|	|
k    }|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         }|j        }d}
 ||
          }|ssdt          j        |          t          j        |          t          j        |
          t          j        |          dz  }t%          t          j        |                    d x}x}x}
}|j        d         }d}||k    }|slt          j        d|fd||f          t          j        |          t          j        |          dz  }dd|iz  }t%          t          j        |                    d x}x}}d}|j        }
||
v }|st          j        d|fd||
f          t          j        |          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}x}}
t          |          }|j        }||v}
|
s0t          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        |          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}x}
}d S )'Nprivatezmissing.mp4test_thumb_fallbackpackage_thumb_fallbackrI   r   zthumb-fallback-checksumzNo Media Yet)rK   rL   rM   rN   rO   rP   rR   rS   rT   rU   r   r   r   r   r   r    r!   rV   zimage/svg+xmlrX   rY   r[   zpublic, max-age=600r#   r$   r'   r(   )in)z,%(py1)s in %(py5)s
{%(py5)s = %(py3)s.text
})r%   rZ   r   )not in)zN%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} not in %(py7)s
{%(py7)s = %(py5)s.text
}r`   missing_path)r   r%   rZ   r   r!   zassert %(py9)spy9)r   r   r
   r`   r   rc   rd   re   rf   rg   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   rh   ri   text)r   r4   r   r6   ry   rm   rn   ro   r   r7   r8   r9   r:   r;   r<   r=   rp   r>   r?   @py_format10s                       r   8test_video_thumbnail_falls_back_to_svg_without_path_leakr}   ?   s    -h 7 7Ivvi'-7L	 G./%,''.(/	
 	
 	
 	E8                zz====>>H&3&3&&&&&&&&&&3&&&&&&&&&&&&8&&&&&8&&&&&&&&&&3&&&&&&&&&&&&&&&&&&&&&&&&&&&N+G+6GG66GGGGGGGG+GGGG6GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGO,E0EE,0EEEEEEEEEEE,0EEEEEE,EEEE0E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*X]*>]**********>]*****>***********X*****X******]***************************|1HM1M1111111111M11111111111131111131111111111111|11111|11111111111111111H11111H111111M11111111111111111111111111111s   A4B++B/2B/c                    t          |           \  }}}| dz  }|                                 |dz  }|                    d           |dz  }|                    d           t          |          5 }t	          dddt          |          |                                j        d	t          |          d
t          j	        	  	        }|
                    |           |                                 |                    |           |j        }	d d d            n# 1 swxY w Y   |                    d|	 d          }
|
j        }d}||k    }|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         }|j        }d} ||          }|ssdt!          j        |          t!          j        |          t!          j        |          t!          j        |          dz  }t-          t!          j        |                    d x}x}x}}|
j        }d}||k    }|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}}d S )NrB   rC   rD   rE   rF   test_preview_aliaspackage_preview_aliasrI   zpreview-alias-checksumzPreview AliasrJ   rT   z/preview-framer   r   r   r   r   r    r!   rV   rW   rX   rY   r\   r]   )r   r4   r   r6   rB   rk   rl   rm   rn   ro   r   r7   r8   r9   r:   r;   r<   r=   rp   s                      r   0test_video_preview_frame_uses_thumbnail_responser   [   s    -h 7 7IvvwE	KKMMM$J,---$J.///	 G-.%*oo oo''/-z??)/

 

 

 	E8              " zzAAAABBH&3&3&&&&&&&&&&3&&&&&&&&&&&&8&&&&&8&&&&&&&&&&3&&&&&&&&&&&&&&&&&&&&&&&&&&&N+D+6D|D66|DDDDDDDD+DDDD6DDDD|DDDDDDDDDDDDDDDDDDDDDDDDDDDD22222222222222222222222222282222282222222222222222222222222222222222222222rr   )builtinsr-   _pytest.assertion.rewrite	assertionrewriter+   pathlibr   fastapi.testclientr   sqlmodelr   app.core.configr   app.db.sessionr   r   app.mainr	   app.models.corer
   r   r   r@   rq   r}   r    r   r   <module>r      s                        ) ) ) ) ) )       ( ( ( ( ( ( 6 6 6 6 6 6 6 6       3 3 3 3 3 3 3 3- - -* * *3 3 3B2 2 283 3 3 3 3r   