def add_role(name): """ Add New Post Category """ try: c = Category() c.name = name c.set_slug(name) c.description = 'Default Description' c.save() except Exception as exp: print(exp) else: print(c.__repr__()) del c
def test_04_category_repr_save_and_delete(self): self.assertTrue(Category.query.count() == 0) Category.add_none() category = Category(name='tester', parent_category=Category.query.get(1)) category.save() self.assertTrue( '<Category tester Parent None Son []>' == category.__repr__()) self.assertTrue(Category.query.count() == 2) post = Post(body='# Post Big title', category=category) post.save() self.assertTrue(category.posts.count() == 1) category.delete() self.assertTrue(Category.query.count() == 1) self.assertTrue(post.category_id == 1)