def test_banks(monkeypatch, read_fixture): @classmethod # hack def get_archive(cls, url): basename = path.basename(url) if basename == 'bik_swift-bik.zip': return read_fixture(basename) return read_fixture('bik_db_28062018.zip') monkeypatch.setattr(Banks, '_get_archive', get_archive) banks = Banks('2018-06-29') bank = banks['045004641'] assert bank.place == 'НОВОСИБИРСК' assert bank.place_type.shortname == 'Г' assert bank.region.name == 'НОВОСИБИРСКАЯ ОБЛАСТЬ' try: bank = banks['SABRRUMMNH1'] # by swift bic assert bank.bic == '045004641' except KeyError: # no swift data pass annotated = Banks.annotate([bank])[0] assert annotated['БИК'] == '045004641' assert 'vkey' not in annotated['Тип']
def test_banks(legacy, monkeypatch, datafix_readbin): @classmethod # hack def get_archive(cls, url): if legacy: basename = path.basename(url) if basename == 'bik_swift-bik.zip': return datafix_readbin(basename, io=True) return datafix_readbin('bik_db_28062018.zip', io=True) return datafix_readbin('20201204ED01OSBR.zip', io=True) monkeypatch.setattr(Banks, '_get_archive', get_archive) banks = Banks('2018-06-29' if legacy else '2020-11-04') bank0 = banks['dummy'] bank = banks['045004641'] if legacy: assert bank.place == 'НОВОСИБИРСК' assert bank.place_type.shortname == 'Г' assert bank.region.name == 'НОВОСИБИРСКАЯ ОБЛАСТЬ' else: assert bank.place == 'Новосибирск' assert bank.place_type == 'г' assert bank.region_code == '50' bank_swift = banks['SABRRUMMNH1'] # by swift bic if bank_swift: assert bank_swift.bic == '045004641' annotated = Banks.annotate([bank, bank0])[0] assert annotated['БИК'] == '045004641' assert 'vkey' not in annotated['Тип'] if not legacy: bank = banks['044525487'] # Test restrictions assert bank.restricted assert len(bank.restrictions) == 2 annotated = Banks.annotate([bank])[0] assert annotated['Ограничения'] assert annotated['Счета'] # Test accounts assert bank.accounts account = bank.accounts[0] assert account.number == '30101810400000000487' assert 'CRSA' in f'{account}' assert len(account.restrictions) == 2
def banks(date, bic): """Prints out banks information.""" banks = Banks(on_date=date) if bic: banks = [banks[bic]] else: banks = banks.banks for bank in Banks.annotate(banks): click.secho('') for title, value in bank.items(): value and click.secho('%s: %s' % (title, value))
rates.date_received # 2016-06-25 00:00:00 rates.dates_match # False # Note: 26th of June was a holiday, data is taken from the 25th. # Various indexing is supported: rates['USD'].name # US Dollar rates['R01235'].name # US Dollar rates['840'].name # US Dollar rates['USD'] ''' ExchangeRate( id='R01235', name='US Dollar', code='USD', num='840', value=Decimal('65.5287'), par=Decimal('1'), rate=Decimal('65.5287')) ''' ''' banks = Banks() bank = banks['045004641'] bank.swift # SABRRUMMNH1 bank.corr # 30101810500000000641 bank_annotated = Banks.annotate([bank])[0] for title, value in bank_annotated.items(): print('%s: %s' % (title, value)) '''
def test_get_archive(): assert Banks._get_data_swift()