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_no_meeting(meeting_api):
    note = next(fake_note())
    author = fake_instructor()
    meeting_api.meeting_persistence.get_note.return_value = Some(note)
    meeting_api.meeting_persistence.get_meeting.return_value = NONE
    assert (f"Meeting with ID: '{note.meeting_id}'"
            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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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()