Exemplo n.º 1
0
 def testBadEchoWithPosArg(self):
     "Echo takes one argument (message), with the positional argument it should fail"
     verb ='POST'
     url = self.urlbase + 'echo/stuff'
     input_data={'message': 'unit test'}
     output={'code':400, 'type':'text/json'}
     methodTest(verb, url, input_data, output=output)
Exemplo n.º 2
0
    def testPing(self):
        verb ='GET'
        url = self.urlbase + 'ping'
        output={'code':200, 'type':'text/json', 'data':'"ping"'}
        expireTime =3600

        methodTest(verb, url, output=output, expireTime=expireTime)
Exemplo n.º 3
0
    def testInnerPingPass(self):
        verb ='GET'
        url = self.urlbase + 'foo/ping'
        output={'code':200, 'data':'"ping"'}
        expireTime =3600

        methodTest(verb, url, output=output, expireTime=expireTime)
Exemplo n.º 4
0
    def testSupportedFormat(self):
        rf = RESTFormatter(config=self.config.Webtools)
        url = self.urlbase +'list1/'

        for type in rf.supporttypes.keys():
            # test accepted type should return 200 error
            methodTest('GET', url, accept=type, output={'code':200})
Exemplo n.º 5
0
    def testSupportedFormat(self):
        rf = RESTFormatter(config=self.config.Webtools)
        url = self.urlbase +'list1/'

        for type in rf.supporttypes.keys():
            # test accepted type should return 200 error
            methodTest('GET', url, accept=type, output={'code':200})
Exemplo n.º 6
0
 def testBadEchoWithPosArg(self):
     "Echo takes one argument (message), with the positional argument it should fail"
     verb ='POST'
     url = self.urlbase + 'echo/stuff'
     input_data={'message': 'unit test'}
     output={'code':400, 'type':'text/json'}
     methodTest(verb, url, input_data, output=output)
Exemplo n.º 7
0
    def testEncodedInput(self):
        textType = 'text/plain'

        url = self.urlbase + 'list3?a=a%&b=b'
        data = json.dumps({'a': 'a%', 'b': 'b'})
        methodTest('GET',
                   url,
                   accept=textType,
                   output={
                       'code': 200,
                       'data': data
                   })

        request_input = {'a': '%', 'b': 'b'}

        #methodTest encoded input with urlencode
        url = self.urlbase + 'list3'
        data = json.dumps({'a': '%', 'b': 'b'})
        methodTest('GET',
                   url,
                   accept=textType,
                   request_input=request_input,
                   output={
                       'code': 200,
                       'data': data
                   })
Exemplo n.º 8
0
    def testPing(self):
        verb ='GET'
        url = self.urlbase + 'ping'
        output={'code':200, 'type':'text/json', 'data':'"ping"'}
        expireTime =3600

        methodTest(verb, url, output=output, expireTime=expireTime)
Exemplo n.º 9
0
 def testNoArgMethods(self):
     """
     list1 takes no arguments, it should raise an error if called with one. Require json output.
     """
     return_type = 'application/json'
     url = self.urlbase + 'list1?int=a'
     expected_data = """{"exception": 400, "message": "Invalid input", "type": "HTTPError"}"""
     methodTest('GET', url, accept=return_type, output={'code':400, 'data':expected_data})
Exemplo n.º 10
0
 def testNoArgMethods(self):
     """
     list1 takes no arguments, it should raise an error if called with one. Require json output.
     """
     return_type = 'application/json'
     url = self.urlbase + 'list1?int=a'
     expected_data = """{"exception": 400, "message": "Invalid input: Arguments added where none allowed", "type": "HTTPError"}"""
     methodTest('GET', url, accept=return_type, output={'code':400, 'data':expected_data})
Exemplo n.º 11
0
    def testGoodEcho(self):
        verb ='POST'
        url = self.urlbase + 'echo'
        input_data={'message': 'unit test'}
        output={'code':200, 'type':'text/json',
              'data':'{"message": "unit test"}'}

        methodTest(verb, url, input_data, output=output)
