@@ -62,3 +62,37 @@ def test_admin_can_delete_product(api_client, admin_user, get_token):
6262 response = api_client .delete (f"/api/products/{ product .id } /" )
6363
6464 assert response .status_code == 204
65+
66+ @pytest .mark .django_db
67+ def test_client_sees_only_own_products (api_client , client_user , get_token ):
68+ ProductFactory .create_batch (3 , owner = client_user )
69+ ProductFactory .create_batch (2 )
70+
71+ token = get_token (client_user )
72+ api_client .credentials (HTTP_AUTHORIZATION = f"Bearer { token } " )
73+
74+ response = api_client .get ("/api/products/" )
75+ assert len (response .data ) == 3
76+
77+
78+ @pytest .mark .django_db
79+ def test_staff_sees_only_public_products (api_client , staff_user , get_token ):
80+ ProductFactory .create_batch (2 , is_public = True )
81+ ProductFactory .create_batch (2 , is_public = False )
82+
83+ token = get_token (staff_user )
84+ api_client .credentials (HTTP_AUTHORIZATION = f"Bearer { token } " )
85+
86+ response = api_client .get ("/api/products/" )
87+ assert len (response .data ) == 2
88+
89+
90+ @pytest .mark .django_db
91+ def test_admin_sees_all_products (api_client , admin_user , get_token ):
92+ ProductFactory .create_batch (5 )
93+
94+ token = get_token (admin_user )
95+ api_client .credentials (HTTP_AUTHORIZATION = f"Bearer { token } " )
96+
97+ response = api_client .get ("/api/products/" )
98+ assert len (response .data ) == 5
0 commit comments