
    62j	                         d dl Zd dlmc mZ d dlmZmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZ d d	lmZmZmZmZ d
ededefdZd Z d Z!d Z"d Z#dS )    N)datedatetime)ZoneInfo)
TestClient)Sessionselect)engineinit_db)app)ChildScheduleBlockScheduleDayTaskInstance)child_timelineget_afternoon_leave_home_time get_first_afternoon_school_blockget_next_external_activitysessionnamereturnc                     |                      t          t                                        t          j        |k                                                        S )N)execr   r   wherer   one)r   r   s     D/home/agent/projects/FamilyDashboard/backend/tests/test_dashboard.pychild_by_namer      s;    <<u++EJ$,>??@@DDFFF    c                  F   t                       t          t                    5 } |                     d          }d d d            n# 1 swxY w Y   |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	         }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 |d         D             }d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         d         }|d         d         }|s:ddt          j
        |          iz  }t          t          j        |                    d }d}|d         }||v }	|	slt          j        d|	fd||f          t          j
        |          t          j
        |          dz  }
dd|
iz  }t          t          j        |                    d x}x}	}|d         d         }|s:ddt          j
        |          iz  }t          t          j        |                    d }d |d         d         D             }t          |          }|sdd t          j                    v st          j	        t                    rt          j
        t                    nd t          j
        |          t          j
        |          d!z  }
t          t          j        |
                    d x}}|d         d         }|s:ddt          j
        |          iz  }t          t          j        |                    d }|d"         }t          |          }h d#}||k    }|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}}|d"         d)         }|d"         d*         }|d"         d+         }||z
  }||k    }	|	st          j        d|	fd,||f          t          j
        |          t          j
        |          t          j
        |          d-z  }d'd(|iz  }t          t          j        |                    d x}x}	x}x}}d S ).Nz/api/dashboard?date=2026-06-15   ==z3%(py2)s
{%(py2)s = %(py0)s.status_code
} == %(py5)sresponsepy0py2py5assert %(py7)spy7r   z
2026-06-15z%(py1)s == %(py4)spy1py4assert %(py6)spy6c                 *    g | ]}|d          d         S )childr    .0items     r   
<listcomp>zMtest_dashboard_contains_children_tasks_timeline_and_coins.<locals>.<listcomp>   s!    BBBdDM&!BBBr   childrenEmiliaValerier   timelinesegmentszassert %(py1)sr,   progress_percent)in)z%(py1)s in %(py4)scurrent_stepc              3   .   K   | ]}|d          dk    V  dS )titleu   Musikinstrument übenNr2   )r4   tasks     r   	<genexpr>zLtest_dashboard_contains_children_tasks_timeline_and_coins.<locals>.<genexpr>   s,      [[DtG} 77[[[[[[r   tasksopenz,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}any)r%   r&   r-   coin_summary>   postedreserved	available)z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)sset)r%   r&   r-   r)   zassert %(py9)spy9rI   rG   rH   )z%(py1)s == (%(py4)s - %(py6)s))r,   r-   r/   )r
   r   r   getstatus_code
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationjsonrE   rJ   )clientr#   @py_assert1@py_assert4@py_assert3@py_format6@py_format8payload@py_assert0@py_assert2@py_format5@py_format7first@py_format2@py_assert6@py_assert5@py_format10@py_assert7s                     r   9test_dashboard_contains_children_tasks_timeline_and_coinsrh      sc   III	C @F::>??@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ &3&3&&&&&&&&&&3&&&&&&&&&&&&8&&&&&8&&&&&&&&&&3&&&&&&&&&&&&&&&&&&&&&&&&&&&mmooG6?*l*?l**********?l*****?****l***************************BBgj.ABBB[xQZF[[BF[[[[[[[[[[[BF[[[[[[B[[[[F[[[[[[[[[[[[[[[[[[[[[[[[[[[[J"EZ(((((((((((((((((((((((((2z!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22222222222^,,,,,,,,,,,,,,,,,,,,,,,,,[[E'NSYDZ[[[[3[[[[[[[[[[[[[[[[3[[[[[3[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[>&!!!!!!!!!!!!!!!!!!!!!!!!!^$L3$%%L)L)L)LL%)LLLLLLLLLLL%)LLLLLLLLLLLLL3LLLLL3LLLLLL$LLLL%LLLL)LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -t~1Fx1PtSXYgShisStt1PSt1tt-1ttttttttttt-1tttttt-tttt1PttttStttttttttttttttttttttttttttttttttt   AA	A	c                  v   t                       t          ddd          } t          t                    5 }|                    d|                                            }|                    d|                                            }d d d            n# 1 swxY w Y   |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}||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}}t          t                     5 }	|	                    t%          t&                                        t&          j        | k                                                        }
d d d            n# 1 swxY w Y   t/          |
          }d}||k    }|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}}d S )N        z/api/dashboard?date=r   r    r"   rb   r$   r(   r)   second   )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)slenrC   )r%   r,   py3r/   zassert %(py8)spy8)r
   r   r   r   rL   	isoformatrM   rN   rO   rP   rQ   rR   rS   rT   rU   r   r	   r   r   r   r   	task_dateallrp   )targetrW   rb   rn   rX   rY   rZ   r[   r\   r   rC   r_   re   ra   @py_format9s                  r   1test_dashboard_lazy_task_generation_is_idempotentrx   #   sd   III$2F	C IF

F&2B2B2D2DFFGGG63C3C3E3EGGHHI I I I I I I I I I I I I I I ########################5#####5#####################################$$$$$$$$$$$$$$$$$$$$$$$$6$$$$$6$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$	 aGVL11778NRX8XYYZZ^^``a a a a a a a a a a a a a a au:::?:33uu:s%   ABBB6AJJ!$J!c                     t                       t          t                    5 } |                     d          }d d d            n# 1 swxY w Y   |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	 |                                d
         D             }dd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}}d S )Nz/api/dashboard?date=2026-06-20r   r    r"   r#   r$   r(   r)   c                 *    g | ]}|d          d         S )r:   moder2   r3   s     r   r6   z/test_dashboard_weekend_mode.<locals>.<listcomp>7   s"    NNN$T*f%NNNr   r7   weekendz%(py0)s == %(py3)smodesr%   rq   assert %(py5)sr'   )r
   r   r   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   )
