Example #1
0
    def testComments(self):
        session = self.Session()

        #
        # - Comment(1) (3 Revisions)
        #   |
        #    - Reply Comment(2)
        #      |
        #       - Another Reply Comment(3)
        #

        comment1 = Comment(id=1, parent_id=None, founder_id=1)
        comment2 = Comment(id=2, parent_id=1, founder_id=1)
        comment3 = Comment(id=3, parent_id=2, founder_id=1)

        comment_rev1 = CommentHistory(id=1,
                                      revision=1,
                                      created=datetime.now(),
                                      author_id=1,
                                      comment_id=1,
                                      body="U Suk!")
        comment_rev2 = CommentHistory(id=2,
                                      revision=2,
                                      created=datetime.now(),
                                      author_id=1,
                                      comment_id=1,
                                      body="U Suk More!")
        comment_rev3 = CommentHistory(id=3,
                                      revision=3,
                                      created=datetime.now(),
                                      author_id=1,
                                      comment_id=1,
                                      body="U Suk Even More!")
        for cr in [comment_rev1, comment_rev2, comment_rev3]:
            comment1.history.append(cr)

        session.add(comment1)
        session.add(comment2)
        session.add(comment3)

        session.flush()
        self.assertTrue(str(comment1).startswith('<Comment'),
                        msg="str(Comment) must start with '<Comment'")
        self.assertEqual(comment1, comment_rev1.comment)
        self.assertEqual(comment1, comment_rev2.comment)
        self.assertEqual(comment1, comment_rev3.comment)
        self.assertEqual(comment1.history,
                         [comment_rev1, comment_rev2, comment_rev3])
        self.assertEqual(comment1.replies, [comment2])
        self.assertEqual(comment2.replies, [comment3])
        self.assertEqual(comment2.parent_comment, comment1)
Example #2
0
    def testPosts(self):
        session = self.Session()

        post = Post(id=1, founder_id=1, group_id=1)

        post_rev1 = PostHistory(revision=1,
                                created=datetime.now(),
                                author_id=1,
                                description="This is an assignment.")
        post_rev2 = PostHistory(revision=2,
                                created=datetime.now(),
                                author_id=2,
                                description="This is another assignment.")
        post_rev3 = PostHistory(revision=3,
                                created=datetime.now(),
                                author_id=3,
                                description="This is the last assignment.")
        for p in [post_rev1, post_rev2, post_rev3]:
            post.history.append(p)
        session.add(post)

        comment = Comment(id=1, founder_id=1)
        comment1 = Comment(id=2, founder_id=1)
        comment2 = Comment(id=3, founder_id=1)
        for c in [comment, comment1, comment2]:
            session.add(c)

        post_comment = PostComment(post_id=1, comment_id=1)
        post_comment1 = PostComment(post_id=1, comment_id=2)
        post_comment2 = PostComment(post_id=1, comment_id=3)
        for pc in [post_comment, post_comment1, post_comment2]:
            session.add(pc)

        tag = Tag(id=1, name='Test')
        session.add(tag)

        post_tag = PostTag(id=1, post_id=1, tag_id=1)
        post.post_tags.append(post_tag)

        session.flush()
        self.assertTrue(str(post).startswith('<Post'),
                        msg="str(Post) must start with '<Post'")
        self.assertEqual(post.history, [post_rev1, post_rev2, post_rev3])
        self.assertEqual(post_rev1.post, post)
        self.assertEqual(post_rev2.post, post)
        self.assertEqual(post_rev3.post, post)
        self.assertEqual(post.comments, [comment, comment1, comment2])
        self.assertEqual(comment.post, post)
        self.assertEqual(comment1.post, post)
        self.assertEqual(comment2.post, post)
        self.assertIn(tag, post.tags)
