Exemplo n.º 1
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)
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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