示例#1
0
  def test_generic_error(self):
    def bad_method(ctx):
      raise KeyError
    self.logic_registry.register(bad_method)

    request = {
        'main': {
          'service': 'bad_method'
        }
    }
    
    with self.assertRaises(KeyError):
      phero.process_request(self.registries, request)

    expected = {
        'error': 'GenericInternalError'
    }

    actual = phero.process_request(self.registries, request, catch_all=True)

    self.assertEquals(expected, actual)
示例#2
0
  def test_phero_error(self):
    request = {
        'main': {
          'service': 'does_not_exist'
        }
    }
    expected = {
        'error': 'UnknownService',
        'details': { 'service': 'does_not_exist' }
    }

    actual = phero.process_request(self.registries, request)

    self.assertEquals(expected, actual)
示例#3
0
  def test_basic(self):
    request = {
        'main': {
          'service': 'whoami',
          'args': { 'all_caps': True }
        },
        'auth': {
          'service': 'simple_auth',
          'args': { 'username': '******' }
        }
    }
    expected = { 'result': 'ALEX' }

    actual = phero.process_request(self.registries, request)

    self.assertEquals(expected, actual)
示例#4
0
  def test_custom_error(self):
    class AuthError(phero.PheroError): pass
    def bad_auth(ctx):
      raise AuthError(msg='I hate you')
    self.auth_registry.register(bad_auth)

    request = {
        'auth': {
          'service': 'bad_auth'
        }
    }
    expected = {
        'error': 'AuthError',
        'details': { 'msg': 'I hate you' }
    }

    actual = phero.process_request(self.registries, request)

    self.assertEquals(expected, actual)
示例#5
0
  def test_no_args(self):
    def whoami_simple(ctx):
      return ctx['auth']
    self.logic_registry.register(whoami_simple)

    request = {
        'main': {
          'service': 'whoami_simple',
        },
        'auth': {
          'service': 'simple_auth',
          'args': { 'username': '******' }
        }
    }
    expected = { 'result': 'alex' }

    actual = phero.process_request(self.registries, request)

    self.assertEquals(expected, actual)