def test_call(self): failover_response = FailoverResponse(user_id()) self.assertDictEqual( failover_response.call(), { 'action': configuration.failover_strategy, 'user_id': user_id(), 'failover': True, 'failover_reason': None })
def authenticate(self, options): if self.tracked(): try: response = self.api.call( CommandsAuthenticate(self.context).build(options)) response.update(failover=False, failover_reason=None) return response except InternalServerError as exception: return Client.failover(options, exception) else: return FailoverResponse(options['user_id'], 'allow', 'Castle set to do not track.').call()
def authenticate(self, options): if self.tracked(): self._add_timestamp_if_necessary(options) command = CommandsAuthenticate(self.context).build(options) try: response = self.api.call(command) response.update(failover=False, failover_reason=None) return response except (RequestError, InternalServerError) as exception: return Client.failover_response_or_raise(options, exception) else: return FailoverResponse(options.get('user_id'), 'allow', 'Castle set to do not track.').call()
def failover_response_or_raise(options, exception): if configuration.failover_strategy == 'throw': raise exception return FailoverResponse(options.get('user_id'), None, exception.__class__.__name__).call()
def failover(options, exception): if configuration.failover_strategy != 'throw': return FailoverResponse(options['user_id'], None, exception.__class__.__name__).call() raise exception
def test_strategy_not_passed(self): failover_response = FailoverResponse(user_id()) self.assertEqual(failover_response.user_id, user_id()) self.assertEqual(failover_response.strategy, configuration.failover_strategy)
def test_strategy_passed(self): failover_response = FailoverResponse(user_id(), strategy()) self.assertEqual(failover_response.user_id, user_id()) self.assertEqual(failover_response.strategy, strategy())