def get_auth_settings(self):
     """
     Get the email and password from the user
     """
     self.auth['email'] = util.prompt('LendingClub email', self.auth['email'])
     self.auth['pass'] = util.get_password()
     return self.auth
 def test_prompt_prefill(self):
     # User enters empty string, select prefill
     util.get_input = lambda msg: ''
     self.assertEqual(util.prompt('msg'), '')
     self.assertEqual(util.prompt('msg', 'not test'), 'not test')
 def test_prompt(self):
     # User enters 'test'
     util.get_input = lambda msg: 'test'
     self.assertEqual(util.prompt('msg'), 'test')
     self.assertEqual(util.prompt('msg', 'not test'), 'test')
    def portfolio_picker(self, default_folio=False):
        """
        Load existing portfolios and let the user choose one or create a new one
        default_folio is the name of the default portfolio, or the one that was used last time.
        """

        if not self.investor:
            return False

        print '\nPortfolios...'
        try:
            folios = self.investor.get_portfolio_list()

            # Add default portfolio to the list
            if default_folio is not False and default_folio not in folios:
                folios.append(default_folio)

            # Print out the portfolio list
            folios.sort()
            i = 1
            other_index = 0
            cancel_index = 0
            default_indicator = ''
            default_index = False
            for folio in folios:
                default_indicator = '  '
                if default_folio == folio:
                    default_indicator = '> '
                    default_index = str(i)

                print '{0}{1}: {2}'.format(default_indicator, i, folio)
                i += 1

            other_index = i
            print '  {0}: Other'.format(other_index)
            i += 1

            cancel_index = i
            print '  {0}: Cancel'.format(cancel_index)

            # Choose a portfolio
            while(True):
                choice = util.prompt('Choose one', default_index)

                # If no digit was chosen, ask again unless a default portfolio is present
                if not choice.isdigit():
                    if default_folio is not False:
                        return default_folio
                    else:
                        continue
                choice = int(choice)

                # No zero
                if choice == 0:
                    continue

                # Existing portfolio chosen
                if choice <= len(folios):
                    break

                # Other
                elif choice == other_index:
                    while(True):
                        other = util.prompt('Enter the name for your new portfolio')

                        # Empty string entered, show list again
                        if other.strip() == '':
                            break

                        # Invalid character
                        elif re.search('[^a-zA-Z0-9 ,_\-#\.]', other):
                            print 'The portfolio name \'{0}\' is not valid! Only alphanumeric, spaces , _ - # and . are allowed.'.format(other)

                        # Return custom portfolio name
                        else:
                            return other

                # Cancel
                else:
                    return False

            # Existing portfolio
            if choice < other_index:
                return folios[choice - 1]

        except Exception as e:
            self.logger.error(e)
    def portfolio_picker(self, previous_folio=False):
        """
        Load existing portfolios and let the user choose one or create a new one
        previous_folio is the name of the last portfolio selected
        """

        if not self.investor:
            return False

        print '\nPortfolios...'
        try:
            folios = self.investor.get_portfolio_list()

            # Print out the portfolio list
            i = 1
            other_index = 0
            cancel_index = 0
            previous_index = 0
            for folio in folios:
                print '{0}: {1}'.format(i, folio)

                if previous_folio == folio:
                    previous_folio = False

                i += 1

            if previous_folio is not False:
                previous_index = i
                print '{0}: {1}'.format(previous_index, previous_folio)
                i += 1

            other_index = i
            print '{0}: Other'.format(other_index)
            i += 1

            cancel_index = i
            print '{0}: Cancel'.format(cancel_index)

            # Choose a portfolio
            while(True):
                choice = util.prompt('Choose one')

                if not choice.isdigit():
                    continue
                choice = int(choice)

                # No zero
                if choice == 0:
                    continue

                # Existing portfolio chosen
                if choice <= len(folios):
                    break

                # Previous
                elif choice == previous_index:
                    return previous_folio

                # Other
                elif choice == other_index:
                    while(True):
                        other = util.prompt('Enter the name for your new portfolio')

                        # Empty string entered, show list again
                        if other.strip() == '':
                            break

                        # Invalid character
                        elif re.search('[^a-zA-Z0-9 ,_\-#\.]', other):
                            print 'The portfolio name is not valid, only alphanumeric space , _ - # and . are allowed.'

                        # Return custom portfolio name
                        else:
                            return other

                # Cancel
                else:
                    return False

            # Existing portfolio
            if choice < other_index:
                return folios[choice - 1]

        except Exception as e:
            self.logger.error(e)