Exemplo n.º 1
0
def test_create_note(schema, success):
    note = next(fake_note())
    error = Err(fake.pystr())
    context = MagicMock()
    context.api.meeting_api.create_note.return_value = Ok(
        note) if success else error
    query = """
    mutation createNote($meetingId: UUID!, $contentText: String!) {
        createNote(meetingId: $meetingId, contentText: $contentText) {
            noteId
            meetingId
            timeStamp
            contentText
        }
    }
    """
    variables = {
        "meetingId": str(note.meeting_id),
        "contentText": note.content_text
    }
    result = schema.execute(query, context=context, variables=variables)
    if success:
        assert not result.errors
        for attr, val in result.data["createNote"].items():
            expected = getattr(note, to_snake_case(attr))
            if isinstance(expected, UUID):
                expected = str(expected)
            assert expected == val
    else:
        assert error.unwrap_err() in str(result.errors)
    context.api.meeting_api.create_note.assert_called_once_with(
        note.meeting_id, context.user, note.content_text)
Exemplo n.º 2
0
def test_delete_note(schema, success):
    context = MagicMock()
    note_id = uuid4()
    error = Err(fake.pystr())
    context.user = fake_instructor()
    context.api.meeting_api.delete_note.return_value = Ok(
        note_id) if success else error
    query = """
    mutation deleteNote($noteId: UUID!) {
        deleteNote(noteId: $noteId) {
            noteId
        }
    }
    """

    result = schema.execute(query,
                            context=context,
                            variables={"noteId": str(note_id)})
    if success:
        assert not result.errors
        assert result.data["deleteNote"] == {"noteId": str(note_id)}
    else:
        assert error.unwrap_err() in str(result.errors)
    context.api.meeting_api.delete_note.assert_called_once_with(
        note_id, context.user)
Exemplo n.º 3
0
def test_create_comment(schema, author, success):
    context = MagicMock()
    comment = next(fake_comment())
    error = Err(fake.pystr())
    query = """
    mutation createComment($meetingId: UUID!, $contentText: String!) {
        createComment(meetingId: $meetingId, contentText: $contentText) {
            commentId
            meetingId
            author {
                ... on Instructor {
                    userName
                }
                ... on Student {
                    studentNumber
                }
            }
            timeStamp
            contentText
        }
    }
    """
    context.api.meeting_api.create_comment.return_value = (Ok(comment) if
                                                           success else error)
    variables = {
        "meetingId": str(comment.meeting_id),
        "contentText": comment.content_text,
    }
    result = schema.execute(query, context=context, variables=variables)
    if success:
        assert not result.errors
        for key, val in result.data["createComment"].items():
            if key == "author":
                if isinstance(comment.author, Instructor):
                    assert val["userName"] == comment.author.user_name
                else:
                    assert val[
                        "studentNumber"] == comment.author.student_number
            else:
                expected = getattr(comment, to_snake_case(key))
                if isinstance(expected, UUID):
                    expected = str(expected)
                assert expected == val
    else:
        assert result.errors
        assert error.unwrap_err() in str(result.errors)
    context.api.meeting_api.create_comment.assert_called_once_with(
        comment.meeting_id, context.user, comment.content_text)
Exemplo n.º 4
0
def test_delete_office_hour(schema, success):
    context = MagicMock()
    office_hour_id = uuid4()
    error = Err(fake.pystr())
    context.api.course_api.delete_officehour.return_value = (
        Ok(office_hour_id) if success else error)
    query = """
    mutation deleteOfficeHour($id: UUID!) {
        deleteOfficeHour(officeHourId: $id) {
            officeHourId
        }
    }
    """
    result = schema.execute(query,
                            context=context,
                            variables={"id": str(office_hour_id)})
    if success:
        assert not result.errors
        assert result.data["deleteOfficeHour"]["officeHourId"] == str(
            office_hour_id)
    else:
        assert error.unwrap_err() in str(result.errors)
    context.api.course_api.delete_officehour.assert_called_once_with(
        office_hour_id)
