
    -vj:                     \    d Z ddlZddlmc mZ ddlmZm	Z	m
Z
mZmZ d Zd Zd Zd Zd Zy)	zTests for PeerDrop Core models.    N)DevicePeerTransferTransferRequestTransferStatusc                     t        ddg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                  }t        |      }d}||k(  }|s
t        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                  |      t        j                  |      dz  }	dd|	iz  }
t        t        j                  |
            d x}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 )N	QmTest123z/ip4/192.168.1.1/tcp/4001zTest Device)peer_idaddrsname==z/%(py2)s
{%(py2)s = %(py0)s.peer_id
} == %(py5)speerpy0py2py5assert %(py7)spy7   )zK%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.addrs
})
} == %(py8)slenr   py1py3r   py8assert %(py10)spy10T)is)z1%(py2)s
{%(py2)s = %(py0)s.is_online
} is %(py5)s)r   r
   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationr   r   	is_online)r   @py_assert1@py_assert4@py_assert3@py_format6@py_format8@py_assert2@py_assert7@py_assert6@py_format9@py_format11s              3/Users/sumanjeet/code/PeerDrop/tests/test_models.pytest_peer_creationr4      s   *+D
 <<&;&<;&&&&<;&&&&&&4&&&4&&&<&&&;&&&&&&&zz3z?a?a?a33ttz?a>>!T!>T!!!!>T!!!!!!4!!!4!!!>!!!T!!!!!!!    c                  Z   t        dddddd      } | j                  }t        j                  }||k(  }|st	        j
                  d|fd	||f      d
t        j                         v st	        j                  |       rt	        j                  |       nd
t	        j                  |      dt        j                         v st	        j                  t              rt	        j                  t              nd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}}| j                  }	t        |	      }d}
||
k(  }|s
t	        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                  |      t	        j                  |
      dz  }dd|iz  }t        t	        j                  |            d x}	x}x}}
y )Nz/tmp/test.txtztest.txti   	QmRootCIDQmSender
QmReceiver)	file_path	file_name	file_sizeroot_cidsender_peer_idreceiver_peer_idr   )zK%(py2)s
{%(py2)s = %(py0)s.status
} == %(py6)s
{%(py6)s = %(py4)s.PENDING
}transferr   )r   r   py4py6zassert %(py8)sr   g        )z0%(py2)s
{%(py2)s = %(py0)s.progress
} == %(py5)sr   r   r      )zQ%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.transfer_id
})
} == %(py8)sr   r   r   r   )r   statusr   PENDINGr    r!   r"   r#   r$   r%   r&   r'   progresstransfer_idr   )r@   r)   @py_assert5r+   @py_format7r1   r*   r,   r-   r.   r/   r0   r2   s                r3   test_transfer_creationrJ      s   !!%H ??4n444?44444?444444484448444?444444n444n44444444444############8###8###############*3#$**$****$******3***3******x***x***#***$**********r5   c                  B   t        dd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}||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}}y )Nz	photo.jpgi   
QmPhotoCIDr8   )r;   r<   r=   r>   r   )z1%(py2)s
{%(py2)s = %(py0)s.file_name
} == %(py5)sreqr   r   r   )z1%(py2)s
{%(py2)s = %(py0)s.file_size
} == %(py5)s)r   r;   r    r!   r"   r#   r$   r%   r&   r'   r<   )rM   r)   r*   r+   r,   r-   s         r3   test_transfer_requestrN   %   s    
!	C =='K'=K''''=K''''''3'''3'''='''K'''''''== D =D    =D      3   3   =   D       r5   c                  	   t         j                  } | j                  }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}}t         j                  } | j                  }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}}t         j                  } | j                  }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}}t         j                  } | j                  }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}}t         j                  } | j                  }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}}y )Npendingr   )zJ%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.PENDING
}.value
} == %(py7)sr   )r   r   rA   r   zassert %(py9)spy9transferring)zO%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.TRANSFERRING
}.value
} == %(py7)s	completed)zL%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.COMPLETED
}.value
} == %(py7)sfailed)zI%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.FAILED
}.value
} == %(py7)s	cancelled)zL%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.CANCELLED
}.value
} == %(py7)s)r   rE   valuer    r!   r"   r#   r$   r%   r&   r'   TRANSFERRING	COMPLETEDFAILED	CANCELLED)r)   r+   r0   rH   r-   @py_format10s         r3   test_transfer_status_valuesr\   0   s   !!4!''494'94444'9444444>444>444!444'44494444444&&>&,,>>,>>>>,>>>>>>>>>>>>>>&>>>,>>>>>>>>>>##8#))8[8)[8888)[888888>888>888#888)888[8888888  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##8#))8[8)[8888)[888888>888>888#888)888[8888888r5   c                  @   t        d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}||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}}y )N
QmMyDevicez	My Laptopi  )r
   r   listen_portr   r   devicer   r   r   )z3%(py2)s
{%(py2)s = %(py0)s.listen_port
} == %(py5)s)r   r
   r    r!   r"   r#   r$   r%   r&   r'   r_   )r`   r)   r*   r+   r,   r-   s         r3   test_device_creationra   8   s    F
 >>)\)>\))))>\))))))6)))6)))>)))\)))))))%%%%%%%%%%%%6%%%6%%%%%%%%%%%%%r5   )__doc__builtinsr"   _pytest.assertion.rewrite	assertionrewriter    peerdrop.core.modelsr   r   r   r   r   r4   rJ   rN   r\   ra    r5   r3   <module>ri      s0    %     "+!9&r5   