예제 #1
0
 def test_email_validate(self):
     validator = Validators(self.df)
     result = validator._email_validate(self.df.loc[0])
     if result:
         self.assertIs(type(result), dict)
     else:
         self.assertIsNone(result)
예제 #2
0
 def test_validate_errors(self):
     validator = Validators(self.df)
     result = validator._validate_errors(self.df.loc[2])
     if result:
         self.assertIs(type(result), list)
     else:
         valid = validator_validate(self.df.loc[2])
         self.assertTrue(valid)
예제 #3
0
    def __init__(self,
                 xml_node="carrinho",
                 namespace="http://connect.akatus.com/"):
        """Metodo construtor que recebe o nome do node pai do XML de envio
        e o namespace para a validacao no XML Schema"""

        self.validators = Validators()

        if xml_node:
            self.xml_node = etree.Element(xml_node, xmlns=namespace)
예제 #4
0
def file_saver(file):
    '''
    Saves uploaded file as a json file, in a SQL database, and creates a
    pandas dataframe to run validation test
  '''
    # check filename uniqueness
    filename = file_exists(file.filename)

    # saves original uploaded file to files directory
    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

    #creates pandas dataframe from the csv file
    df = pd.read_csv('files/' + filename, sep='|')

    # run validation rules
    validate = Validators(df=df)
    data = validate.clean_orders()

    #create a dictionary from pandas dataframe
    d = [
        dict([(colname, row[i]) for i, colname in enumerate(data.columns)])
        for row in data.values
    ]

    # seeds database with order information
    Orders.query.delete()
    for order_row in d:
        order_id = order_row['id']
        name = order_row['name']
        state = order_row['state']
        email = order_row['email']
        zipcode = order_row['zipcode']
        birthday = order_row['birthday']
        valid = str(order_row['valid'])
        errors = str(order_row['errors'])
        save_order = Orders(order_id=order_id,
                            name=name,
                            state=state,
                            email=email,
                            zipcode=zipcode,
                            birthday=birthday,
                            valid=valid,
                            errors=errors)
        db.session.add(save_order)
    db.session.commit()

    # create json file
    with open('files/' + filename.rsplit('.', 1)[0] + '.json', 'w') as outfile:
        json.dump(d, outfile)
    return outfile
예제 #5
0
            #print('Genesis',json.dumps(near_blockchain.genesis, indent=4, sort_keys=True))
            print('Epoch t     seat price', near_blockchain.get_seat_price(epoch='current'))
            print('Epoch t + 1 seat price', near_blockchain.get_seat_price(epoch='next'))
            print('Epoch t + 2 seat price', near_blockchain.get_seat_price(epoch='proposals'))
            print('Percentage current epoch ', epoch_percentage)

        # Make sure bot runs only once per epoch to avoid spamming       
        if epoch_percentage > 95 and bot_has_been_executed:
            bot_has_been_executed = False
        elif epoch_percentage <= 95:
            bot_has_been_executed = True

        # if in debug mode always run
        if not bot_has_been_executed:
            # create master account
            validators_node = Validators(CONTRACT_NAME, PATH_TO_JSON_PRIVATE_KEY_FILE_MASTER_ACCOUNT, ENDPOINT_URL)
            estimated_seat_price_nextnext_epoch = near_blockchain.get_seat_price(epoch='proposals')
            amount_master_account_unlocked = int(validators_node.get_master_account().state['amount'])

            # ping contract before proceding
            # near call my_validator ping '{}' --accountId user1
            
            validators_node.get_master_account().function_call(
                contract_id = CONTRACT_NAME, 
                method_name = 'ping', 
                args = None, 
                gas = DEFAULT_ATTACHED_GAS)
            

            # if master account has more that 1 NEAR deposit it to contract
            if amount_master_account_unlocked > YOCTO_CONSTANT and DEPOSIT_ALL_TOKENS_FROM_MASTERACCOUNT_INTO_CONTRACT: