def test_find_by_email(self, mock_query: Mock) -> None: expected = Invitation(id=123) filter_by = mock_query.return_value.filter_by first = filter_by.return_value.first first.return_value = expected result = Invitation.find_by_email('name-xyz', None) filter_by.assert_called_once_with(email='name-xyz') first.assert_called_once_with() assert result == expected
def test_find_by_email_with_id(self, mock_query: Mock) -> None: expected = Invitation(id=123) filter_by = mock_query.return_value.filter_by filter = filter_by.return_value.filter first = filter.return_value.first first.return_value = expected result = Invitation.find_by_email('name-xyz', 654) filter_by.assert_called_once_with(email='name-xyz') filter.assert_called_once_with(_BinaryExpressionMatcher(Invitation.id != 654)) first.assert_called_once_with() assert result == expected