コード例 #1
0
def test_get_meetings_of_instructor(meeting_api):
    user_name = fake.pystr()
    expected = [meeting for meeting, _ in zip(fake_meeting(), range(10))]
    meeting_api.meeting_persistence.get_meetings_of_instructor.return_value = expected
    assert meeting_api.get_meetings_of_instructor(user_name) == expected
    meeting_api.meeting_persistence.get_meetings_of_instructor.assert_called_once_with(
        user_name)
コード例 #2
0
 def test_meetings_of_officehour(self, schema, amount):
     meetings = [
         meeting for meeting, _ in zip(fake_meeting(), range(amount))
     ]
     context = MagicMock()
     context.api.meeting_api.get_meetings_of_officehour_for_date.return_value = (
         meetings)
     query = """
     query meetings($officeHourId: UUID!, $startTime: Int!, $endTime: Int!) {
         meetings(officeHourId: $officeHourId, startTime: $startTime, endTime: $endTime) {
             meetingId
         }
     }
     """
     variables = {
         "officeHourId": str(uuid4()),
         "startTime": fake.pyint(),
         "endTime": fake.pyint(),
     }
     result = schema.execute(query, context=context, variables=variables)
     assert not result.errors
     for expected_meeting, actual_meeting in zip(meetings,
                                                 result.data["meetings"]):
         assert str(
             expected_meeting.meeting_id) == actual_meeting["meetingId"]
     context.api.meeting_api.get_meetings_of_officehour_for_date.assert_called_once_with(
         UUID(variables["officeHourId"]),
         variables["startTime"],
         variables["endTime"],
     )
コード例 #3
0
def test_create_meeting(meeting_api, success):
    meeting = next(fake_meeting())
    error = Err(fake.pystr())

    def assert_called_correctly(_meeting):
        assert meeting.meeting_id != _meeting.meeting_id
        for attr in (
                "office_hour_id",
                "index",
                "instructor",
                "student",
                "notes",
                "comments",
                "start_time",
        ):
            assert getattr(meeting, attr) == getattr(_meeting, attr)
        return Ok(meeting) if success else error

    meeting_api.meeting_persistence.create_meeting.side_effect = assert_called_correctly
    result = meeting_api.create_meeting(
        meeting.instructor,
        meeting.student,
        meeting.office_hour_id,
        meeting.index,
        meeting.start_time,
    )
    if success:
        assert result.unwrap() == meeting
    else:
        assert result == error
    meeting_api.meeting_persistence.create_meeting.assert_called_once()
コード例 #4
0
def test_get_meetings_of_student(meeting_api):
    student_number = fake.pystr()
    expected = [meeting for meeting, _ in zip(fake_meeting(), range(10))]
    meeting_api.meeting_persistence.get_meetings_of_student.return_value = expected
    assert meeting_api.get_meetings_of_student(student_number) == expected
    meeting_api.meeting_persistence.get_meetings_of_student.assert_called_once_with(
        student_number)
コード例 #5
0
def test_check_meeting_user(meeting_api, user_type):
    meeting = next(fake_meeting())
    user = meeting.instructor if user_type == "instructor" else meeting.student
    meeting_api.meeting_persistence.get_meeting.return_value = Some(meeting)
    assert meeting_api._check_meeting_user(meeting.meeting_id, user, "").is_ok
    meeting_api.meeting_persistence.get_meeting.assert_called_once_with(
        meeting.meeting_id)
コード例 #6
0
def fake_officehour():
    return OfficeHour(
        uuid4(),
        fake_section(),
        fake.pyint(),
        choice(list(Weekday)),
        [meeting for meeting, _ in zip(fake_meeting(), range(6))],
    )
コード例 #7
0
def test_check_meeting_user_not_permitted(meeting_api, user):
    meeting = next(fake_meeting())
    meeting_api.meeting_persistence.get_meeting.return_value = Some(meeting)
    error = fake.pystr()
    assert (meeting_api._check_meeting_user(meeting.meeting_id, user,
                                            error).unwrap_err() == error)
    meeting_api.meeting_persistence.get_meeting.assert_called_once_with(
        meeting.meeting_id)
コード例 #8
0
def test_delete_meeting_fail_user_check(meeting_api, user):
    meeting = next(fake_meeting())
    error = Err(fake.pystr())
    meeting_api._check_meeting_user = MagicMock(return_value=error)
    assert meeting_api.delete_meeting(meeting.meeting_id, user) == error
    meeting_api.meeting_persistence.delete_meeting.assert_not_called()
    meeting_api._check_meeting_user.assert_called_once_with(
        meeting.meeting_id, user,
        "Cannot delete meeting that you are not a part of")
コード例 #9
0
def test_delete_note_wrong_author(meeting_api):
    note = next(fake_note())
    meeting = next(fake_meeting())
    author = fake_instructor()
    meeting_api.meeting_persistence.get_note.return_value = Some(note)
    meeting_api.meeting_persistence.get_meeting.return_value = Some(meeting)
    assert "not belong" in meeting_api.delete_note(note.note_id,
                                                   author).unwrap_err()
    meeting_api.meeting_persistence.get_note.assert_called_once_with(
        note.note_id)
    meeting_api.meeting_persistence.get_meeting.assert_called_once_with(
        note.meeting_id)
