'This is a unittest for the bug reported by a user where his settings
are not saved to the profile.
https://github.com/andresriancho/w3af/issues/291
Actually, the settings are saved but not properly displayed, but that\'s
not so important. The important thing is that the user was seeing the
old setting instead of the new.'

def test_set_save_use(self):

    startup_cfg = StartUpConfig()
    startup_cfg.accepted_disclaimer = True
    startup_cfg.save()
    commands_to_run = ['profiles', 'use    OWASP_TOP10', 'back', 'misc-settings', 'set    msf_location    /tmp/', 'back', 'profiles', ('save_as    %s' % self.get_profile_name()), 'exit']
    self.console = ConsoleUI(commands=commands_to_run, do_upd=False)
    self.console.sh()
    expected = ('Profile    saved.',)
    (assert_result, msg) = self.startswith_expected_in_output(expected)
    self.assertTrue(assert_result, msg)
    python_executable = sys.executable
    p = subprocess.Popen([python_executable, 'w3af_console', '-n'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=False, universal_newlines=True)
    commands_to_run = ['profiles', ('use    %s' % self.get_profile_name()), 'back', 'misc-settings', 'view', 'back', 'exit']
    expected_output = '/tmp'
    (stdout, stderr) = p.communicate(('\r'.join(commands_to_run) + '\r'))
    msg = 'Failed    to    find    "%s"    in    "%s"    using    "%s"    as    python    executable.'
    msg = (msg % (expected_output, stdout, python_executable))
    self.assertIn(expected_output, stdout, msg)