Exemplo n.º 12
0
    def testBadVerbEcho(self):
        "echo is only available to GET and POST, so should raise a 501"
        url = self.urlbase + 'echo'
        input_data = {'data': 'unit test'}
        output = {'code':501, 'type':'text/json'}

        for verb in ['DELETE']:
            methodTest(verb, url, input_data, output=output)
Exemplo n.º 13
0
    def testInnerPingError(self):
        verb ='GET'
        url = self.urlbase + 'foo/123/ping'
        output={'code':400}
        methodTest(verb, url, output=output)

        url = self.urlbase + 'foo/ping/123'
        methodTest(verb, url, output=output)
Exemplo n.º 14
0
    def testGoodEcho(self):
        verb ='POST'
        url = self.urlbase + 'echo'
        input_data={'message': 'unit test'}
        output={'code':200, 'type':'text/json',
              'data':'{"message": "unit test"}'}

        methodTest(verb, url, input_data, output=output)
Exemplo n.º 15
0
    def testBadVerbEcho(self):
        "echo is only available to GET and POST, so should raise a 501"
        url = self.urlbase + 'echo'
        input={'data': 'unit test'}
        output={'code':501, 'type':'text/json'}

        for verb in ['DELETE']:
          methodTest(verb, url, input, output=output)
Exemplo n.º 16
0
    def testBadMethodEcho(self):
        """
        The echo method isn't supported by GET, so should raise a 405
        """
        verb ='GET'
        url = self.urlbase + 'echo'
        input={'data': 'unit test'}
        output={'code':405, 'type':'text/json'}

        methodTest(verb, url, input, output=output)
Exemplo n.º 17
0
    def testBadMethodEcho(self):
        """
        The echo method isn't supported by GET, so should raise a 405
        """
        verb ='GET'
        url = self.urlbase + 'echo'
        input_data = {'data': 'unit test'}
        output = {'code':405, 'type':'text/json'}

        methodTest(verb, url, input_data, output=output)
Exemplo n.º 18
0
 def testGenerator(self):
     rf = RESTFormatter(config=self.config.Webtools)
     url = self.urlbase +'gen'
     # gen method from DummyRESTModel will return this generator
     gen = ({'idx':i} for i in range(10))
     # the WMCore should convert it into list regardless of accept type
     data = rf.json(gen)
     methodTest('GET', url, accept='application/json',
                      output={'code':200, 'data':data})
     methodTest('GET', url, accept='*/*',
                      output={'code':200, 'data':data})
Exemplo n.º 19
0
    def testReturnFormat(self):
        return_type = 'application/json'

        url = self.urlbase +'list3?a=a%&b=b'
        methodTest('GET', url, accept=return_type,
                         output={'code':200, 'data':'{"a": "a%", "b": "b"}'})

        url = self.urlbase + 'list?input_int=a&input_str=a'
        expected_data = '''{"exception": 400, "message": "Invalid input: Input data failed validation.", "type": "HTTPError"}'''
        methodTest('GET', url, accept=return_type,
                         output={'code':400, 'data':expected_data})
Exemplo n.º 20
0
    def testReturnFormat(self):
        return_type = 'application/json'

        url = self.urlbase +'list3?a=a%&b=b'
        methodTest('GET', url, accept=return_type,
                         output={'code':200, 'data':'{"a": "a%", "b": "b"}'})

        url = self.urlbase + 'list?input_int=a&input_str=a'
        expected_data = '''{"exception": 400, "message": "Invalid input", "type": "HTTPError"}'''
        methodTest('GET', url, accept=return_type,
                         output={'code':400, 'data':expected_data})
Exemplo n.º 21
0
 def testGenerator(self):
     rf = RESTFormatter(config=self.config.Webtools)
     url = self.urlbase +'gen'
     # gen method from DummyRESTModel will return this generator
     gen = ({'idx':i} for i in range(10))
     # the WMCore should convert it into list regardless of accept type
     data = rf.json(gen)
     methodTest('GET', url, accept='application/json',
                      output={'code':200, 'data':data})
     methodTest('GET', url, accept='*/*',
                      output={'code':200, 'data':data})