Example #3
0
    def testVotes(self):
        session = self.Session()

        user = User(id=1,
                    username="******",
                    email="*****@*****.**",
                    joined=datetime.now(),
                    last_online=datetime.now())
        group = Group(id=1,
                      name="My cool group",
                      created=datetime.now(),
                      edited=datetime.now())
        comment = Comment(id=1, founder_id=1)
        #upvote
        vote = Vote(id=1, user_id=1, comment_id=1, vote=1)

        session.add(group)
        session.add(user)
        session.add(comment)
        session.add(vote)

        session.flush()
        self.assertTrue(str(vote).startswith('<Vote'),
                        msg="str(Vote) must start with '<Vote'")
        self.assertIn(vote, user.votes)
        self.assertEqual(user, vote.user)
        self.assertIn(vote, comment.votes)
        self.assertEqual(comment, vote.comment)
Example #4
0
    def testUsers(self):
        session = self.Session()

        user = User(id=1,
                    username="******",
                    email="*****@*****.**",
                    joined=datetime.now(),
                    last_online=datetime.now())
        auth_user = AuthUser('jayd3e', 'secret')
        post = Post(id=1, founder_id=1, group_id=1)
        question = Question(id=1, created=datetime.now(), founder_id=1)
        group = Group(id=1,
                      name="My cool group",
                      created=datetime.now(),
                      edited=datetime.now())
        comment = Comment(id=1)

        user.auth_user = auth_user
        user.posts.append(post)
        user.questions.append(question)
        user.founded_groups.append(group)
        user.comments.append(comment)
        session.add(user)

        # Moderator of founded group
        moderator = Moderator(user_id=1, group_id=1)
        session.add(moderator)

        # Subscribed to founded group
        subscription = Subscription(user_id=1, group_id=1)
        session.add(subscription)

        session.flush()
        self.assertTrue(
            str(subscription).startswith('<Subscription'),
            msg="str(Subscription) must start with '<Subscription'")
        self.assertEqual(user.auth_user, auth_user)
        self.assertEqual(auth_user.user, user)
        self.assertIn(post, user.posts)
        self.assertEqual(post.founder, user)
        self.assertIn(question, user.questions)
        self.assertEqual(question.founder, user)
        self.assertIn(group, user.founded_groups)
        self.assertEqual(user, group.founder)
        self.assertIn(comment, user.comments)
        self.assertEqual(user, comment.founder)
        self.assertIn(group, user.subscribed_groups)
        self.assertIn(user, group.subscribers)
        self.assertIn(user, group.moderators)
        self.assertIn(group, user.moderated_groups)
def reply(session, _id):
    comment = Comment(parent_id=_id,
                      founder_id=1,
                      created=datetime.now())
    session.add(comment)
    session.flush()
    comment_rev = CommentHistory(revision=1,
                                 created=datetime.now(),
                                 author_id=1,
                                 comment_id=comment.id,
                                 body="This is branch with parent_comment=" + str(_id) + " comment=" + str(comment.id))
    session.add(comment_rev)

    if random.randint(0, 1) == 1:
        reply(session, comment.id)
Example #6
0
    def testPostComments(self):
        session = self.Session()

        post = Post(id=1, founder_id=1, group_id=1)
        comment = Comment(id=1, founder_id=1)
        post_comment = PostComment(post_id=1, comment_id=1)
        session.add(post)
        session.add(comment)
        session.add(post_comment)

        session.flush()
        self.assertTrue(str(post_comment).startswith('<PostComment'),
                        msg="str(PostComment) must start with '<PostComment'")
        self.assertEqual(post_comment.post, post)
        self.assertEqual(post_comment.comment, comment)
        self.assertEqual(post_comment, comment.post_comment)
        self.assertIn(post_comment, post.post_comments)
Example #7
0
    def testQuestionComments(self):
        session = self.Session()

        question = Question(id=1, created=datetime.now(), founder_id=1)
        comment = Comment(id=1, founder_id=1)
        question_comment = QuestionComment(question_id=1, comment_id=1)
        session.add(question)
        session.add(comment)
        session.add(question_comment)

        session.flush()
        self.assertTrue(
            str(question_comment).startswith('<QuestionComment'),
            msg="str(QuestionComment) must start with '<QuestionComment'")
        self.assertEqual(question_comment.question, question)
        self.assertEqual(question_comment.comment, comment)
        self.assertEqual(question_comment, comment.question_comment)
        self.assertIn(question_comment, question.question_comments)
