def test_delete_a_category(self): """ Delete a Category """ category = Category(name="Dog") category.save() self.assertEqual(len(Category.all()), 1) # delete the category and make sure it isn't in the database category.delete() self.assertEqual(len(Category.all()), 0)
def test_add_a_category(self): """ Create a category and add it to the database """ categories = Category.all() self.assertEqual(categories, []) category = Category(name="Dog") self.assertTrue(category != None) self.assertEqual(category.id, None) category.save() # Asert that it was assigned an id and shows up in the database self.assertNotEqual(category.id, None) categories = Category.all() self.assertEqual(len(categories), 1)
def test_update_a_category(self): """ Update a Category """ category = Category(name="Dog") category.save() self.assertNotEqual(category.id, None) category_id = category.id # Change it an save it category.name = "K9" category.save() self.assertEqual(category.id, category_id) # Fetch it back and make sure the id hasn't changed # but the data did change categories = Category.all() self.assertEqual(len(categories), 1) self.assertEqual(categories[0].name, "K9")