Пример #1
0
 def test__init__db__ok_nominal_case(self):
     """
     Test database initialisation
     """
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     # delete config to be sure command will work
     app.run([
         "db",
         "delete",
         "--force",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "--debug",
     ])
     result = app.run([
         "db", "init", "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH), "--debug"
     ])
     assert result == 0
Пример #2
0
 def test_func__user_update_command__err_password_modification_failed__external_auth(
         self, hapic, session, user_api_factory) -> None:
     """
     Test user password update
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     user.auth_type = AuthType.LDAP
     assert user.auth_type == AuthType.LDAP
     session.add(user)
     session.flush()
     transaction.commit()
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     with pytest.raises(ExternalAuthUserPasswordModificationDisallowed):
         app.run([
             "user",
             "update",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "-p",
             "new_ldap_password",
             "--debug",
         ])
Пример #3
0
 def test__init__db__ok_nominal_case(self, hapic, session,
                                     user_api_factory):
     """
     Test database initialisation
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     # delete config to be sure command will work
     app.run([
         "db",
         "delete",
         "--force",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "--debug",
     ])
     result = app.run([
         "db", "init", "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH), "--debug"
     ])
     assert result == 0
Пример #4
0
 def test_func__user_update_command__err_password_modification_failed__external_auth(
         self) -> None:
     """
     Test user password update
     """
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     user.auth_type = AuthType.LDAP
     assert user.auth_type == AuthType.LDAP
     self.session.add(user)
     self.session.flush()
     transaction.commit()
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(ExternalAuthUserPasswordModificationDisallowed):
         app.run([
             "user",
             "update",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "-p",
             "new_ldap_password",
             "--debug",
         ])
Пример #5
0
 def test__delete__db__err_no_force_param(self, hapic, session,
                                          user_api_factory):
     """
     Test database deletion
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     with pytest.raises(ForceArgumentNeeded):
         app.run([
             "db", "delete", "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH), "--debug"
         ])
     result = app.run([
         "db", "delete", "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH)
     ])
     assert result == 1
Пример #6
0
 def test__init__db__ok_nominal_case(self):
     """
     Test database initialisation
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     # delete config to be sure command will work
     app.run([
         'db',
         'delete',
         '--force',
         '-c',
         'tests_configs.ini#command_test',
         '--debug',
     ])
     result = app.run([
         'db',
         'init',
         '-c',
         'tests_configs.ini#command_test',
         '--debug',
     ])
     assert result == 0
Пример #7
0
 def test__delete__db__err_no_config_file(self):
     """
     Test database deletion
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(FileNotFoundError):
         app.run([
             'db',
             'delete',
             '-c',
             'donotexit.ini#command_test',
             '--debug',
         ])
     result = app.run([
         'db',
         'delete',
         '-c',
         'donotexist.ini#command_test',
     ])
     assert result == 1
Пример #8
0
 def test__delete__db__err_no_sqlalchemy_url(self):
     """
     Test database deletion
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(InvalidSettingFile):
         app.run([
             'db',
             'delete',
             '-c',
             'tests_configs.ini#command_test_no_sqlalchemy_url',
             '--debug',
         ])
     result = app.run([
         'db',
         'delete',
         '-c',
         'tests_configs.ini#command_test_no_sqlalchemy_url',
     ])
     assert result == 1
Пример #9
0
 def test__init__db__ok_db_already_exist(self):
     """
     Test database initialisation
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(DatabaseInitializationFailed):
         app.run(["db", "init", "-c", "tests_configs.ini#command_test", "--debug"])
Пример #10
0
 def test_func__user_create_command__err__password_required(self) -> None:
     """
     Test User creation without filling password
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(BadCommandError):
         app.run([
             '--debug',
             'user', 'create',
             '-c', 'tests_configs.ini#command_test',
             '-l', '*****@*****.**',
             '--debug',
         ])
Пример #11
0
 def test_func__user_create_command__err__in_unknown_group(self) -> None:
     """
     Test User creation with an unknown group
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(GroupDoesNotExist):
         app.run([
             'user', 'create',
             '-c', 'tests_configs.ini#command_test',
             '-l', 'command_test@user',
             '-p', 'new_password',
             '-g', 'unknown',
             '--debug',
         ])
Пример #12
0
 def test_func__user_create_command__err_user_already_exist(self) -> None:
     """
     Test User creation with existing user login
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(UserAlreadyExistError):
         app.run([
             '--debug',
             'user', 'create',
             '-c', 'tests_configs.ini#command_test',
             '-l', '*****@*****.**',
             '-p', 'new_password',
             '--debug',
         ])