コード例 #10
0
ファイル: test_meeting_query.py プロジェクト: sakshaat/ohs
 def test_query_one(self, schema):
     meeting = next(fake_meeting())
     meeting.comments.append(next(fake_comment(fake_student())))
     meeting.comments.append(next(fake_comment(fake_instructor())))
     context = MagicMock()
     context.api.meeting_api.get_meeting.return_value = Some(meeting)
     result = schema.execute(
         self.query_one,
         context=context,
         variables={"meetingId": str(meeting.meeting_id)},
     )
     assert not result.errors
     context.api.meeting_api.get_meeting.assert_called_once_with(
         meeting.meeting_id)
     assert result.data["meeting"]["meetingId"] == str(meeting.meeting_id)
コード例 #11
0
def test_delete_meeting(meeting_api, success, user_type):
    meeting = next(fake_meeting())
    error = Err(fake.pystr())
    meeting_api.meeting_persistence.delete_meeting.return_value = (Ok(
        meeting.meeting_id) if success else error)
    meeting_api._check_meeting_user = MagicMock(return_value=Ok(None))
    user = meeting.instructor if user_type == "instructor" else meeting.student
    result = meeting_api.delete_meeting(meeting.meeting_id, user)
    if success:
        assert result.unwrap() == meeting.meeting_id
    else:
        assert result == error
    meeting_api._check_meeting_user.assert_called_once_with(
        meeting.meeting_id, user,
        "Cannot delete meeting that you are not a part of")
    meeting_api.meeting_persistence.delete_meeting.assert_called_once_with(
        meeting.meeting_id)
コード例 #12
0
def test_delete_note(meeting_api, success):
    note = next(fake_note())
    meeting = next(fake_meeting())
    error = Err(fake.pystr())
    meeting_api.meeting_persistence.get_note.return_value = Some(note)
    meeting_api.meeting_persistence.get_meeting.return_value = Some(meeting)
    meeting_api.meeting_persistence.delete_note.return_value = (Ok(
        note.note_id) if success else error)
    result = meeting_api.delete_note(note.note_id, meeting.instructor)
    if success:
        assert result.unwrap() == note.note_id
    else:
        assert result == error
    meeting_api.meeting_persistence.get_note.assert_called_once_with(
        note.note_id)
    meeting_api.meeting_persistence.get_meeting.assert_called_once_with(
        note.meeting_id)
コード例 #13
0
ファイル: test_meeting_query.py プロジェクト: sakshaat/ohs
 def test_query_upcoming(self, schema, user, amount):
     meetings = [
         meeting for meeting, _ in zip(fake_meeting(), range(amount))
     ]
     context = MagicMock()
     context.user = user
     if isinstance(user, Instructor):
         api_method = context.api.meeting_api.get_meetings_of_instructor
         user_id = user.user_name
     else:
         api_method = context.api.meeting_api.get_meetings_of_student
         user_id = user.student_number
     api_method.return_value = meetings
     result = schema.execute(self.query_upcoming, context=context)
     assert not result.errors
     for gql_result, meeting in zip(result.data["upcomingMeetings"],
                                    meetings):
         assert gql_result["meetingId"] == str(meeting.meeting_id)
     api_method.assert_called_once_with(user_id)
コード例 #14
0
def test_create_note(meeting_api, success):
    note = next(fake_note())
    error = Err(fake.pystr())
    meeting = next(fake_meeting())

    def assert_called_correctly(_note):
        assert abs(note.time_stamp - _note.time_stamp) < 10
        assert note.note_id != _note.note_id
        assert note.meeting_id == _note.meeting_id
        assert note.content_text == _note.content_text
        return Ok(note) if success else error

    meeting_api.meeting_persistence.create_note.side_effect = assert_called_correctly
    meeting_api._check_meeting_user = MagicMock(return_value=Ok(None))

    result = meeting_api.create_note(note.meeting_id, meeting.instructor,
                                     note.content_text)
    if success:
        assert result.unwrap() == note
    else:
        assert result == error
    meeting_api.meeting_persistence.create_note.assert_called_once()
    meeting_api._check_meeting_user.assert_called_once()
コード例 #15
0
        meeting.meeting_id)


@pytest.mark.parametrize("user", [fake_instructor(), fake_student()])
def test_delete_meeting_fail_user_check(meeting_api, user):
    meeting = next(fake_meeting())
    error = Err(fake.pystr())
    meeting_api._check_meeting_user = MagicMock(return_value=error)
    assert meeting_api.delete_meeting(meeting.meeting_id, user) == error
    meeting_api.meeting_persistence.delete_meeting.assert_not_called()
    meeting_api._check_meeting_user.assert_called_once_with(
        meeting.meeting_id, user,
        "Cannot delete meeting that you are not a part of")


@pytest.mark.parametrize("expected", [Some(next(fake_meeting())), NONE])
def test_get_meeting(meeting_api, expected):
    meeting_id = expected.unwrap().meeting_id if expected else uuid4()
    meeting_api.meeting_persistence.get_meeting.return_value = expected
    assert meeting_api.get_meeting(meeting_id) == expected
    meeting_api.meeting_persistence.get_meeting.assert_called_once_with(
        meeting_id)
    meeting_api.meeting_persistence.delete_meeting.assert_not_called()


def test_get_meetings_of_instructor(meeting_api):
    user_name = fake.pystr()
    expected = [meeting for meeting, _ in zip(fake_meeting(), range(10))]
    meeting_api.meeting_persistence.get_meetings_of_instructor.return_value = expected
    assert meeting_api.get_meetings_of_instructor(user_name) == expected
    meeting_api.meeting_persistence.get_meetings_of_instructor.assert_called_once_with(
コード例 #16
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,
    )