def verify_response(response: requests.Response) -> None: if response is None: raise exceptions.ConcentUnavailableError('response is None') logger.debug('Headers received from Concent: %s', response.headers) if response.status_code % 500 < 100: raise exceptions.ConcentServiceError( "Concent service exception ({}): {}".format( response.status_code, response.text)) if not 200 <= response.status_code <= 299: logger.warning( 'Concent request failed with status %d and ' 'response: %r', response.status_code, response.text) raise exceptions.ConcentRequestError( "Concent request exception ({}): {}".format( response.status_code, response.text)) try: concent_version = response.headers['Concent-Golem-Messages-Version'] except KeyError: raise exceptions.ConcentVersionMismatchError( 'Unknown version', ours=gconst.GOLEM_MESSAGES_VERSION, theirs=None, ) if not utils.is_version_compatible( theirs=concent_version, spec=gconst.GOLEM_MESSAGES_SPEC, ): raise exceptions.ConcentVersionMismatchError( 'Incompatible version', ours=gconst.GOLEM_MESSAGES_VERSION, theirs=concent_version, )
def test_invalid(self): self.assertFalse(utils.is_version_compatible(fake.word(), self.spec)) # noqa pylint: disable=no-member
def test_None(self): self.assertFalse(utils.is_version_compatible(None, self.spec))
def test_lower_minor(self): self.assertFalse(utils.is_version_compatible('0.10.1', self.spec))
def test_lower_patch(self): self.assertTrue(utils.is_version_compatible('0.11.0', self.spec))
def test_equal(self): self.assertTrue( utils.is_version_compatible(str(self.version), self.spec), )
def test_higher_minor(self): self.assertFalse(utils.is_version_compatible('0.12.0', self.spec))