Esempio n. 1
0
def test_register_existing_user():
    original_path = os.path.exists
    os.path.exists = mock.Mock(original_path)
    os.path.exists.return_value = True
    with pytest.raises(application_control.userNameError):
        application_control.register("username", "password")
    os.path.exists = original_path
Esempio n. 2
0
def test_register():
    original_user = user_control.User
    user_control.User = mock.Mock()
    mocked_user_ob = mock.Mock()
    user_control.User.return_value = mocked_user_ob
    original_add_user = user_control.add_user
    user_control.add_user = mock.Mock()

    original_path = os.path.exists
    os.path.exists = mock.Mock(original_path)
    os.path.exists.return_value = False

    ob = application_control.register("username", "password")
    user_control.User.assert_called_with("username")

    user_control.add_user.assert_called_with("username", "password")
    assert ob == mocked_user_ob

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