Example #1
0
    def setUp(self):
        # Check if we have a previously saved user
        if NeolibTestBase.susr is not None:
            self._usr = NeolibTestBase.susr
            return

        print('')
        print('Welcome to the Neolib 2 test framework!')
        print('Please enter the below test configuration values:')

        username = input('Account username: '******'Account password: '******'Attempting to login to ' + self._usr.username)

            if self._usr.login():
                print('Successfully logged into ' + self._usr.username)

                # Store this user for later testing
                NeolibTestBase.susr = self._usr
            else:
                print('Failed to login to ' + self._usr.username +
                      '. Exiting...')
                exit()
        except Exception as e:
            print('Error while logging into ' + self._usr.username)
            print('Message: ' + str(e))
            print('Exiting...')
            exit()
def main():
    with open('user.json') as pwd_file:
        user_config = json.load(pwd_file)
    LOGDIR = user_config.get("logdir", DEFAULT_LOGDIR)

    """Set up logging in main, not global scope."""
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO) # - this is the line I needed to get logging to work!

    # So we also see logging to stderr so we can see it...
    stderr = logging.StreamHandler()
    stderr.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler())

    o_k = User(user_config['username'], user_config['password'])
    o_k.login()

    o_k.inventory.load()
    items = o_k.inventory.items
    print(items)
Example #3
0
def main():
    logger = logging.getLogger()

    stderr = logging.StreamHandler()
    stderr.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler())

    with open('user.json') as f:
        login = json.load(f)

    ok = User(login['username'], login['password'])
    if not ok.loggedIn:
        ok.login()

    nq = Neoquest(ok)

    current_state = nq.action('noop')
    print(current_state)
    current_state.map()

    raise Exception('Dummy error to drop into ipython shell')
Example #4
0
def main():
    with open('user.json') as f:
        user_config = json.load(f)
    LOGDIR = user_config.get("logdir", DEFAULT_LOGDIR)

    # Set up logging in main, not global scope.
    logger = logging.getLogger(__name__)
    logger.setLevel(
        logging.INFO)  # - this is the line I needed to get logging to work!

    fh = logging.FileHandler(os.path.join(LOGDIR, 'anacron_output.log'))
    fh.setLevel(logging.INFO)
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
    logger.addHandler(fh)

    # So we also see logging to stderr so we can see it...
    stderr = logging.StreamHandler()
    stderr.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler())

    ok = User(user_config['username'], user_config['password'])
    ok.login()

    # Start off your day by collecting interest at the bank
    ok.bank.load()
    ok.bank.collectInterest()
    logger.info('Stored/Bank NP before transactions: {}'.format(
        ok.bank.balance))
    logger.info('NP before transactions: {}'.format(ok.nps))

    # Then let's get do some dailies...
    # NOTE: doing these in this way guards from "Already did today!" exceptions
    for message in Daily.doDailies(ok, DAILY_LIST):
        logger.info(message)

    # Obviously, this script part doesn't really work anymore: but still,
    # for posterity,
    try_to_do_stocks(ok, logger)
Example #5
0
    def setup(self, config):
        """Sets up the class instance for registering a new user

        Some internal checking for validity of the given configuration values
        is done and appropiate exceptions will be raised if any validation
        fails. However, not all data can be checked in this function. To
        alleviate problems registering, please refer to the example below for
        the format in which data should be passed to this function. Please note
        that this function will fail with an exception if the dictionary
        supplied is not formatted exactly as shown in the example blelow.

        Args:
            | **attributes**: A dictionary of configuration data to be used

        Example:
            ru = RegisterUser()
            config = {
                'general': {
                    'username': '******',
                    'password': '******',
                    'country': 'US',
                    'state': 'WA',
                    'gender': 'M',
                    'birth_day': '01',
                    'birth_month': '10',
                    'birth_year': '1984',
                    'email_address': '*****@*****.**',
                },
                'neopet': {
                    'name': 'myneopetname',
                    'species': 'aisha',
                    'color': 'green',
                    'gender': 'male',
                    'terrain': '2',
                    'likes': '1',
                    'meetothers': '6',
                    'stats': '2',
                },
            }

            ru.setup(config)
        """
        # Need to force the end-user to provide all attributes
        required_gen = [
            'username', 'password', 'country', 'state', 'gender', 'birth_day',
            'birth_month', 'birth_year', 'email_address'
        ]
        required_neopet = [
            'name', 'species', 'color', 'gender', 'terrain', 'likes',
            'meetothers', 'stats'
        ]

        for r in required_gen:
            if r not in config['general'].keys():
                raise MissingRequiredAttribute(
                    'Missing required general attribute ' + r)

        for r in required_neopet:
            if r not in config['neopet'].keys():
                raise MissingRequiredAttribute(
                    'Missing required neopet attribute ' + r)

        # We can check the validity of the Neopets information
        if config['neopet']['color'] not in self.COLORS:
            raise InvalidNeopet(config['neopet']['color'] + ' is not valid')

        if int(config['neopet']['terrain']) not in self.TERRAINS.values():
            raise InvalidNeopet(config['neopet']['terrain'] + ' is not valid')

        if int(config['neopet']['likes']) not in self.LIKES.values():
            raise InvalidNeopet(config['neopet']['likes'] + ' is not valid')

        if int(config['neopet']['meetothers']) not in self.MEETOTHERS.values():
            raise InvalidNeopet(config['neopet']['meetothers'] +
                                ' is not valid')

        if int(config['neopet']['stats']) not in self.STATS:
            raise InvalidNeopet(config['neopet']['stats'] + ' is not valid')

        # Now we just try to set the config
        try:
            for key in config['general'].keys():
                setattr(self, key, config['general'][key])
        except Exception:
            raise AttributeNotFound('General attribute `' + key +
                                    '` not found')

        try:
            for key in config['neopet'].keys():
                setattr(self, 'neopet_' + key, config['neopet'][key])
        except Exception:
            raise AttributeNotFound('Neopet attribute `' + key + '` not found')

        # Setup the user instance
        self._usr = User(self.username, self.password)