예제 #1
0
def test_login_wronguser():
    original_path = os.path.exists
    os.path.exists = mock.Mock(original_path)
    os.path.exists.return_value = False

    with pytest.raises(application_control.LoginError):
        user = application_control.login("username", "password")

    os.path.exists = original_path
예제 #2
0
def test_login_wrongpass():
    original_path = os.path.exists
    os.path.exists = mock.Mock(original_path)
    os.path.exists.return_value = True
    original_user = user_control.User
    user_control.User, mock_user = mock.Mock(original_user), mock.Mock(original_user)

    user_control.User.return_value = mock_user
    mock_user.password = "******"

    with pytest.raises(application_control.LoginError):
        user = application_control.login("username", "password")

    user_control.User = original_user
    os.path.exists = original_path
예제 #3
0
def test_login():
    original_user = user_control.User
    user_control.User, mock_user = mock.Mock(original_user), mock.Mock(original_user)
    original_path = os.path.exists
    os.path.exists = mock.Mock(original_path)
    os.path.exists.return_value = True
    user_control.User.return_value = mock_user
    mock_user.password = "******"

    user = application_control.login("username", "password")

    user_control.User.assert_called_with("username")
    assert user == mock_user

    user_control.User = original_user
    os.path.exists = original_path