Ejemplo n.º 1
0
    def test_tags(self):
        q = Question.create(
            author_id=self.user._id,
            title='How to patch KDE on FreeBSD?',
            body="subjxxxxxx",
            tags=["kde", "freebsd", "anime"],
        )
        q.save()
        self.run_tasks()

        cnt = 0
        for tag in Tag.find():
            cnt += 1
            self.assertEqual(tag.questions_count, 1)
        self.assertEqual(cnt, len(q.tags))

        q2 = Question.create(
            author_id=self.user._id,
            title='TCPDump on FreeBSD',
            body="Does FreeBSD has a linux-like tcpdump or it's been as usual",
            tags=["freebsd", "tcpdump"],
        )
        q2.save()
        self.run_tasks()

        t = Tag.get("freebsd")
        self.assertEqual(t.questions_count, 2)

        q2.destroy()
        q.destroy()
        self.run_tasks()
        self.assertEqual(Tag.find().count(),
                         4)  # tags are not deleted automatically anymore
Ejemplo n.º 2
0
    def test_hrid(self):
        q = Question.create(
            author_id=self.user._id,
            title='How to patch KDE on FreeBSD?',
            body="subjxxxxxx",
            tags=["kde", "freebsd", "anime"],
        )
        q.save()
        self.run_tasks()
        self.assertEqual(q.human_readable_id, "how-to-patch-kde-on-freebsd")

        q = Question.create(
            author_id=self.user._id,
            title='How to patch KDE on FreeBSD?',
            body="subjxxxxxx",
            tags=["kde", "freebsd", "anime"],
        )
        q.save()
        self.run_tasks()
        self.assertEqual(q.human_readable_id, "how-to-patch-kde-on-freebsd_1")
Ejemplo n.º 3
0
    def test_substitutions(self):
        ctx.cfg["substitutions"] = (
            (r"\b([A-Z]+-\d+)\b",
             r"[\1](https://jira.example.com/browse/\1)"), )

        q = Question.create(
            author_id=self.user._id,
            title='How to patch KDE on FreeBSD?',
            body="Is that exactly what is meant in MYPROJ-338?",
            tags=["kde", "freebsd", "anime"],
        )

        q.save()
        self.run_tasks()

        self.assertEqual(
            q.body, "Is that exactly what is meant in "
            "[MYPROJ-338](https://jira.example.com/browse/MYPROJ-338)?")

        a = q.create_answer({
            "author_id": self.user._id,
            "body": "No, it's not. It's actually MYPROJ-42"
        })
        a.save()
        self.run_tasks()

        self.assertEqual(
            a.body, "No, it's not. It's actually "
            "[MYPROJ-42](https://jira.example.com/browse/MYPROJ-42)")
        a.save()

        c = a.create_comment({
            "author_id":
            self.user._id,
            "body":
            "MYPROJ-338 looks more promising. Well, MYPROJ-42 is OK too.",
        })

        c.save()
        self.run_tasks()

        self.assertEqual(
            c.body,
            "MYPROJ-338 looks more promising. Well, MYPROJ-42 is OK too.")
Ejemplo n.º 4
0
 def create(self):
     self.create_users()
     ctx.log.info("generating questions")
     for iq in range(QUESTION_COUNT):
         title = requests.get("https://fish-text.ru/get?type=title").json()["text"]
         text = self.random_paragraph()
         tags = self.random_tags()
         q = Question.create(body=text, title=title, tags=tags, author_id=self.random_user()._id)
         q.save()
         for ic in range(random.randrange(MAX_COMMENTS)):
             text = requests.get("https://fish-text.ru/get?type=sentence").json()["text"]
             c = q.create_comment(dict(author_id=self.random_user()._id, body=text))
             c.save()
         for ac in range(random.randrange(MAX_ANSWERS)):
             text = self.random_paragraph()
             a = q.create_answer(dict(author_id=self.random_user()._id, body=text))
             a.save()
             for ic in range(random.randrange(MAX_COMMENTS)):
                 text = requests.get("https://fish-text.ru/get?type=sentence").json()["text"]
                 c = a.create_comment(dict(author_id=self.random_user()._id, body=text))
                 c.save()
     for task in ctx.queue.tasks:
         wrk.run_task(task)