コード例 #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)
コード例 #2
0
def createMeeting(currentUser):
    print("created!!!")
    channel = ''
    for i in range(3):
        a = ''.join(
            random.choices(string.ascii_uppercase + string.ascii_lowercase,
                           k=3))
        channel += a
        if i != 2:
            channel += '-'
    uid = currentUser.id
    appId = os.environ.get("APPID")
    expiredTime = int(time.time()) + 24 * 60 * 60
    token = RtcTokenBuilder.buildTokenWithUid(
        appId, os.environ.get("APP_CERTIFICATE"), channel, uid, 1, expiredTime)
    # print(uid,appId,expiredTime,channel,token)
    meeting = MeetingModel(channel, uid)
    meeting.saveToDB()
    participant = ParticipantModel(token, meeting.id, uid)
    participant.saveToDB()
    print({
        "meetingDetails": {
            "channel": channel,
            "token": token,
            "mid": meeting.id
        }
    })
    return jsonify({
        "meetingDetails": {
            "channel": channel,
            "token": token,
            "mid": meeting.id,
            "uid": uid
        }
    }), 201
コード例 #3
0
    def test_find_by_id(self):
        with self.app_context:
            meeting, _, _ = self.add_meeting_to_db(self.meeting_1,
                                                   self.member_1, self.role_1)

            meeting = MeetingModel.find_by_id(meeting.id)

            self.assertEqual(meeting.description, self.DESCRIPTION)
コード例 #4
0
    def test_find_by_creator_id(self):
        with self.app_context:
            meeting, creator, _ = self.add_meeting_to_db(
                self.meeting_1, self.member_1, self.role_1)

            meetings = MeetingModel.find_by_creator_id(creator.id)

            self.assertEqual(meetings[0].id, meeting.id)
コード例 #5
0
    def test_find_all(self):
        with self.app_context:
            meeting, _, _ = self.add_meeting_to_db(self.meeting_1,
                                                   self.member_1, self.role_1)

            meetings = MeetingModel.find_all()

            self.assertEqual(meetings[0].id, meeting.id)
コード例 #6
0
    def test_meetings_members_relation(self):
        with self.app_context:
            meeting, member, _ = self.add_meeting_to_db(
                self.meeting_1, self.member_1, self.role_1)

            meeting = MeetingModel.find_by_id(meeting.id)
            member = MemberModel.find_by_id(member.id)
            meeting.members.append(member)

            self.assertEqual(meeting.members[0].email, member.email)
コード例 #7
0
def get_meetings() -> ApiResponse:
    meeting_list = MeetingModel.find_all()

    if not meeting_list:
        abort(404, description=ERROR_404_LIST.format("meetings"))

    return (
        jsonify({"meetings": meeting_list_schema.dump(meeting_list)}),
        200,
    )
コード例 #8
0
def get_meeting(meeting_id: int) -> ApiResponse:
    meeting = MeetingModel.find_by_id(meeting_id)

    if not meeting:
        abort(404, description=ERROR_404.format("Meeting", "id", meeting_id))

    return (
        jsonify({
            "meeting": meeting_schema.dump(meeting),
        }),
        200,
    )
コード例 #9
0
    def put(self, session):
        name = request.json["name"]
        description = request.json["description"]
        room_uuid = request.json["room"]
        date = request.json["date"]
        start = request.json["start"]
        stop = request.json["stop"]

        room: RoomModel = RoomModel.query.filter_by(uuid=room_uuid).first()

        meeting: MeetingModel = MeetingModel.create(name, description, room.uuid, date, start, stop)

        return meeting.serialize
コード例 #10
0
def startRecording(user):
    try:
        print("this is the error f*****g hell")
        body = request.get_json()
        print(body["channel"])
        meeting = MeetingModel.fetchByChannel(body["channel"])
        if not meeting:
            return {"message": "invalid channel name"}
        result = startRecordingAgora(body["channel"], meeting.id,
                                     body["token"])
        return result, 200
    except Exception as e:
        print(str(e))
コード例 #11
0
def delete_meeting(meeting_id: int) -> ApiResponse:
    meeting = MeetingModel.find_by_id(meeting_id)

    if not meeting:
        abort(404, description=ERROR_404.format("Meeting", "id", meeting_id))

    meeting.delete_from_db()

    return (
        jsonify({
            "message": DELETED.format("Meeting"),
            "meeting": meeting_schema.dump(meeting),
        }),
        200,
    )
コード例 #12
0
def put_meeting(meeting_id: int) -> ApiResponse:
    meeting = MeetingModel.find_by_id(meeting_id)

    if not meeting:
        abort(404, description=ERROR_404.format("Meeting", "id", meeting_id))

    meeting_json = request.get_json()

    meeting.datetime = meeting_json.get("datetime")
    meeting.type = meeting_json.get("type")
    meeting.location = meeting_json.get("location")
    meeting.description = meeting_json.get("description")
    meeting.creator_id = meeting_json.get("creator_id")
    meeting.save_to_db()

    return (
        jsonify({
            "message": MODIFIED.format("Meeting"),
            "meeting": meeting_schema.dump(meeting),
        }),
        200,
    )
コード例 #13
0
def joinMeeting(currentUser):
    body = request.get_json()
    meeting = MeetingModel.fetchByChannel(body["channel"])
    if not meeting:
        return jsonify({"message": "Channel name doesn't exist"}), 400
    uid = currentUser.id
    appId = os.environ.get("APPID")
    expiredTime = int(time.time()) + 24 * 60 * 60
    token = RtcTokenBuilder.buildTokenWithUid(
        appId, os.environ.get("APP_CERTIFICATE"), meeting.channel, uid, 1,
        expiredTime)
    # Code for adding participants in the meeting!
    participant = ParticipantModel(token, meeting.id, uid)
    participant.saveToDB()
    return jsonify({
        "meetingDetails": {
            "channel": meeting.channel,
            "token": token,
            "mid": meeting.id,
            "uid": uid
        }
    }), 200
コード例 #14
0
 def add_meeting_to_db(
     self, meeting: MeetingModel, member: MemberModel, role: RoleModel
 ) -> Tuple[MeetingModel, MemberModel, RoleModel]:
     member, role = self.add_member_to_db(member, role)
     meeting = meeting.save_to_db()
     return meeting, member, role