Ejemplo n.º 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)
Ejemplo n.º 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)