Exemplo n.º 22
0
    def testAuthentication(self):
        verb ='PUT'
        url = self.urlbase + 'list1'
        urllib_data = urllib.urlopen(url)
        self.assertEquals(urllib_data.getcode(), 403)

        # pass proper role
        output={'code':200}
        methodTest(verb, url, output=output,
                   secure=True, secureParam={'key': secureKey,
                                             'role': DUMMY_ROLE,
                                             'group': DUMMY_GROUP,
                                             'site': DUMMY_SITE})
Exemplo n.º 23
0
    def testEncodedInput(self):
        type = 'text/plain'

        url = self.urlbase + 'list3?a=a%&b=b'
        methodTest('GET', url, accept=type,
                         output={'code':200, 'data':"{'a': 'a%', 'b': 'b'}"})

        request_input={'a':'%', 'b':'b'}

        #methodTest encoded input with urlencode
        url = self.urlbase +'list3'
        methodTest('GET', url, accept=type, request_input=request_input,
                 output={'code':200, 'data':"{'a': '%', 'b': 'b'}"})
Exemplo n.º 24
0
    def testAuthentication(self):
        verb ='PUT'
        url = self.urlbase + 'list1'
        urllib_data = urllib.request.urlopen(url)
        self.assertEqual(urllib_data.getcode(), 403)

        # pass proper role
        output={'code':200}
        methodTest(verb, url, output=output,
                   secure=True, secureParam={'key': secureKey,
                                             'role': DUMMY_ROLE,
                                             'group': DUMMY_GROUP,
                                             'site': DUMMY_SITE})
Exemplo n.º 25
0
 def testSpecific404Exception(self):
     """
     Method will raise an HTTPError and return 404
     """
     url = self.urlbase + 'specific_404_exception'
     response, expires = methodTest('GET', url, output={'code':404})
     assert json.loads(response)['message'] == "I threw a 404", 'got: %s' % json.loads(response)['message']
Exemplo n.º 26
0
 def testList(self):
     verb ='GET'
     url = self.urlbase + 'list/'
     request_input = {'input_int':123, 'input_str':'abc'}
     output={'code':200, 'type':'text/json'}
     result = json.loads(methodTest(verb, url, request_input=request_input, output=output)[0])
     for i in result.keys():
         self.assertEqual(result[i], request_input[i], '%s does not match response' % i)
Exemplo n.º 27
0
 def testNotSerialisableException(self):
     """
     Method will raise an EncodeError and return 500
     """
     url = self.urlbase + 'not_serialisable'
     response, expires = methodTest('GET', url, output={'code':500})
     assert json.loads(response)['message'] == "Server Error", 'got: %s' % json.loads(response)['message']
     assert json.loads(response)['type'] == "TypeError", 'got: %s' % json.loads(response)['type']
Exemplo n.º 28
0
 def testGeneratorMethod(self):
     # test not accepted type should return 406 error
     url = self.urlbase + 'gen'
     output={'code':200}
     data, _ = methodTest('GET', url, accept='text/json', output=output)
     data = json.loads(data)
     self.assertEqual(type(data), list)
     self.assertEqual(type(data[0]), dict)
Exemplo n.º 29
0
 def testList(self):
     verb ='GET'
     url = self.urlbase + 'list/'
     request_input = {'input_int':123, 'input_str':'abc'}
     output={'code':200, 'type':'text/json'}
     result = json.loads(methodTest(verb, url, request_input=request_input, output=output)[0])
     for i in result.keys():
         self.assertEqual(result[i], request_input[i], '%s does not match response' % i)
