def test_find_or_create_user_existing_uuid(mocker): """ Return an existing user object with the referenced uuid. """ mock_session = mocker.MagicMock() mock_user = mocker.MagicMock() mock_user.username = '******' mock_session.query().filter_by().one_or_none.return_value = mock_user assert find_or_create_user('uuid', 'foobar', mock_session) == mock_user
def test_find_or_create_user_new(mocker): """ Create and return a user object for an unknown username. """ mock_session = mocker.MagicMock() mock_session.query().filter_by().one_or_none.return_value = None new_user = find_or_create_user('uuid', 'unknown', mock_session) assert new_user.username == 'unknown' mock_session.add.assert_called_once_with(new_user) mock_session.commit.assert_called_once_with()
def test_find_or_create_user_update_username(mocker, session): """ Return an existing user object with the updated username. """ user = factory.User(uuid="mock_uuid", username="******") session.add(user) actual_user = find_or_create_user("mock_uuid", "mock_username", session) assert actual_user == user assert actual_user.username == "mock_username"
def test_find_or_create_user_existing_username(mocker): """ Return an existing user object with the referenced username. """ mock_session = mocker.MagicMock() mock_user = mocker.MagicMock() mock_user.username = '******' mock_session.query().filter_by().one_or_none.return_value = mock_user assert find_or_create_user('uuid', 'testymctestface', mock_session) == mock_user assert mock_user.username == 'testymctestface' mock_session.add.assert_called_once_with(mock_user) mock_session.commit.assert_called_once_with()