def test_fetch_auth_key(self): fak = PhishNetAPI(api_key='foo') with requests_mock.mock() as m: m._adapter.register_uri('GET', 'https://api.phish.net/api.json', [ {'text': '{"success": "0"}', 'status_code': 200}, ]) self.assertRaises(AuthError, fak.fetch_auth_key, 'wilson') with requests_mock.mock() as m: m._adapter.register_uri('GET', 'https://api.phish.net/api.json', [ {'text': '{"success": "0"}', 'status_code': 200}, ]) m._adapter.register_uri('POST', 'https://api.phish.net/api.json', [ {'text': '{"success": "1", "authkey": "232342342342"}', 'status_code': 200} ]) self.assertEqual('232342342342', fak.fetch_auth_key('wilson', 'password'))
def test_fetch_auth_key(self): fak = PhishNetAPI(api_key='foo') with requests_mock.mock() as m: m._adapter.register_uri('GET', 'https://api.phish.net/api.json', [ { 'text': '{"success": "0"}', 'status_code': 200 }, ]) self.assertRaises(AuthError, fak.fetch_auth_key, 'wilson') with requests_mock.mock() as m: m._adapter.register_uri('GET', 'https://api.phish.net/api.json', [ { 'text': '{"success": "0"}', 'status_code': 200 }, ]) m._adapter.register_uri( 'POST', 'https://api.phish.net/api.json', [{ 'text': '{"success": "1", "authkey": "232342342342"}', 'status_code': 200 }]) self.assertEqual('232342342342', fak.fetch_auth_key('wilson', 'password'))