Пример #1
0
def save_to_database(data):
    committee_preferred = data["committee_preferred"]
    choice = data["choice"]
    email = data["email"]
    name = data["name"]
    senate_division = data["senate_division"]
    department_name = data["department"]
    job_title = data["job_title"]
    is_interested = data["is_interested"]
    expertise = data["expertise"]

    logger.debug(f"Saving committee preferences for {name}")

    committee_id = None
    if committee_preferred:
        committee_record = CommitteeManager.add_committee(committee_preferred)
        committee_id = committee_record.committee_id

    department_record = DepartmentManager.add_department(department_name)
    department_id = department_record.department_id

    SenateDivisionManager.add_senate_division(senate_division)

    faculty_record = FacultyManager.add_faculty(name, email, job_title,
                                                senate_division)
    faculty_email = faculty_record.email

    SurveyChoiceManager.add_survey_choice(faculty_email, committee_id, choice)

    SurveyDataManager.add_survey_data(faculty_email, is_interested, expertise)

    DepartmentAssociationsManager.add_department_association(
        email, department_id)
Пример #2
0
    def test_faculty_manager_adds_data_to_database(self):
        expected = FacultyManager.add_faculty(
            "test-full-name",
            "test-email",
            "test-job-title",
            "test-senate-division",
        )
        actual = (dal.DBSession.query(Faculty).filter(
            Faculty.email == "test-email").first())

        assert actual.full_name == expected.full_name
        assert actual.email == expected.email
        assert actual.job_title == expected.job_title
        assert actual.senate_division_short_name == expected.senate_division_short_name
Пример #3
0
    def test_survey_data_manager_adds_data_to_database(self):
        faculty_record = FacultyManager.add_faculty(
            "test-full-name",
            "test-email",
            "test-job-title",
            "test-senate-division",
        )
        email = faculty_record.email

        expected = SurveyDataManager.add_survey_data(email, True)
        actual = (dal.DBSession.query(SurveyData).filter(
            SurveyData.email == email).first())

        assert actual.email == expected.email
        assert actual.is_interested == expected.is_interested
        assert actual.expertise is None
Пример #4
0
    def test_department_associations_manager_adds_data_to_database(self):
        department_record = DepartmentManager.add_department("test-department")
        department_id = department_record.department_id
        faculty_record = FacultyManager.add_faculty(
            "test-full-name",
            "test-email",
            "test-job-title",
            "test-senate-division",
        )
        faculty_email = faculty_record.email

        expected = DepartmentAssociationsManager.add_department_association(
            faculty_email, department_id)
        actual = (dal.DBSession.query(DepartmentAssociations).filter(
            DepartmentAssociations.email == faculty_email,
            DepartmentAssociations.department_id == department_id,
        ).first())

        assert actual.department_id == expected.department_id
        assert actual.email == expected.email
Пример #5
0
    def test_survey_choice_manager_adds_data_to_database_with_priority(self):
        faculty_record = FacultyManager.add_faculty(
            "test-full-name",
            "test-email",
            "test-job-title",
            "test-senate-division",
        )
        email = faculty_record.email
        committee_record = CommitteeManager.add_committee("test-committee")
        committee_id = committee_record.committee_id

        expected = SurveyChoiceManager.add_survey_choice(
            email, committee_id, 1)
        actual = (dal.DBSession.query(SurveyChoice).filter(
            SurveyChoice.email == email,
            SurveyChoice.committee_id == committee_id,
        ).first())

        assert actual.email == expected.email
        assert actual.committee_id == expected.committee_id
        assert actual.choice_id == 1