<s> import uuid <EOL> from django . core . urlresolvers import reverse <EOL> from rest_framework import status <EOL> from shop . tests . factories import ( <EOL> ProductFactory , <EOL> ProductTrxFactory , <EOL> ProductCategoryFactory <EOL> ) <EOL> from shop . enums import TrxType <EOL> from foobar . rest . fields import MoneyField <EOL> from . base import AuthenticatedAPITestCase <EOL> def serialize_money ( x ) : <EOL> return MoneyField ( ) . to_representation ( x ) <EOL> class TestProductAPI ( AuthenticatedAPITestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ) . setUp ( ) <EOL> self . force_authenticate ( ) <EOL> def test_retrieve_existing ( self ) : <EOL> product_obj = ProductFactory . create ( ) <EOL> ProductTrxFactory . create ( <EOL> product = product_obj , <EOL> qty = <NUM_LIT:10> , <EOL> trx_type = TrxType . INVENTORY <EOL> ) <EOL> url = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : product_obj . id } ) <EOL> response = self . api_client . get ( url ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( response . data [ '<STR_LIT>' ] , <NUM_LIT:10> ) <EOL> url = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : uuid . uuid4 ( ) } ) <EOL> response = self . api_client . get ( url ) <EOL> self . assertEqual ( response . status_code , status . HTTP_404_NOT_FOUND ) <EOL> def test_list_products ( self ) : <EOL> for code in range ( <NUM_LIT:9> ) : <EOL> ProductFactory . create ( ) <EOL> fixed_code = '<STR_LIT>' . format ( <NUM_LIT> ) <EOL> ProductFactory . create ( code = fixed_code ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> response = self . api_client . get ( url ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( len ( response . data ) , <NUM_LIT:10> ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> response = self . api_client . get ( url , { '<STR_LIT:code>' : fixed_code } ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( len ( response . data ) , <NUM_LIT:1> ) <EOL> class TestProductCategoryAPI ( AuthenticatedAPITestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ) . setUp ( ) <EOL> self . force_authenticate ( ) <EOL> def test_list_categories ( self ) : <EOL> url = reverse ( '<STR_LIT>' ) <EOL> response = self . api_client . get ( url ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( len ( response . data ) , <NUM_LIT:0> ) <EOL> ProductCategoryFactory . create ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> response = self . api_client . get ( url ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( len ( response . data ) , <NUM_LIT:1> ) </s>
