Exemple #1
0
    def test_setup(self):
        """Test `verdi setup`."""
        postgres = Postgres(interactive=False,
                            quiet=True,
                            dbinfo=self.pg_test.dsn)
        postgres.determine_setup()
        db_name = 'aiida_test_setup'
        db_user = '******'
        db_pass = '******'
        postgres.create_dbuser(db_user, db_pass)
        postgres.create_db(db_user, db_name)
        configuration.reset_profile()

        profile_name = 'testing'
        user_email = '*****@*****.**'
        user_first_name = 'John'
        user_last_name = 'Smith'
        user_institution = 'ECMA'

        # Keep the `--profile` option last as a regression test for #2897 and #2907. Some of the other options have
        # defaults, callbacks and or contextual defaults that might depend on it, but should not fail if they are parsed
        # before the profile option is parsed.
        options = [
            '--non-interactive', '--email', user_email, '--first-name',
            user_first_name, '--last-name', user_last_name, '--institution',
            user_institution, '--db-name', db_name, '--db-username', db_user,
            '--db-password', db_pass, '--db-port', self.pg_test.dsn['port'],
            '--db-backend', self.backend, '--profile', profile_name
        ]

        result = self.cli_runner.invoke(cmd_setup.setup, options)
        self.assertClickResultNoException(result)
        self.assertClickSuccess(result)

        config = configuration.get_config()
        self.assertIn(profile_name, config.profile_names)

        profile = config.get_profile(profile_name)
        profile.default_user = user_email

        # Verify that the backend type of the created profile matches that of the profile for the current test session
        self.assertEqual(self.backend, profile.database_backend)

        user = orm.User.objects.get(email=user_email)
        self.assertEqual(user.first_name, user_first_name)
        self.assertEqual(user.last_name, user_last_name)
        self.assertEqual(user.institution, user_institution)
Exemple #2
0
    def test_setup_fail_callback(self):
        """Make sure `determine_setup` works despite wrong initial values in case of correct callback"""

        def correct_setup(interactive, dbinfo):  # pylint: disable=unused-argument
            return self.pg_test.dsn

        postgres = Postgres(interactive=False, quiet=True, dbinfo={'port': '11111'}, determine_setup=False)
        postgres.set_setup_fail_callback(correct_setup)
        setup_success = postgres.determine_setup()
        self.assertTrue(setup_success)