def test_delete_feeditem_with_comments(self): feeditem = new_feeditem(self.user, project=self.project, content="content", save=True) comment = new_comment(self.user, feeditem.key, save=True) self.login() response = self.delete(self.base_url("/" + feeditem.key)) self.assertStatus(200, response) with self.assertRaises(NotFoundError): FeedItem.get(feeditem.key) with self.assertRaises(NotFoundError): Comment.get(comment.key)
def new_comment(user, parent, **kwargs): save = kwargs.pop("save", False) key = kwargs.pop("key", None) kwargs["parent"] = parent if key: comment = Comment(key=key, data=kwargs) else: comment = Comment(data=kwargs) comment.author = user if save: comment.save() return comment
def test_delete_todo_with_comments(self): todo1 = new_todo(self.user, self.project, save=True) comment = new_comment(self.user, todo1.key, save=True) self.login() response = self.delete(self.base_url("/" + todo1.key), query_string={"really": "1"}) self.assertStatus(200, response) with self.assertRaises(NotFoundError): Todo.get(todo1.key) with self.assertRaises(NotFoundError): ArchivedTodo.get(todo1.key) with self.assertRaises(NotFoundError): Comment.get(comment.key)
def new_comment(user, parent, **kwargs): save = kwargs.pop("save", False) key = kwargs.pop("key", None) if isinstance(parent, Document): parent = parent.key kwargs["parent"] = parent if key: comment = Comment(key=key, data=kwargs) else: comment = Comment(data=kwargs) comment.author = user if save: comment.save() return comment
def test_new_comment_for_feed(self): feeditem = new_feeditem(self.user, self.project, content="content", save=True) self.login() response, data = self.postJSON(self.base_url(feeditem.key), data={"content": "content"}) self.assertStatus(200, response) key = data["key"] response, data = self.getJSON("/api/v1/projects/{}/feed/{}".format(self.project.key, feeditem.key)) self.assertEquals(1, len(data["children"])) self.assertEquals(key, data["children"][0]["key"]) self.assertEquals(self.user.key, data["children"][0]["author"]["key"]) self.logout() user2 = self.create_user("*****@*****.**") self.project.collaborators.append(user2.key) self.project.save() self.login(user2) response, data = self.postJSON(self.base_url(feeditem.key), data={"content": "content"}) self.assertStatus(200, response) key = data["key"] # to fix issues where the datetime is the same and sort order gets weirded out. comment = Comment.get(key) comment.date = datetime.now() + timedelta(1) comment.save() response, data = self.getJSON("/api/v1/projects/{}/feed/{}".format(self.project.key, feeditem.key)) self.assertEquals(2, len(data["children"])) self.assertEquals(key, data["children"][1]["key"]) self.assertEquals(user2.key, data["children"][1]["author"]["key"]) self.project.collaborators.remove(user2.key) self.project.save()