def test_shopper_can_claim_requested_item(self): shopper = test_utils.create_shopper() requested_item = test_utils.create_requested_item(shopper=shopper) self.login_user(shopper.user) self.claim_item(requested_item) requested_item.refresh_from_db() self.assertEqual(requested_item.shopper, shopper)
def test_owner_of_requested_item_can_delete(self): requested_item = test_utils.create_requested_item() requested_item_pk = requested_item.pk self.login_user(requested_item.requester.user) self.delete_requested_item(requested_item) self.assertFalse( RequestedItem.objects.filter(pk=requested_item_pk).exists())
def test_unauthorized_user_cannot_delete_comment(self): requested_item = test_utils.create_requested_item( shopper=test_utils.create_shopper()) comment = test_utils.create_comment(requested_item=requested_item) requester = test_utils.create_requester() self.login_user(requester.user) resp = self.delete_comment(comment) self.assertResponseIsPermissionDenied(resp)
def test_user_can_delete_comment(self): shopper = test_utils.create_shopper() requested_item = test_utils.create_requested_item(shopper=shopper) comment = test_utils.create_comment(author=shopper.user, requested_item=requested_item) self.assertEqual(requested_item.comments.count(), 1) self.login_user(shopper.user) resp = self.delete_comment(comment) self.assertEqual(requested_item.comments.count(), 0)
def test_user_can_create_comment(self): comment_body = 'Bar' shopper = test_utils.create_shopper() requested_item = test_utils.create_requested_item(shopper=shopper) self.login_user(shopper.user) self.create_comment(requested_item, {'body': comment_body}) requested_item.refresh_from_db() self.assertEqual(requested_item.comments.count(), 1) comment = requested_item.comments.first() self.assertEqual(comment_body, comment.body)
def test_unauthorized_user_cannot_create_comment(self): requested_item = test_utils.create_requested_item() requester = test_utils.create_requester() self.login_user(requester.user) resp = self.create_comment(requested_item, {'body': 'Foo'}) self.assertResponseIsPermissionDenied(resp)
def test_unauthorized_shopper_cannot_claim_requested_item(self): requested_item = test_utils.create_requested_item() shopper = test_utils.create_shopper() self.login_user(shopper.user) resp = self.claim_item(requested_item) self.assertResponseIsPermissionDenied(resp)
def test_shopper_cannot_delete_requested_items(self): shopper = test_utils.create_shopper() requested_item = test_utils.create_requested_item() self.login_user(shopper.user) resp = self.delete_requested_item(requested_item) self.assertResponseIsPermissionDenied(resp)
def test_requested_items_default_ordering_priority_descending(self): medium = utils.create_requested_item(priority=RequestedItem.MEDIUM) high = utils.create_requested_item(priority=RequestedItem.HIGH) low = utils.create_requested_item(priority=RequestedItem.LOW) self.assertEqual(list(RequestedItem.objects.all()), [high, medium, low])