Exemplo n.º 5
0
def test_create_officehour(schema, success):
    context = MagicMock()
    officehour = fake_officehour()
    error = Err(fake.pystr())
    context.api.course_api.get_section.return_value = Some(officehour.section)
    context.api.course_api.create_officehour.return_value = (
        Ok(officehour) if success else error)
    query = """
    mutation createOfficeHour(
        $sectionInput: SectionInput!, $startingHour: Int!, $weekday: Weekday!
    ) {
        createOfficeHour(
            sectionInput: $sectionInput, startingHour: $startingHour, weekday: $weekday
        ) {
            officeHourId
            section {
                sectionCode
            }
            startingHour
            weekday
            meetings {
                meeting {
                    meetingId
                }
            }
        }
    }
    """
    variables = {
        "sectionInput": {
            "course": {
                "courseCode": officehour.section.course.course_code
            },
            "year": officehour.section.year,
            "semester": officehour.section.semester.name,
            "sectionCode": officehour.section.section_code,
            "taughtBy": officehour.section.taught_by.user_name,
            "numStudents": officehour.section.num_students,
        },
        "startingHour": officehour.starting_hour,
        "weekday": officehour.weekday.name,
    }
    result = schema.execute(query, context=context, variables=variables)
    if success:
        assert not result.errors
        create_officehour = result.data["createOfficeHour"]
        assert create_officehour["officeHourId"] == str(
            officehour.office_hour_id)
        assert (create_officehour["section"]["sectionCode"] ==
                officehour.section.section_code)
        assert create_officehour["weekday"] == officehour.weekday.name
        assert create_officehour["startingHour"] == officehour.starting_hour
        for slot, meeting in zip(create_officehour["meetings"],
                                 officehour.meetings):
            if not slot["meeting"]:
                assert not meeting
            else:
                assert slot["meeting"]["meetingId"] == str(meeting.meeting_id)
    else:
        assert error.unwrap_err() in str(result.errors)
    context.api.course_api.create_officehour.assert_called_once_with(
        officehour.section, officehour.starting_hour, officehour.weekday)
Exemplo n.º 6
0
def test_create_meeting(schema, success):
    context = MagicMock()
    meeting = next(fake_meeting())
    error = Err(fake.pystr())
    context.api.instructor_api.get_instructor.return_value = Ok(
        meeting.instructor)
    context.api.meeting_api.create_meeting.return_value = (Ok(meeting) if
                                                           success else error)
    context.user = meeting.student
    query = """
    mutation createMeeting($instructor: String!, $officeHourId: UUID!, $index: Int!, $startTime:
    Int!) {
        createMeeting(instructor: $instructor, officeHourId: $officeHourId, index: $index,
        startTime: $startTime) {
            instructor {
                userName
            }
            student {
                studentNumber
            }
            officeHourId
            index
            startTime
            notes {
                noteId
            }
            comments {
                commentId
            }
        }
    }
    """
    result = schema.execute(
        query,
        context=context,
        variables={
            "instructor": meeting.instructor.user_name,
            "officeHourId": str(meeting.office_hour_id),
            "index": meeting.index,
            "startTime": meeting.start_time,
        },
    )
    if success:
        assert not result.errors
        create_meeting = result.data["createMeeting"]
        for attr in ("index", "startTime"):
            assert getattr(meeting,
                           to_snake_case(attr)) == create_meeting[attr]
        assert str(meeting.office_hour_id) == create_meeting["officeHourId"]
        assert create_meeting["notes"] == []
        assert create_meeting["comments"] == []
        assert create_meeting["instructor"][
            "userName"] == meeting.instructor.user_name
        assert (create_meeting["student"]["studentNumber"] ==
                meeting.student.student_number)
    else:
        assert error.unwrap_err() in str(result.errors)
    context.api.instructor_api.get_instructor.assert_called_once_with(
        meeting.instructor.user_name)
    context.api.meeting_api.create_meeting.assert_called_once_with(
        meeting.instructor,
        context.user,
        meeting.office_hour_id,
        meeting.index,
        meeting.start_time,
    )