diff --git a/revolut/base.py b/revolut/base.py index 8dbb986..c8df4ab 100644 --- a/revolut/base.py +++ b/revolut/base.py @@ -29,7 +29,7 @@ def _request(self, func, path, data=None): if rsp.status_code != 204: result = rsp.json(parse_float=Decimal) if rsp.status_code < 200 or rsp.status_code >= 300: - message = getattr(result, "message", "No message supplied") + message = result.get("message", "No message supplied") _log.error("HTTP {} for {}: {}".format(rsp.status_code, url, message)) if rsp.status_code in (400, 422): if "o pocket found" in message: diff --git a/revolut/business.py b/revolut/business.py index 4aa6748..9c61c71 100644 --- a/revolut/business.py +++ b/revolut/business.py @@ -50,7 +50,7 @@ def counterparties(self): return self._counterparties def _refresh_counterparties(self): - self._counterparties = self._cptbyaccount = {} + self._counterparties = self._cptbyaccount = None _ = self.counterparties def transactions( diff --git a/tests/test_business.py b/tests/test_business.py index ff669e3..007ed7a 100644 --- a/tests/test_business.py +++ b/tests/test_business.py @@ -53,7 +53,6 @@ def test_refresh_token_via_renewable_session(self): self.assertIsNotNone(sess.access_token) self.assertIn("grant_type=refresh_token", responses.calls[0].request.body) - class TestRevolutBusiness(TestCase, JSONResponsesMixin): access_token = "oa_sand_lI35rv-tpvl0qsKa5OJGW5yiiXtKg7uZYB6b0jmLSCk" @@ -67,16 +66,19 @@ def test_key(self): @responses.activate def test_404(self): + message = "The requested resource not found" responses.add( responses.GET, "https://sandbox-b2b.revolut.com/api/1.0/whatever", - json={"message": "The requested resource not found"}, + json={"message": message}, status=404, ) tssn = TemporarySession(self.access_token) cli = BusinessClient(tssn) - self.assertRaises(exceptions.RevolutHttpError, cli._get, "whatever") + with self.assertRaises(exceptions.RevolutHttpError) as cm: + cli._get("whatever") + self.assertEqual(str(cm.exception), message) @responses.activate def test_accounts(self):