Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1.     def test_add_to_cart(self):
  2.         # self.api_client.client.login(username=self.username, password=self.password)
  3.  
  4.         # get categories
  5.         response = self.api_client.get(
  6.             '/api/v1/category/',
  7.             # authentication=self.get_credentials()
  8.         )
  9.         categories = self.deserialize(response)
  10.  
  11.         # get single category
  12.         category = categories['objects'][0]
  13.  
  14.         # get products list from category
  15.         response = self.api_client.get(
  16.             '/api/v1/product/?category={}'.format(category['id']),
  17.             # authentication=self.get_credentials()
  18.         )
  19.         products = self.deserialize(response)
  20.         product = products['objects'][0]
  21.  
  22.         # get cart
  23.         response = self.api_client.get(
  24.             '/api/v1/cart/{}/'.format(self.user.cart.id),
  25.             # authentication=self.get_credentials()
  26.         )
  27.         cart = self.deserialize(response)
  28.  
  29.         # insert product to cart (create cart item)
  30.         response = self.api_client.post(
  31.             '/api/v1/cart_item/1/',
  32.             data=dict(
  33.                 cart=cart,
  34.                 product=product,
  35.                 amount=1,
  36.             ),
  37.             # authentication=self.get_credentials()
  38.         )
  39.  
  40.         print response
  41.         print response.status_code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement