def test_go_failed(self, requests): requests.get.return_value = DummyResponse('', 404) rest = Spell({ 'endpoint': self.ENDPOINT }) results = rest.go() for item in results: assert not item requests.get.assert_called_once_with(self.ENDPOINT, headers=rest.get_headers())
def get_headers(self): headers = BaseRest.get_headers(self) headers['X-Access-Token'] = self.config.get('token') headers['X-Client-ID'] = self.config.get('client_id') return headers
def go(self): for item in BaseSpell.go(self): data = item['data'][0] net = float(data['net']) yield { 'name': data['name'], 'unit_value': net, 'date': data['enddate'], 'total_value': net * float(self.config['units']) }
def __init__(self, config): code = config['code'] print(config) config[ 'endpoint'] = f'https://fund.10jqka.com.cn/data/client/myfund/{code}' BaseSpell.__init__(self, config)
def __init__(self, config): BaseRest.__init__(self, config)
def test_intro(self): name = Spell.intro() assert type(name) == str assert len(name) > 0
def test_name(self): name = Spell.name() assert type(name) == str assert len(name) > 0