Example #8
0
    def testQuestionCommentNotifications(self):
        session = self.Session()

        user = User(id=1,
                    username="******",
                    email="*****@*****.**",
                    joined=datetime.now(),
                    last_online=datetime.now())
        question = Question(id=1, created=datetime.now(), founder_id=1)
        comment = Comment(id=1, founder_id=1)
        question_comment = QuestionComment(question_id=1, comment_id=1)
        session.add(user)
        session.add(question)
        session.add(comment)
        session.add(question_comment)
        session.flush()

        question_comment_notification = QuestionCommentNotification(
            created=datetime.now(),
            discriminator="question_comment",
            user_id=user.id,
            comment_id=comment.id,
            question_id=question.id)
        session.add(question_comment_notification)
        session.flush()

        notification = Notification(
            user_id=user.id,
            notification_item_id=question_comment_notification.id)
        session.add(notification)
        session.flush()
        self.assertTrue(
            str(question_comment_notification).startswith(
                '<QuestionCommentNotification'),
            msg=
            "str(QuestionCommentNotification) must start with '<QuestionCommentNotification'"
        )
        self.assertIn(question_comment_notification, user.notifications)
        self.assertEqual(user, notification.user)
        self.assertEqual(user, question_comment_notification.commenter)
        self.assertEqual(comment, question_comment_notification.comment)
        self.assertEqual(question, question_comment_notification.question)
def data():
    num_of_groups = 3
    num_of_posts = 10
    num_of_histories = 5
    num_of_comments = 5
    num_of_replies = 5
    num_of_statuses = 5

    engine = create_engine('postgresql+psycopg2://vagrant:fluffy&Bunny@localhost/clusterflunk')
    Session = sessionmaker(bind=engine)
    session = Session()

    network = Network(id=1,
                      name="Uni of Iowa",
                      created=datetime.now())
    session.add(network)

    user = User(id=1,
                username="******",
                email="*****@*****.**",
                joined=datetime.now(),
                last_online=datetime.now())
    auth_user = AuthUser("jayd3e", "blah7")
    user.auth_user = auth_user
    session.add(user)

    membership = Membership(id=1,
                            user_id=1,
                            network_id=1)
    session.add(membership)

    for i in range(num_of_groups + 1):
        group = Group(id=int(i),
                      name="Physics 10" + str(i),
                      network_id=1,
                      created=datetime.now(),
                      edited=datetime.now(),
                      founder_id=1)
        subscription = Subscription(user_id=1,
                                    group_id=int(i))
        session.add(subscription)
        session.add(group)

        for j in range(num_of_statuses + 1):
            question = Question(created=datetime.now(),
                                founder_id=1)
            session.add(question)
            session.flush()
            for k in range(num_of_histories + 1):
                question_len = len(questions)
                question_num = random.randint(0, question_len - 1)

                question_rev = QuestionHistory(revision=int(k),
                                               author_id=1,
                                               question_id=question.id,
                                               created=datetime.now(),
                                               body=questions[question_num])
                question.history.append(question_rev)

            broadcast = Broadcast(question_id=question.id,
                                  group_id=int(i))
            session.add(broadcast)

        session.flush()

    for i in range(num_of_posts + 1):
        post = Post(id=int(i),
                    founder_id=1,
                    group_id=random.randint(1, num_of_groups),
                    created=datetime.now())
        session.add(post)
        session.flush()
        for j in range(num_of_histories + 1):
            post_rev = PostHistory(revision=int(j),
                                   author_id=1,
                                   post_id=post.id,
                                   created=datetime.now(),
                                   name="Post #" + str(i) + str(j),
                                   description="This is a description.  Version #" + str(j))
            post.history.append(post_rev)

        for k in range(num_of_comments + 1):
            comment = Comment(parent_id=None,
                              founder_id=1,
                              created=datetime.now())
            session.add(comment)
            session.flush()
            post_comment = PostComment(post_id=post.id,
                                       comment_id=comment.id)
            comment_rev = CommentHistory(revision=1,
                                         created=datetime.now(),
                                         author_id=1,
                                         comment_id=comment.id,
                                         body="U Suk!")
            session.add(post_comment)
            session.add(comment_rev)

            for l in range(num_of_replies + 1):
                reply(session, comment.id)

    session.flush()
    session.commit()