def test_add_item_via_hash(self): from onelist.apps.lists.helpers import generate_hash user = g.User.get(email="*****@*****.**") hash = generate_hash("*****@*****.**") # Page loads rv = self.client.get(url_for("lists.add_item_via_hash", hash=hash)) self.assertEqual(rv.status_code, 200) # Can add a new item before_item_count = len(list(g.ListItem.get_for_user(user))) rv = self.client.post( url_for("lists.add_item_via_hash", hash=hash), data={"text-add": "New list item"}, follow_redirects=True ) after_item_count = len(list(g.ListItem.get_for_user(user))) self.assertEqual(rv.status_code, 200) assert "by_hash" in rv.data self.assertNotEqual(before_item_count, after_item_count) assert "Sorry, an error has occurred" not in rv.data
def create(self, user): kwargs = {'user_id': user.id, 'hash': generate_hash(user.email)} return super(ListModel, self).create(**kwargs)