Beispiel #1
0
    def test_mention_event(self):
        user = User({"username": "******", "ext_id": "test"})
        user.save()
        other_user = User({"username": "******", "ext_id": "other"})
        other_user.save()

        p = Question({
            "title": "test title",
            "body": "test body, @test is mentioned",
            "tags": ["test-tag"],
            "author_id": user._id
        })
        p.save()
        self.run_tasks()
        events = user.get_new_events()
        self.assertEqual(events.count(), 0)

        a = p.create_answer({
            "author_id": other_user._id,
            "body": "this @test mention should create an event"
        })
        a.save()
        self.run_tasks()

        events = user.get_new_events()
        self.assertEqual(events.count(), 2)  # new comment event and mention event

        found_mention_event = False
        for event in events:
            if isinstance(event, MentionEvent):
                found_mention_event = True
                self.assertEqual(event.author_id, other_user._id)
                self.assertEqual(event.post_id, a._id)
        self.assertTrue(found_mention_event)
Beispiel #2
0
    def test_question_new_answer_event(self):
        user = User({"username": "******", "ext_id": "test"})
        user.save()
        other_user = User({"username": "******", "ext_id": "other"})
        other_user.save()

        p = Question({
            "title": "test title",
            "body": "test body, needs to be long",
            "tags": ["test-tag", "test-tag2"],
            "author_id": user._id
        })
        p.save()
        self.run_tasks()
        Event.destroy_all()

        a = p.create_answer({
            "body": "this is a self-answer, should not generate events",
            "author_id": user._id
        })
        a.save()
        self.run_tasks()

        events = user.get_new_events()
        self.assertEqual(events.count(), 0)

        a = p.create_answer({
            "body": "this is an answer by somebody else",
            "author_id": other_user._id
        })
        a.save()
        self.run_tasks()

        events = user.get_new_events()
        self.assertEqual(events.count(), 1)

        event: QuestionNewAnswerEvent = events[0]
        self.assertEqual(event.question_id, p._id)
        self.assertEqual(event.answer_id, a._id)
        self.assertEqual(event.author_id, other_user._id)
Beispiel #3
0
    def test_post_comment_event(self):
        user = User({"username": "******", "ext_id": "test"})
        user.save()
        other_user = User({"username": "******", "ext_id": "other"})
        other_user.save()

        p = Question({
            "title": "test title",
            "body": "test body, needs to be long",
            "tags": ["test-tag", "test-tag2"],
            "author_id": user._id
        })
        p.save()
        self.run_tasks()
        Event.destroy_all()

        c = p.create_comment({
            "body": "this is a self-comment, should not generate events",
            "author_id": user._id
        })
        c.save()
        self.run_tasks()

        events = user.get_new_events()
        self.assertEqual(events.count(), 0)

        c = p.create_comment({
            "body": "this is a real comment, should generate an event",
            "author_id": other_user._id
        })
        c.save()
        self.run_tasks()

        events = user.get_new_events()
        self.assertEqual(events.count(), 1)

        event: PostNewCommentEvent = events[0]
        self.assertEqual(event.post_id, p._id)
        self.assertEqual(event.comment_id, c._id)
        self.assertEqual(event.author_id, other_user._id)
Beispiel #4
0
    def test_tag_new_post_event(self):
        u = User({"username": "******", "ext_id": "test"})
        u.save()
        u.subscribe_to_tag("test-tag")
        u.subscribe_to_tag("test-tag2")
        u.subscribe_to_tag("test-tag3")

        p = Question({
            "title": "test title",
            "body": "test body, needs to be long",
            "tags": ["test-tag", "test-tag2"],
            "author_id": u._id
        })
        p.save()
        self.run_tasks()

        events = u.get_new_events()
        self.assertEqual(events.count(), 0)

        other_user = User({"username": "******", "ext_id": "other"})
        other_user.save()

        p = Question({
            "title": "test title",
            "body": "test body, needs to be long",
            "tags": ["test-tag", "test-tag2"],
            "author_id": other_user._id
        })
        p.save()
        self.run_tasks()
        events = u.get_new_events()
        self.assertEqual(events.count(), 1)
        event: TagNewQuestionEvent = events[0]

        # only subscribed tags are listed in event
        self.assertCountEqual(event.tags, ["test-tag", "test-tag2"])
        self.assertEqual(event.question_id, p._id)