Ejemplo n.º 1
0
    def setUp(self) -> None:
        """Create all db tables before each test"""
        self.client = app.test_client()
        self.app_context = app.app_context()

        with self.app_context:
            db.create_all()

            self.keynote_1 = KeynoteModel(**TEST_KEYNOTE_1)
            self.keynote_2 = KeynoteModel(**TEST_KEYNOTE_2)
            self.member_1 = MemberModel(**TEST_MEMBER_1)
            self.member_2 = MemberModel(**TEST_MEMBER_2)
            self.meeting_1 = MeetingModel(**TEST_MEETING_1)
            self.meeting_2 = MeetingModel(**TEST_MEETING_2)
            self.permission_1 = PermissionModel(**TEST_PERMISSION_1)
            self.permission_2 = PermissionModel(**TEST_PERMISSION_2)
            self.permission_3 = PermissionModel(**TEST_PERMISSION_3)
            self.permission_4 = PermissionModel(**TEST_PERMISSION_4)
            self.permission_5 = PermissionModel(**TEST_PERMISSION_5)
            self.permission_6 = PermissionModel(**TEST_PERMISSION_6)
            self.permission_7 = PermissionModel(**TEST_PERMISSION_7)
            self.permission_8 = PermissionModel(**TEST_PERMISSION_8)
            self.project_1 = ProjectModel(**TEST_PROJECT_1)
            self.project_2 = ProjectModel(**TEST_PROJECT_2)
            self.role_1 = RoleModel(**TEST_ROLE_1)
            self.role_2 = RoleModel(**TEST_ROLE_2)
            self.role_3 = RoleModel(**TEST_ROLE_3)
            self.role_4 = RoleModel(**TEST_ROLE_4)
            self.role_5 = RoleModel(**TEST_ROLE_5)
            self.speaker_1 = SpeakerModel(**TEST_SPEAKER_1)
            self.speaker_2 = SpeakerModel(**TEST_SPEAKER_2)
Ejemplo n.º 2
0
def put_speaker(speaker_id: int) -> ApiResponse:
    speaker = SpeakerModel.find_by_id(speaker_id)

    if not speaker:
        abort(
            404,
            description=ERROR_404.format("Speaker", "id", speaker_id),
        )

    speaker_json = request.get_json()
    speaker.first_name = speaker_json.get("first_name")
    speaker.last_name = speaker_json.get("last_name")
    speaker.email = speaker_json.get("email")
    speaker.linkedin_profile = speaker_json.get("linkedin_profile")
    speaker.github_profile = speaker_json.get("github_profile")
    speaker.twitter_profile = speaker_json.get("twitter_profile")
    speaker.bio = speaker_json.get("bio")
    speaker.profile_picture = speaker_json.get("profile_picture")
    speaker.save_to_db()

    return (
        jsonify({
            "message": MODIFIED.format("Speaker"),
            "speaker": speaker_schema.dump(speaker),
        }),
        200,
    )
Ejemplo n.º 3
0
    def test_find_by_id(self):
        with self.app_context:
            speaker = self.add_speaker_to_db(self.speaker_1)

            speaker = SpeakerModel.find_by_id(speaker.id)

            self.assertEqual(speaker.first_name, self.FIRST_NAME)
Ejemplo n.º 4
0
    def test_find_by_email(self):
        with self.app_context:
            speaker = self.add_speaker_to_db(self.speaker_1)

            speaker = SpeakerModel.find_by_email(speaker.email)

            self.assertEqual(speaker.email, self.EMAIL)
Ejemplo n.º 5
0
    def test_find_all(self):
        with self.app_context:
            speaker = self.add_speaker_to_db(self.speaker_1)

            speakers = SpeakerModel.find_all()

            self.assertEqual(speakers[0].id, speaker.id)
Ejemplo n.º 6
0
def get_speakers() -> ApiResponse:
    speaker_list = SpeakerModel.find_all()

    if not speaker_list:
        abort(404, description=ERROR_404_LIST.format("speakers"))

    return (
        jsonify({"speakers": speaker_list_schema.dump(speaker_list)}),
        200,
    )
Ejemplo n.º 7
0
def get_speaker(speaker_id: int) -> ApiResponse:
    speaker = SpeakerModel.find_by_id(speaker_id)

    if not speaker:
        abort(
            404,
            description=ERROR_404.format("Speaker", "id", speaker_id),
        )

    return (
        jsonify({
            "speaker": speaker_schema.dump(speaker),
        }),
        200,
    )
Ejemplo n.º 8
0
def delete_speaker(speaker_id: int) -> ApiResponse:
    speaker = SpeakerModel.find_by_id(speaker_id)

    if not speaker:
        abort(
            404,
            description=ERROR_404.format("Speaker", "id", speaker_id),
        )

    speaker.delete_from_db()

    return (
        jsonify({
            "message": DELETED.format("Speaker"),
            "speaker": speaker_schema.dump(speaker),
        }),
        200,
    )
Ejemplo n.º 9
0
 def add_speaker_to_db(self, speaker: SpeakerModel) -> SpeakerModel:
     return speaker.save_to_db()