예제 #1
0
    def test(self):  # noqa: WPS210
        factory: Generator = Faker()

        chapter_name: str = factory.paragraph()
        chapter_order_number: int = 1

        chapter = Chapter(
            name=chapter_name,
            order_number=chapter_order_number,
        )
        Chapter.save(chapter)
        exist_chapter = Chapter.query.get(1)
        self.assertEqual(exist_chapter.name, chapter_name)
        self.assertEqual(exist_chapter.order_number, chapter_order_number)

        question_text: str = factory.paragraph()
        question_order_number: int = 1
        question_user_id: int = 1
        question_chapter_id: int = 1
        question = Question(
            order_number=question_order_number,
            user=question_user_id,
            chapter_id=question_chapter_id,
            text=question_text,
        )
        Question.save(question)
        exist_question = Question.query.get(1)
        self.assertEqual(exist_question.order_number, question_order_number)
        self.assertEqual(exist_question.user, question_user_id)
        self.assertEqual(exist_question.chapter_id, question_chapter_id)
        self.assertEqual(exist_question.text, question_text)
예제 #2
0
    def setUp(self):
        super().setUp()
        fixtures: list[dict] = load_fixture('minimum-questions.yml')
        test_cases_fixtures: dict = load_yaml_fixture('test_cases.yaml')

        self.questions: tuple = tuple(
            Question(**question_fixture).save()
            for question_fixture in fixtures['questions'])

        self.chapters: tuple = tuple(
            Chapter(**chapter_fixture)
            for chapter_fixture in fixtures['chapters'])

        self.sections: tuple = tuple(
            Section(**section_fixture)
            for section_fixture in fixtures['sections'])

        self.test_cases: tuple = tuple(
            TestCase(**test_case_fixture)
            for test_case_fixture in test_cases_fixtures['test_cases'])

        self.test_questions: tuple = tuple(
            TestQuestion(**test_question)
            for test_question in test_cases_fixtures['test_questions'])

        db.session.add_all(self.sections)
        db.session.add_all(self.chapters)
        db.session.add_all(self.questions)
        db.session.add_all(self.test_cases)
        db.session.add_all(self.test_questions)
예제 #3
0
def load_section_questions(fixture_name: str):
    """
    Load selected Section, related Chapters and Questions.

    Requires YML filename without '-questions.yml'
    Example:
    flask load-section-questions bars
    """
    fixtures: dict = load_fixture(f'{fixture_name}-questions.yml')
    db.session.add_all(
        Chapter(**chapter_fixture)
        for chapter_fixture in fixtures['chapters']
    )
    db.session.add_all(
        Question(**question_fixture)
        for question_fixture in fixtures['questions']
    )

    db.session.add_all(
        Section(**section_fixture)
        for section_fixture in fixtures['sections']
    )

    db.session.commit()

    print(f'{fixture_name}: chapters and questions successful load in database.')  # noqa TOO1
예제 #4
0
    def test(self):  # noqa: WPS210
        factory: Generator = Faker()

        chapter_name: str = factory.paragraph()
        chapter_order_number: int = 1

        chapter = Chapter(
            name=chapter_name,
            order_number=chapter_order_number,
        )
        Chapter.save(chapter)
        chapter = Chapter.query.get(1)

        question_text: str = factory.paragraph()
        question_order_number: int = 1
        question_user_id: int = 1
        question = Question(
            order_number=question_order_number,
            user=question_user_id,
            chapter_id=chapter.id,
            text=question_text,
        )
        Question.save(question)
        question = Question.query.get(1)

        answer_text: str = factory.paragraph()
        answer_is_approve: bool = True
        answer_question_id: int = 1

        answer = Answer(
            text=answer_text,
            is_approve=answer_is_approve,
            question_id=answer_question_id,
        )
        Answer.save(answer)
        answer = Answer.query.get(1)
        self.assertEqual(answer.text, answer_text)
        self.assertEqual(answer.is_approve, answer_is_approve)
        self.assertEqual(answer.question_id, answer_question_id)

        response = self.client.get(
            url_for('answers.answer', question_id=question.id), )
        self.assert_200(
            response,
            url_for('answers.answer', question_id=question.id),
        )
예제 #5
0
    def setUp(self):
        super().setUp()
        fixtures: list[dict] = load_fixture('chapters-questions.yml')

        self.questions: tuple = tuple(
            Question(**question_fixture).save()
            for question_fixture in fixtures['questions'])

        self.chapters: tuple = tuple(
            Chapter(**chapter_fixture)
            for chapter_fixture in fixtures['chapters'])

        db.session.add_all(self.questions)
        db.session.add_all(self.chapters)
예제 #6
0
def load_question_structure(self):
    fixtures: list[dict] = load_fixture('minimum-questions.yml')

    self.sections: tuple = tuple(
        Section(**section_fixture).save()
        for section_fixture in fixtures['sections'])

    self.chapters: tuple = tuple(
        Chapter(**chapter_fixture).save()
        for chapter_fixture in fixtures['chapters'])

    self.questions: tuple = tuple(
        Question(**question_fixture).save()
        for question_fixture in fixtures['questions'])

    db.session.add_all(self.questions)
    db.session.add_all(self.chapters)
    db.session.add_all(self.sections)
예제 #7
0
def load_chapters_questions():
    Section.query.delete()
    Question.query.delete()
    Chapter.query.delete()
    Answer.query.delete()
    fixtures: dict = load_fixture('chapters-questions.yml')
    db.session.add_all(
        Chapter(**chapter_fixture) for chapter_fixture in fixtures['chapters'])
    db.session.add_all(
        Question(**question_fixture)
        for question_fixture in fixtures['questions'])

    db.session.add_all(
        Section(**section_fixture) for section_fixture in fixtures['sections'])

    db.session.commit()

    print('Sections, chapters and questions successful load in database.'
          )  # noqa TOO1
예제 #8
0
파일: qa_test.py 프로젝트: honeydev/junior
    def test(self):  # noqa: WPS210
        factory: Generator = Faker()

        chapter_name: str = factory.paragraph()
        chapter_order_number: int = 1

        chapter = Chapter(
            name=chapter_name,
            order_number=chapter_order_number,
        )
        Chapter.save(chapter)
        chapter = Chapter.query.get(1)

        question_text: str = factory.paragraph()
        question_order_number: int = 1
        question_user_id: int = 1
        question = Question(
            order_number=question_order_number,
            user=question_user_id,
            chapter_id=chapter.id,
            text=question_text,
        )
        Question.save(question)
        question = Question.query.get(1)

        user_username: str = factory.md5()[:8]
        user_password: str = factory.password(8)
        user_email: str = factory.email()
        user_firstname: str = factory.first_name()
        user = User(
            login=user_username,
            email=user_email,
            password=user_password,
            firstname=user_firstname,
            is_aproved=True,
        )
        User.save(user)

        answer_text: str = factory.paragraph()
        answer_is_approve: bool = True
        answer_question_id: int = 1
        answer_owner_id: int = 1

        answer = Answer(
            text=answer_text,
            is_approve=answer_is_approve,
            question_id=answer_question_id,
            owner_id=answer_owner_id,
        )
        Answer.save(answer)
        answer = Answer.query.get(1)
        self.assertEqual(answer.text, answer_text)
        self.assertEqual(answer.is_approve, answer_is_approve)
        self.assertEqual(answer.question_id, answer_question_id)

        response = self.client.get(
            url_for('answers.answer', question_id=question.id), )
        self.assert_200(
            response,
            url_for('answers.answer', question_id=question.id),
        )