def setUp(self):
     create_tables()
     # create some items
     self.person = Person.create(firstname="Steve", lastname="Loria")
     self.person2 = Person.create(firstname="Monty", lastname="Python")
     self.item = Item.create(name="Foo", person=self.person)
     self.item2 = Item.create(name="Bar")
 def setUp(self):
     create_tables()
     # create some items
     self.person = Person.create(firstname="Steve", lastname="Loria")
     self.person2 = Person.create(firstname="Monty", lastname="Python")
     self.item = Item.create(name="Foo", person=self.person)
     self.item2 = Item.create(name="Bar")
 def test_put_item(self):
     res = self._put_json(
         "/api/v1/items/{0}".format(self.item.id), {"checked_out": True, "person_id": self.person2.id}
     )
     item = Item.get(Item.id == self.item.id)
     assert_true(item.checked_out)
     assert_equal(item.person, self.person2)
 def test_post_item(self):
     res = self._post_json("/api/v1/items/", {"name": "Ipad", "checked_out": True})
     assert_equal(res.status_code, 201)
     item = Item.select().order_by(Item.updated.desc()).first()
     assert_true(item is not None)
     assert_equal(item.name, "Ipad")
     assert_true(item.checked_out)
 def test_post_item_with_person_id(self):
     res = self._post_json('/api/v1/items/', {
         "name": "Ipod",
         "person_id": self.person.id
     })
     assert_equal(res.status_code, 201)
     item = Item.select().order_by(Item.updated.desc()).first()
     assert_equal(item.person, self.person)
 def test_put_item(self):
     res = self._put_json("/api/v1/items/{0}".format(self.item.id), {
         "checked_out": True,
         "person_id": self.person2.id
     })
     item = Item.get(Item.id == self.item.id)
     assert_true(item.checked_out)
     assert_equal(item.person, self.person2)
 def test_post_item(self):
     res = self._post_json("/api/v1/items/", {
         "name": "Ipad",
         'checked_out': True
     })
     assert_equal(res.status_code, 201)
     item = Item.select().order_by(Item.updated.desc()).first()
     assert_true(item is not None)
     assert_equal(item.name, "Ipad")
     assert_true(item.checked_out)
 def test_delete_item(self):
     all_items = [i for i in Item.select()]
     assert_in(self.item, all_items)
     res = self.client.delete("/api/v1/items/{0}".format(self.item.id))
     all_items = [i for i in Item.select()]
     assert_not_in(self.item, all_items)
 def test_post_item_with_person_id(self):
     res = self._post_json("/api/v1/items/", {"name": "Ipod", "person_id": self.person.id})
     assert_equal(res.status_code, 201)
     item = Item.select().order_by(Item.updated.desc()).first()
     assert_equal(item.person, self.person)
 def test_delete_item(self):
     all_items = [i for i in Item.select()]
     assert_in(self.item, all_items)
     res = self.client.delete("/api/v1/items/{0}".format(self.item.id))
     all_items = [i for i in Item.select()]
     assert_not_in(self.item, all_items)