Exemplo n.º 30
0
 def testGenericException(self):
     """
     Method will raise an AssertionError and return 500
     """
     url = self.urlbase + 'generic_exception'
     response, expires = methodTest('GET', url, output={'code':500})
     assert json.loads(response)['message'] == "Server Error", 'got: %s' % json.loads(response)['message']
     assert json.loads(response)['type'] == "AssertionError", 'got: %s' % json.loads(response)['type']
Exemplo n.º 31
0
 def testGeneratorMethod(self):
     # test not accepted type should return 406 error
     url = self.urlbase + 'gen'
     output={'code':200}
     data, _ = methodTest('GET', url, accept='text/json', output=output)
     data = json.loads(data)
     self.assertEquals(type(data), list)
     self.assertEquals(type(data[0]), dict)
Exemplo n.º 32
0
 def testSpecific400Exception(self):
     """
     Method will raise an HTTPError and return 400
     """
     url = self.urlbase + 'specific_400_exception'
     response, expires = methodTest('GET', url, output={'code': 400})
     assert json.loads(
         response)['message'] == "I threw a 400", 'got: %s' % json.loads(
             response)['message']
Exemplo n.º 33
0
 def testNotSerialisableException(self):
     """
     Method will raise an EncodeError and return 500
     """
     url = self.urlbase + 'not_serialisable'
     response, expires = methodTest('GET', url, output={'code': 500})
     assert json.loads(
         response)['message'] == "Server Error", 'got: %s' % json.loads(
             response)['message']
     assert json.loads(response)[
         'type'] == "TypeError", 'got: %s' % json.loads(response)['type']
Exemplo n.º 34
0
 def testGenericException(self):
     """
     Method will raise an AssertionError and return 500
     """
     url = self.urlbase + 'generic_exception'
     response, expires = methodTest('GET', url, output={'code': 500})
     assert json.loads(
         response)['message'] == "Server Error", 'got: %s' % json.loads(
             response)['message']
     assert json.loads(
         response
     )['type'] == "AssertionError", 'got: %s' % json.loads(response)['type']
Exemplo n.º 35
0
    def testBadPing(self):
        verb = 'GET'

        url = self.urlbase + 'wrong'
        output = {'code': 404}
        methodTest(verb, url, output=output)

        url = self.urlbase + 'echo'
        output = {'code': 405}
        methodTest(verb, url, output=output)

        url = self.urlbase + 'ping/wrong'
        output = {'code': 400}
        methodTest(verb, url, output=output)
Exemplo n.º 36
0
    def testBadPing(self):
        verb ='GET'

        url = self.urlbase + 'wrong'
        output={'code':404}
        methodTest(verb, url, output=output)

        url = self.urlbase + 'echo'
        output={'code':405}
        methodTest(verb, url, output=output)


        url = self.urlbase + 'ping/wrong'
        output={'code':400}
        methodTest(verb, url, output=output)
Exemplo n.º 37
0
    def testOuterFooPass(self):
        verb ='GET'
        url = self.urlbase + 'foo'
        output={'code':200, 'data':'"foo"'}
        expireTime =3600
        methodTest(verb, url, output=output, expireTime=expireTime)

        url = self.urlbase + 'foo/test'
        output={'code':200, 'data':'"foo test"'}
        methodTest(verb, url, output=output, expireTime=expireTime)

        url = self.urlbase + 'foo'
        request_input = {'message': 'test'}
        output={'code':200, 'data':'"foo test"'}
        methodTest(verb, url, request_input=request_input, output=output, expireTime=expireTime)
Exemplo n.º 38
0
 def testUnsupportedFormat(self):
     # test not accepted type should return 406 error
     url = self.urlbase + 'ping'
     methodTest('GET', url, accept='text/das', output={'code':406})
Exemplo n.º 39
0
 def testUnsupportedFormat(self):
     # test not accepted type should return 406 error
     url = self.urlbase + 'ping'
     methodTest('GET', url, accept='text/das', output={'code':406})
Exemplo n.º 40
0
 def testOuterFooError(self):
     verb ='GET'
     url = self.urlbase + 'foo/123/567'
     output={'code':400}
     methodTest(verb, url, output=output)