def test_14(self, m='Deleted post should be deleted'): p = Post({"title": "Another original post", "contents":"This is the content", "tags":"music,guitar,test", "author":"*****@*****.**"}) p.validate() p.save() retrieved_post = Post.get(p.pk()) retrieved_post.delete() retrieved_post.is_deleted() |should| equal_to(True) Post.get(p.pk()) |should| equal_to(None)
def test_12(self, m="Post should be retrieved by it's pk"): p = Post({"title": "This is the second test", "contents":"This is the content", "tags":"music,guitar,test", "author":"*****@*****.**"}) p.validate() p.is_new() |should| equal_to(True) p.save() p.is_new() |should_not| equal_to(True) retrieved_post = Post.get(p.pk()) retrieved_post |should| equal_to(p) retrieved_post.is_new() |should| equal_to(False)
def add(self, **kvals): if len(kvals): post = Post(kvals) post.validate() if post.is_valid(): post.save() return self.redirect("/post/%s" % post.pk()) else: post = Post() return self.render("post/add", post=post)
def test_01(self, m="Cassandra should enable finding posts by author"): yanekk_post = Post({"title": "This is the post by Yanekk", "contents":"yanekk yanekk yanekk", "tags":"music,guitar,test", "author":"*****@*****.**"}) yanekk_post.validate() yanekk_post.save() second_yanekk_post = Post({"title": "Another post by Yanekk", "contents":"yanekk yanekk yanekk", "tags":"music,guitar,test", "author":"*****@*****.**"}) second_yanekk_post.validate() second_yanekk_post.save() zbyszek_post = Post({"title": "Post by zbyszek", "contents":"yanekk yanekk yanekk", "tags":"music,guitar,test", "author":"*****@*****.**"}) zbyszek_post.validate() zbyszek_post.save() yanekk_posts = Post.by_index("author", "==", "*****@*****.**") zbyszek_posts = Post.by_index("author", "==", "*****@*****.**") yanekk_posts |should| contain(yanekk_post) yanekk_posts |should| contain(second_yanekk_post) yanekk_posts |should_not| contain(zbyszek_post) zbyszek_posts |should| contain(zbyszek_post) zbyszek_posts |should_not| contain(yanekk_post)
def test_11(self, m="Validated Post should be able to save"): p = Post({"title": "This is the test", "contents":"This is the content", "tags":"music,guitar,test", "author":"*****@*****.**"}) p.validate() p.is_valid() |should| equal_to(True) len(p.errors()) |should| equal_to(0) p.save() |should_not| throw(ModelNotValid)
def test_01(self, m="Post should not validate without title, contents, tags and author"): p = Post({"title": "", "contents":"", "tags":"", "author":""}) p.validate() p.is_valid() |should| equal_to(False) len(p.errors()) |should| equal_to(4)
def test_09(self, m="Validated Post should set it's pk to time uuid"): p = Post({"title": "What's the best answe' for 1969", "contents":"This is the content", "tags":"music,guitar,test", "author":"*****@*****.**"}) p.validate() len(p.pk()) |should| equal_to(36) p.pk() |should| be_like('^[\w\d]{8}\-[\w\d]{4}\-[\w\d]{4}\-[\w\d]{4}\-[\w\d]{12}$')
def test_06(self, m="Post should validate"): p = Post({"title": "This is the test", "contents":"This is the content", "tags":"music,guitar,test", "author":"*****@*****.**"}) p.validate() p.is_valid() |should| equal_to(True) len(p.errors()) |should| equal_to(0)
def test_05(self, m="Post should not validate without author email"): p = Post({"title": "This is the test", "contents":"This is the content", "tags":"music,guitar,test", "author":"yanekk"}) p.validate() p.is_valid() |should| equal_to(False) len(p.errors()) |should| equal_to(1)