rW   r#   rX   rY   rZ   r[   r\   r~   r_   @py_format4s
             r   test_dashboard_weekend_moder   1   s^   III	C @F::>??@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ &3&3&&&&&&&&&&3&&&&&&&&&&&&8&&&&&8&&&&&&&&&&3&&&&&&&&&&&&&&&&&&&&&&&&&&&NN(--//*2MNNNE	**5***********5*************5*****5**********************************ri   c                  6   t                       t          ddd          } t          t                    5 }t	          |d          }t          ||| dt          dddddt          d                    	          }d d d            n# 1 swxY w Y   d
 |d         D             }g d}||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}}t!          d |d         D                       }	t!          d |d         D                       }
|	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         }|
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         }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 S )Nrk   rl      r8   zEurope/Zurich   r   )tzinfo)nowc                     g | ]
}|d          S )
shortLabelr2   r4   steps     r   r6   zMtest_dashboard_morning_uses_family_routine_until_ablaufen.<locals>.<listcomp>B   s    GGGTd< GGGr   timelineSteps)Aufu   Frühstücku   ZähneLosSchuler    r}   labelsr   r   r'   c              3   2   K   | ]}|d          dk    |V  dS )key
leave_homeNr2   r   s     r   rB   zLtest_dashboard_morning_uses_family_routine_until_ablaufen.<locals>.<genexpr>D   s0      [[$tE{l?Z?Z?Z?Z?Z?Z[[r   c              3   2   K   | ]}|d          dk    |V  dS )r   school_startNr2   r   s     r   rB   zLtest_dashboard_morning_uses_family_routine_until_ablaufen.<locals>.<genexpr>E   s1      ddd5kUcFcFcFcFcFcFcddr   kindranger*   r+   r.   r/   endTimetime	milestone)r
   r   r   r	   r   r   r   r   rN   rO   rP   rQ   rR   rS   rT   rU   next)rv   r   r1   r:   r   r_   rX   r   r[   leaver   r^   rZ   r`   ra   s                  r   9test_dashboard_morning_uses_family_routine_until_ablaufenr   ;   s#   III$2F	 NGgx00!'5&/xX\^_acefhirz  |K  sL  sL  PM  PM  PM  N  N  NN N N N N N N N N N N N N N N HGXo-FGGGFFFFF6FFFFFFFFFFF6FFFFFFFFFFFFF6FFFFF6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FFFFF[[(?";[[[[[Edd/)BdddddL=#G#=G##########=G#####=####G###########################3|F333333333333333333333333333333333333333333333333333.;.;..........;.........;.............................s   ABB	B	)$builtinsrP   _pytest.assertion.rewrite	assertionrewriterN   r   r   zoneinfor   fastapi.testclientr   sqlmodelr   r   app.db.sessionr	   r
   app.mainr   
app.modelsr   r   r   r   app.services.dashboardr   r   r   r   strr   rh   rx   r   r   r2   r   r   <module>r      s                 # # # # # # # #       ) ) ) ) ) ) $ $ $ $ $ $ $ $ * * * * * * * *       F F F F F F F F F F F F O  O  O  O  O  O  O  O  O  O  O  OG7 G# G% G G G Gu u u&  + + +/ / / / /r   