B
    GDb                 @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ G dd deZG d	d
 d
eZdS )    N)TestCase)	APIClient)Employee
DepartmentArea)Transaction)Companyc               @   s   e Zd ZdZdd ZdS )EmployeeAPIClientz
    for emp login by api
    c             K   s"   |}|r| j |dd dS dS dS )z
        Sets the Factory to appear as if it has successfully logged into a site.

        Returns True if login is possible; False if the provided credentials
        are incorrect.
        z(mysite.accounts.backends.EmployeeBackend)ZbackendTFN)Z_login)selfZempZcredentialsuser r   +G:\easytimepro\master/mysite/mobile\test.pylogin   s
    	zEmployeeAPIClient.loginN)__name__
__module____qualname____doc__r   r   r   r   r   r	      s   r	   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )MobileApiTestc             C   st   t j | _tj | _tj | _tjj	d| jd| _
| j
 shtd| j| jg| jjd| _
| j
  td d S )N1)emp_codecompany)r   Z
departmentarea
company_idsetUp)r   Zobjectsfirstr   r   Zdeptr   r   r   filteremployeeexistsidsaveprint)r
   r   r   r   r   &   s    

zMobileApiTest.setUpc             C   s   t d d S )NtearDown)r    )r
   r   r   r   r!   6   s    zMobileApiTest.tearDownc             C   sn   t  }|| j i }tt |d< d|d< d|d< d|d< d|d	< |jd
t|dd}| |j	d d S )N
punch_time0Z
punch_typez
12.9891657Zlatitudez
77.6885258Z	longitudeztest locationlocationz/mobile/api/mobile_transaction/zapplication/json)content_type   )
r	   r   r   inttimeZpostjsondumpsassertEqualsstatus_code)r
   clientbodyresponser   r   r   test_mobile_transaction9   s    z%MobileApiTest.test_mobile_transactionc          
   C   s   t  }|| j i }tt |d< |jd|dd}| |jd tj	 }t
d tj	 }t| jjd||dd| jj| jjd}|  |jd|dd}| |jd t| jjd||dd| jj| jjd}|  |jd|dd}| |jd d S )	Ncurrent_dayz$/mobile/api/current_day_transaction/zapplication/json)datar%         r   )r   verify_typer"   upload_timesync_statuspunch_stateemp_idr   )r	   r   r   r'   r(   getr+   r,   datetimenowsleepr   r   r   r   r   )r
   r-   r.   r/   t1t2tran1tran2r   r   r   test_current_day_transactionF   s&    


z*MobileApiTest.test_current_day_transactionc          
   C   s6  t  }|| j i }tt |d< d|d< |jd|dd}| |jd tj	 }|tj
dd }|tj
dd }t| jjd||dd	| jj| jjd
}|  tt |d< |jd|dd}| |jd t| jjd||dd	| jj| jjd
}|  tt |d< d|d< |jd|dd}| |jd d S )Nr1   r4   Zpage_numz$/mobile/api/seven_days_transactions/zapplication/json)r2   r%   r3   )Zdaysr   )r   r5   r"   r6   r7   r8   r9   r   r   Zpin)r	   r   r   r'   r(   r:   r+   r,   r;   r<   Z	timedeltar   r   r   r   r   )r
   r-   r.   r/   r>   r?   r@   rA   r   r   r   test_seven_days_transactions`   s2    
z*MobileApiTest.test_seven_days_transactionsN)r   r   r   r   r!   r0   rB   rC   r   r   r   r   r   $   s
   r   )r)   r(   r;   Zdjango.testr   Zrest_framework.testr   Zmysite.personnel.modelsr   r   r   Zmysite.iclock.modelsr   Zmysite.cloud.modelsr   r	   r   r   r   r   r   <module>   s   