def test_add_diary_to_cart_using_post(self): # create form data with a product containing variations and simulate POST post = { 'product_action': 'add_to_cart', 'add_item_id': self.diary.id, 'add_item_quantity': 1, 'add_item_option_group_1': 2, # Color: green 'add_item_text_option_1': 'Doctor Diary', # Engraving } request = self._get_post_request(post) view = DiaryDetailView(request=request, kwargs={'pk': self.diary.id}) view.post() ret = self._get_from_cart() # check if the product is in the cart self.assertEqual(len(ret['cart_items']), 1) values = ret['cart_items'].values()[0] self.assertEqual(values['product_id'], self.diary.id) self.assertEqual(values['quantity'], 1) variation = json.loads(values['variation']) self.assertEqual(variation['option_groups']['1']['name'], 'Color') self.assertEqual(variation['option_groups']['1']['option']['name'], 'green') self.assertEqual(variation['text_options']['1']['text'], 'Doctor Diary') # add the same product with missing quantity field del post['add_item_quantity'] request = self._get_post_request(post) view = DiaryDetailView(request=request, kwargs={'pk': self.diary.id}) view.post() ret = self._get_from_cart() values = ret['cart_items'].values()[0] self.assertEqual(values['quantity'], 2)
def test_get_templates_return_expected_values(self): view = DiaryDetailView() setattr(view, 'object', None) tmp = view.get_template_names() self.assertGreaterEqual(len(tmp), 1)
def test_get_product_returns_correctly(self): request = Mock() view = DiaryDetailView(request=request, kwargs={'pk': self.diary.id}) setattr(view, 'object', None) obj = view.get_object() self.assertTrue(isinstance(obj, DiaryProduct))