def test_invalid(self):
     # Validate the exception path
     request = create_request('foo', [])
     # This will trigger a KeyError when get_response tries to access the
     # 'userInfo'
     del request.json['request']['userInfo']
     response = namespace_validation.get_response(request)
     self.assertEqual("Invalid request",
                      json.loads(response)['response']['status']['message'])
 def runtest(self, namespace, groups, expect):
     # Make test failures easier to identify
     failmsg = "expect={}, namespace={}, groups={}".format(
         expect, namespace, groups)
     request = create_request(namespace, groups)
     response = namespace_validation.get_response(request)
     response = json.loads(response)['response']
     self.assertEqual(expect, response['allowed'], failmsg)
     # On DENY, validate the status message
     if not expect:
         self.assertEqual(
             "You cannot update the privileged namespace {}.".format(
                 namespace), response['status']['message'], failmsg)