def test_registry(self): reg = models.registry curr = models.Currency(10, 'NMC', 'Namecoin') bal = models.Balance(curr, 100) bal2 = models.Balance(curr, 20) reg.put(curr) reg.put(bal) reg.put(bal2) got_bal = reg.get(models.Balance, bal.id) self.assertTrue( got_bal == bal, 'Balance should be equal' ) got_bal = reg.get(models.Balance, bal2.id) self.assertTrue( bal2 == got_bal, 'Balance 2 should be equal' ) got_curr = reg.get(models.Currency, curr.id) self.assertTrue( curr == got_curr, 'Currencies should be equal' ) deleted = reg.delete(curr) self.assertTrue(deleted == curr, "should have deleted curr") got_curr = reg.get(models.Currency, curr.id) self.assertTrue( got_curr is None, 'Should not fetch object after deletion' )
def test_orders(self): c1 = models.Currency(1, 'FOO', 'Foocoin') c2 = models.Currency(2, 'BAR', 'Barcoin') exc = models.Exchange(1, c1, c2) ordr = models.Order( order_id=1, exchange=exc, bid=True, amount=Decimal('1.998'), rate=Decimal(2), filled=Decimal(1) ) comp = ordr.get_compliment() self.assertTrue(comp.exchange == exc, 'Exchanges should match') self.assertTrue(comp.rate == Decimal(2), 'Rates should match') self.assertTrue(comp.amount == Decimal('1'), 'amount should match')
def create_rate_currency(db, data_currencies, date_dt): """ Добавление записи со значением валюты """ for data_currency in data_currencies: new_row = models.Currency(code=data_currency['code'], symbol=data_currency['symbol'], rate=data_currency['rate'], date_value=date_dt) db.session.add(new_row) db.session.commit()
def test_balance(self): curr = models.Currency(10, 'BTC', 'Bitcoin') bal = models.Balance(curr, '10') self.assertTrue(isinstance(bal.id, int), 'balance should be an int') bal2 = models.Balance(curr, '11') self.assertTrue(bal.id != bal2.id, 'balance ids should not be equal') self.assertTrue(bal.amount == Decimal('10'), 'amount should match') self.assertTrue(bal.currency == curr, 'currency should match') bals = models.Balance.get_own() self.assertTrue(isinstance(bals, list), 'balances should be a list')
def putCurrenciesInDB(app): import models while(True): with app.app_context(): currDict = getCurrenciesFromAPI() for key, value in currDict.items(): curr = models.Currency.query.filter_by(code=key).first() if (curr is None): curr = models.Currency(code=key, value=value, guid=uuid.uuid4()) db.session.add(curr) else: curr.value = value db.session.commit() time.sleep(3600)
def test_currency(self): curr = models.Currency(10, 'NMC', 'Namecoin') self.assertTrue(curr.id == 10, 'ID should be 10') self.assertTrue( curr.abbreviation == 'NMC', 'abbreviation should be NMC' ) self.assertTrue(curr.name == 'Namecoin', 'Name should be Namecoin') self.assertTrue(curr == curr, 'Equality should work') self.assertFalse(curr != curr, 'Not equals should work') curs = models.Currency.get_all() self.assertTrue( 0 != len(curs), 'List of currencies should not be empty' ) self.assertTrue( isinstance(curs[0], models.Currency), 'Currency should be a Currency' )
def parse(file_): """ Parses given xml-file-like object. """ dom = minidom.parse(file_) table_no = dom.getElementsByTagName('numer_tabeli')[0].firstChild.data pub_date = dom.getElementsByTagName('data_publikacji')[0].firstChild.data positions = {} for elem1 in dom.getElementsByTagName('pozycja'): currency_name = elem1.getElementsByTagName( 'nazwa_waluty')[0].firstChild.data scaler = elem1.getElementsByTagName('przelicznik')[0].firstChild.data currency_code = elem1.getElementsByTagName( 'kod_waluty')[0].firstChild.data rate = elem1.getElementsByTagName('kurs_sredni')[0].firstChild.data positions[currency_code] = nbp_models.Currency( currency_name, currency_code, float(rate.replace(',', '.')), int(scaler)) return {'table_no': table_no, 'pub_date': pub_date, 'positions': positions}
def airport(city): url = "https://cometari-airportsfinder-v1.p.rapidapi.com/api/airports/by-text" querystring = {"text": str(city)} headers = { 'x-rapidapi-host': "cometari-airportsfinder-v1.p.rapidapi.com", 'x-rapidapi-key': "e9030cc69cmsh46998fa37a68441p18e133jsne5b9847bff25" } response = requests.request("GET", url, headers=headers, params=querystring) json_body = response.json() airport_code = json.dumps(json_body[0]["code"]) airport = "The airport located in {} can be found under airport code {} ".format( str(city), airport_code) new_message = models.Currency(airport) models.db.session.add(new_message) models.db.session.commit() return (airport)