Пример #13
0
 def test__delete__db__err_no_config_file(self):
     """
     Test database deletion
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(FileNotFoundError):
         app.run(["db", "delete", "-c", "donotexit.ini#command_test", "--debug"])
     result = app.run(["db", "delete", "-c", "donotexist.ini#command_test"])
     assert result == 1
Пример #14
0
 def test_func__user_create_command__ok__in_admin_group(self) -> None:
     """
     Test User creation with admin as group
     """
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email("command_test@user")
     self.disconnect_database()
     app = TracimCLI()
     result = app.run([
         "user",
         "create",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-l",
         "command_test@user",
         "-p",
         "new_password",
         "-g",
         "administrators",
         "--debug",
     ])
     assert result == 0
     self.connect_database()
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     new_user = api.get_one_by_email("command_test@user")
     assert new_user.email == "command_test@user"
     assert new_user.validate_password("new_password")
     assert new_user.profile.name == "administrators"
Пример #15
0
 def test_func__user_update_command__ok__nominal_case(self) -> None:
     """
     Test user password update
     """
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     result = app.run([
         "user",
         "update",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-l",
         "*****@*****.**",
         "-p",
         "new_password",
         "--debug",
     ])
     assert result == 0
     self.connect_database()
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     new_user = api.get_one_by_email("*****@*****.**")
     assert new_user.email == "*****@*****.**"
     assert new_user.validate_password("new_password")
     assert not new_user.validate_password("*****@*****.**")
Пример #16
0
 def test_func__user_update_command__err_password_modification_failed__external_auth(self) -> None:
     """
     Test user password update
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     user.auth_type = AuthType.LDAP
     assert user.auth_type == AuthType.LDAP
     self.session.add(user)
     self.session.flush()
     transaction.commit()
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(ExternalAuthUserPasswordModificationDisallowed):
         result = app.run([
             'user', 'update',
             '-c', 'tests_configs.ini#command_test',
             '-l', '*****@*****.**',
             '-p', 'new_ldap_password',
             '--debug',
         ])
Пример #17
0
 def test_func__user_update_command__ok__nominal_case(
         self, hapic, session, user_api_factory) -> None:
     """
     Test user password update
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     result = app.run([
         "user",
         "update",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-l",
         "*****@*****.**",
         "-p",
         "new_password",
         "--debug",
     ])
     assert result == 0
     api = user_api_factory.get()
     new_user = api.get_one_by_email("*****@*****.**")
     assert new_user.email == "*****@*****.**"
     assert new_user.validate_password("new_password")
     assert not new_user.validate_password("*****@*****.**")
Пример #18
0
 def test_func__user_create_command__ok__nominal_case(self) -> None:
     """
     Test User creation
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email("command_test@user")
     self.disconnect_database()
     app = TracimCLI()
     result = app.run(
         [
             "user",
             "create",
             "-c",
             "tests_configs.ini#command_test",
             "-l",
             "command_test@user",
             "-p",
             "new_password",
             "--debug",
         ]
     )
     assert result == 0
     self.connect_database()
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     new_user = api.get_one_by_email("command_test@user")
     assert new_user.email == "command_test@user"
     assert new_user.validate_password("new_password")
     assert new_user.profile.name == "users"
Пример #19
0
 def test_func__user_create_command__err__with_email_notification_disabled(self) -> None:  # nopep8
     """
     Test User creation with email with notification disable
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(NotificationDisabledCantCreateUserWithInvitation):
         app.run([
             '--debug',
             'user', 'create',
             '-c', 'tests_configs.ini#command_test',
             '-l', '*****@*****.**',
             '-p', 'new_password',
             '--send-email',
             '--debug',
         ])
Пример #20
0
 def test_func__user_update_command__ok__nominal_case(self) -> None:
     """
     Test user password update
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     result = app.run([
         'user', 'update',
         '-c', 'tests_configs.ini#command_test',
         '-l', '*****@*****.**',
         '-p', 'new_password',
         '--debug',
     ])
     assert result == 0
     self.connect_database()
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     new_user = api.get_one_by_email('*****@*****.**')
     assert new_user.email == '*****@*****.**'
     assert new_user.validate_password('new_password')
     assert not new_user.validate_password('*****@*****.**')
Пример #21
0
 def test_func__user_update_command__ok__remove_group(self) -> None:
     """
     Test user password update
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     assert user.profile.name == "administrators"
     self.disconnect_database()
     app = TracimCLI()
     result = app.run(
         [
             "user",
             "update",
             "-c",
             "tests_configs.ini#command_test",
             "-l",
             "*****@*****.**",
             "-p",
             "new_password",
             "-rmg",
             "administrators",
             "--debug",
         ]
     )
     assert result == 0
     self.connect_database()
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     new_user = api.get_one_by_email("*****@*****.**")
     assert new_user.email == "*****@*****.**"
     assert new_user.validate_password("new_password")
     assert not new_user.validate_password("*****@*****.**")
     assert new_user.profile.name == "trusted-users"
Пример #22
0
 def test_func__user_create_command__ok__nominal_case(
         self, session, user_api_factory) -> None:
     """
     Test User creation
     """
     api = user_api_factory.get()
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email("command_test@user")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI needs the context to be reset when ran.
     DepotManager._clear()
     app = TracimCLI()
     result = app.run([
         "user",
         "create",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-e",
         "command_test@user",
         "-p",
         "new_password",
         "--debug",
     ])
     assert result == 0
     api = user_api_factory.get()
     new_user = api.get_one_by_email("command_test@user")
     assert new_user.email == "command_test@user"
     assert new_user.validate_password("new_password")
     assert new_user.profile.slug == "users"
Пример #23
0
 def test_func__user_create_command__ok__nominal_case(self) -> None:
     """
     Test User creation
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email('command_test@user')
     self.disconnect_database()
     app = TracimCLI()
     result = app.run([
         'user',
         'create',
         '-c',
         'tests_configs.ini#command_test',
         '-l',
         'command_test@user',
         '-p',
         'new_password',
         '--debug',
     ])
     assert result == 0
     self.connect_database()
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     new_user = api.get_one_by_email('command_test@user')
     assert new_user.email == 'command_test@user'
     assert new_user.validate_password('new_password')
     assert new_user.profile.name == 'users'
Пример #24
0
 def test_func__user_create_command__err__password_required(self) -> None:
     """
     Test User creation without filling password
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(BadCommandError):
         app.run([
             "--debug",
             "user",
             "create",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "--debug",
         ])
Пример #25
0
 def test_func__user_create_command__err_user_already_exist(self) -> None:
     """
     Test User creation with existing user login
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(UserAlreadyExistError):
         app.run([
             "--debug",
             "user",
             "create",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "-p",
             "new_password",
             "--debug",
         ])
Пример #26
0
 def test_func__user_create_command__err__in_unknown_group(self) -> None:
     """
     Test User creation with an unknown group
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(GroupDoesNotExist):
         app.run([
             "user",
             "create",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "command_test@user",
             "-p",
             "new_password",
             "-g",
             "unknown",
             "--debug",
         ])
Пример #27
0
 def test__init__db__ok_db_already_exist(self, hapic, session,
                                         user_api_factory):
     """
     Test database initialisation
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     with pytest.raises(DatabaseInitializationFailed):
         app.run([
             "db", "init", "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH), "--debug"
         ])
Пример #28
0
 def test__delete__db__err_no_config_file(self, hapic, session,
                                          user_api_factory):
     """
     Test database deletion
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     with pytest.raises(FileNotFoundError):
         app.run([
             "db", "delete", "-c", "donotexit.ini#command_test", "--debug"
         ])
     result = app.run(["db", "delete", "-c", "donotexist.ini#command_test"])
     assert result == 1
Пример #29
0
 def test__init__db__ok_db_already_exist(self):
     """
     Test database initialisation
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(DatabaseInitializationFailed):
         app.run([
             'db', 'init',
             '-c', 'tests_configs.ini#command_test',
             '--debug',
         ])
Пример #30
0
 def test_func__user_create_command__err__password_required(
         self, hapic, session) -> None:
     """
     Test User creation without filling password
     """
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     with pytest.raises(BadCommandError):
         app.run([
             "--debug",
             "user",
             "create",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "--debug",
         ])