Ejemplo n.º 1
0
 def test_strangeRequestPatterns(self):
     """
     Test strange request patterns.
     """
     proc = Processor(self.env)
     # root
     data = proc.run(GET, '///')
     self.assertTrue('xml' in data)
     data = proc.run(GET, '//./')
     self.assertTrue('xml' in data)
     # results in /xml
     data = proc.run(GET, '/xml//')
     self.assertTrue('seishub' in data)
     data = proc.run(GET, '//xml/')
     self.assertTrue('seishub' in data)
     data = proc.run(GET, '//////////////////////xml//////////////')
     self.assertTrue('seishub' in data)
     data = proc.run(GET, '/////////./////////////xml///////.////.///')
     self.assertTrue('seishub' in data)
     # results in /xml/seishub
     data = proc.run(GET, '//////////////////////xml/////////////seishub/')
     self.assertTrue('schema' in data)
     data = proc.run(GET, '/////////////////xml///////.//////seishub////')
     self.assertTrue('schema' in data)
     data = proc.run(GET, '/////////////////xml/../xml////seishub////')
     self.assertTrue('schema' in data)
Ejemplo n.º 2
0
 def test_getRevisionFromNotVersionControlledResource(self):
     proc = Processor(self.env)
     # create resource
     proc.run(POST, '/get-test/notvc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/get-test/notvc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/get-test/notvc/test.xml', StringIO(XML_DOC))
     # revision #1 always exist
     # without trailing slash
     res1 = proc.run(GET, '/get-test/notvc/test.xml/1')
     data1 = res1.render(proc)
     # with trailing slash
     res2 = proc.run(GET, '/get-test/notvc/test.xml/1/')
     data2 = res2.render(proc)
     # res must be RESTResource objects
     self.assertTrue(isinstance(res1, RESTResource))
     self.assertTrue(isinstance(res2, RESTResource))
     # both results should equal
     self.assertTrue(Set(data1) == Set(data2))
     # data must be a basestring
     self.assertTrue(isinstance(data1, basestring))
     # check content
     self.assertEquals(data1, XML_DOC)
     # try to GET revision 2
     try:
         proc.run(GET, '/get-test/notvc/test.xml/2')
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 3
0
 def test_getRoot(self):
     proc = Processor(self.env)
     data = proc.run(GET, "/")
     # data must be a dict
     self.assertTrue(isinstance(data, dict))
     # check content
     self.assertTrue("xml" in data.keys())
Ejemplo n.º 4
0
 def test_getResourceIndex(self):
     """
     Tests resource index property.
     """
     proc = Processor(self.env)
     XML_DOC = XML_BASE_DOC % ("üöäß", "5")
     # create resource
     proc.run(POST, '/property-test/notvc/test.xml', StringIO(XML_DOC))
     # get index XML w/o trailing slash
     res = proc.run(GET, '/property-test/notvc/test.xml/.index')
     data = res.render_GET(proc)
     self.assertTrue("<label1>" in data)
     self.assertTrue("<value>üöäß</value>" in data)
     # get index XML w/ trailing slash
     res = proc.run(GET, '/property-test/notvc/test.xml/.index/')
     data = res.render_GET(proc)
     self.assertTrue("<label1>" in data)
     self.assertTrue("<value>üöäß</value>" in data)
     # get index XML on revision 1 w/o trailing slash
     res = proc.run(GET, '/property-test/notvc/test.xml/1/.index/')
     data = res.render_GET(proc)
     self.assertTrue("<label1>" in data)
     self.assertTrue("<value>üöäß</value>" in data)
     # get index XML on revision 1 w/ trailing slash
     res = proc.run(GET, '/property-test/notvc/test.xml/1/.index/')
     data = res.render_GET(proc)
     self.assertTrue("<label1>" in data)
     self.assertTrue("<value>üöäß</value>" in data)
     # remove resource
     proc.run(DELETE, '/property-test/notvc/test.xml')
Ejemplo n.º 5
0
 def test_getRoot(self):
     proc = Processor(self.env)
     data = proc.run(GET, '/')
     # data must be a dict
     self.assertTrue(isinstance(data, dict))
     # check content
     self.assertTrue('xml' in data.keys())
Ejemplo n.º 6
0
 def test_deleteVersionControlledResource(self):
     """
     Successful deletion of version controlled resources.
     """
     proc = Processor(self.env)
     # create resource
     proc.run(POST, '/delete-test/vc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/delete-test/vc/test.xml', StringIO(XML_VCDOC % 1))
     proc.run(PUT, '/delete-test/vc/test.xml', StringIO(XML_VCDOC % 2))
     # check latest resource - should be #20
     data = proc.run(GET, '/delete-test/vc/test.xml').render_GET(proc)
     self.assertEqual(data, XML_VCDOC % 2)
     # check oldest resource -> revision start with 1
     data = proc.run(GET, '/delete-test/vc/test.xml/1').render_GET(proc)
     self.assertEqual(data, XML_DOC)
     # delete resource
     data = proc.run(DELETE, '/delete-test/vc/test.xml')
     self.assertEqual(data, '')
     self.assertEqual(proc.code, http.NO_CONTENT)
     # fetch resource again
     try:
         proc.run(GET, '/delete-test/vc/test.xml').render_GET(proc)
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 7
0
 def test_processResource(self):
     proc = Processor(self.env)
     # upload a resource via POST
     data = proc.run(POST, '/xml/processor-test/notvc', StringIO(XML_DOC))
     # check response; data should be empty; we look into request
     self.assertFalse(data)
     self.assertEqual(proc.code, http.CREATED)
     self.assertTrue(isinstance(proc.headers, dict))
     self.assertTrue('Location' in proc.headers)
     location = proc.headers.get('Location')
     self.assertTrue(location.startswith(self.env.getRestUrl() + proc.path))
     # GET resource
     location = location[len(self.env.getRestUrl()):]
     data = proc.run(GET, location).render_GET(proc)
     self.assertEquals(data, XML_DOC)
     # overwrite this resource via PUT request
     proc.run(PUT, location, StringIO(XML_DOC2))
     # GET resource
     data = proc.run(GET, location).render_GET(proc)
     self.assertNotEquals(data, XML_DOC)
     self.assertEquals(data, XML_DOC2)
     # DELETE resource
     proc.run(DELETE, location)
     # GET deleted revision
     try:
         proc.run(GET, location).render_GET(proc)
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 8
0
 def test_checkRegisteredMappers(self):
     """
     Fetch mapper resource at different levels.
     """
     proc = Processor(self.env)
     # root level
     data = proc.run(GET, '/')
     self.assertTrue('mapper-test' in data.keys())
     self.assertTrue('testmapping4' in data.keys())
     # virtual level
     proc = Processor(self.env)
     data = proc.run(GET, '/mapper-test')
     # registered mappers
     self.assertTrue('testmapping' in data.keys())
     self.assertTrue('testmapping2' in data.keys())
     self.assertTrue('testmapping3' in data.keys())
     # unregistered mapper
     self.assertFalse('testmapping5' in data.keys())
     # content
     proc = Processor(self.env)
     data = proc.run(GET, '/mapper-test/testmapping')
     self.assertEqual(data, 'muh')
     # HEAD equals GET
     data = proc.run(HEAD, '/testmapping4')
     self.assertEquals(data, 'MÜH')
Ejemplo n.º 9
0
 def __init__(self, channel, queued):
     self.env = channel.factory.env
     Processor.__init__(self, self.env)
     http.Request.__init__(self, channel, queued)
     self.notifications = []
     # fetch default pages configuration
     self.default_pages = \
         self.env.config.getlist('web', 'default_pages') or DEFAULT_PAGES
Ejemplo n.º 10
0
 def test_getDisabledResourceType(self):
     proc = Processor(self.env)
     # without trailing slash
     try:
         proc.run(DELETE, '/get-test/notvc2')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 11
0
 def test_invalidMethods(self):
     proc = Processor(self.env)
     for method in ['MUH', 'XXX', 'GETPUT']:
         try:
             proc.run(method, '/')
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 12
0
 def test_getDisabledResourceType(self):
     proc = Processor(self.env)
     # without trailing slash
     try:
         proc.run(DELETE, '/get-test/notvc2')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 13
0
 def test_invalidMethods(self):
     proc = Processor(self.env)
     for method in ["MUH", "XXX", "GETPUT"]:
         try:
             proc.run(method, "/")
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 14
0
 def test_someRESTResourceTypes(self):
     proc = Processor(self.env)
     result = proc.run(GET, "/")
     self.assertTrue(isinstance(result.get("xml"), RESTFolder))
     result = proc.run(GET, "/xml")
     self.assertTrue(isinstance(result.get("seishub"), RESTPackageFolder))
     result = proc.run(GET, "/xml/seishub")
     self.assertTrue(isinstance(result.get("stylesheet"), RESTResourceTypeFolder))
Ejemplo n.º 15
0
 def test_executeResourceScript(self):
     """
     Files with extension '.rpy' should be interpreted as Resource scripts.
     """
     proc = Processor(self.env)
     for method in [POST, PUT, DELETE, MOVE, GET]:
         data = proc.run(method, '/scripts/test.rpy')
         self.assertEquals('<html>%s</html>' % method, data)
Ejemplo n.º 16
0
 def test_executeResourceScript(self):
     """
     Files with extension '.rpy' should be interpreted as Resource scripts.
     """
     proc = Processor(self.env)
     for method in [POST, PUT, DELETE, MOVE, GET]:
         data = proc.run(method, '/scripts/test.rpy')
         self.assertEquals('<html>%s</html>' % method, data)
Ejemplo n.º 17
0
 def test_dontReturnUnicodeFromMapper(self):
     """
     Unicodes returned from a mapper should be encoded into UTF-8 strings.
     """
     proc = Processor(self.env)
     data = proc.run(GET, '/testmapping4')
     self.assertFalse(isinstance(data, unicode))
     self.assertTrue(isinstance(data, basestring))
     self.assertEqual('MÜH', data)
Ejemplo n.º 18
0
 def test_someRESTResourceTypes(self):
     proc = Processor(self.env)
     result = proc.run(GET, '/')
     self.assertTrue(isinstance(result.get('xml'), RESTFolder))
     result = proc.run(GET, '/xml')
     self.assertTrue(isinstance(result.get('seishub'), RESTPackageFolder))
     result = proc.run(GET, '/xml/seishub')
     self.assertTrue(
         isinstance(result.get('stylesheet'), RESTResourceTypeFolder))
Ejemplo n.º 19
0
 def test_dontReturnUnicodeFromMapper(self):
     """
     Unicodes returned from a mapper should be encoded into UTF-8 strings.
     """
     proc = Processor(self.env)
     data = proc.run(GET, '/testmapping4')
     self.assertFalse(isinstance(data, unicode))
     self.assertTrue(isinstance(data, basestring))
     self.assertEqual('MÜH', data)
Ejemplo n.º 20
0
 def test_notImplementedMethods(self):
     """
     Not implemented methods should raise an error.
     """
     proc = Processor(self.env)
     try:
         proc.run('MUH', '/testmapping4')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 21
0
 def test_notImplementedMethods(self):
     """
     Not implemented methods should raise an error.
     """
     proc = Processor(self.env)
     try:
         proc.run('MUH', '/testmapping4')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 22
0
 def test_deleteResourceInNotExistingResourceType(self):
     """
     Resource can't be deleted from not existing resource type.
     """
     proc = Processor(self.env)
     try:
         proc.run(DELETE, '/delete-test/notvc2/test.xml')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
 def process_POST(self, request):
     """
     Just remap to the xml rest interface.
     """
     # Otherwise, just pass to the event xml resource handler.
     proc = Processor(self.env)
     path = "/xml/event_based_data/event"
     if request.postpath:
         path += "/" + "/".join(request.postpath)
     return proc.run(POST, path, StringIO(request.data))
Ejemplo n.º 24
0
 def test_deleteResourceInNotExistingResourceType(self):
     """
     Resource can't be deleted from not existing resource type.
     """
     proc = Processor(self.env)
     try:
         proc.run(DELETE, '/delete-test/notvc2/test.xml')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 25
0
 def test_getResourceIndex(self):
     """
     Tests resource index property.
     """
     proc = Processor(self.env)
     XML_DOC = XML_BASE_DOC % ("üöäß", "5")
     # create resource
     proc.run(POST, '/property-test/notvc/test.xml', StringIO(XML_DOC))
     # get index XML w/o trailing slash
     res = proc.run(GET, '/property-test/notvc/test.xml/.index')
     data = res.render_GET(proc)
     self.assertTrue("<label1>" in data)
     self.assertTrue("<value>üöäß</value>" in data)
     # get index XML w/ trailing slash
     res = proc.run(GET, '/property-test/notvc/test.xml/.index/')
     data = res.render_GET(proc)
     self.assertTrue("<label1>" in data)
     self.assertTrue("<value>üöäß</value>" in data)
     # get index XML on revision 1 w/o trailing slash
     res = proc.run(GET, '/property-test/notvc/test.xml/1/.index/')
     data = res.render_GET(proc)
     self.assertTrue("<label1>" in data)
     self.assertTrue("<value>üöäß</value>" in data)
     # get index XML on revision 1 w/ trailing slash
     res = proc.run(GET, '/property-test/notvc/test.xml/1/.index/')
     data = res.render_GET(proc)
     self.assertTrue("<label1>" in data)
     self.assertTrue("<value>üöäß</value>" in data)
     # remove resource
     proc.run(DELETE, '/property-test/notvc/test.xml')
Ejemplo n.º 26
0
 def test_getRevisionFromNotVersionControlledResource(self):
     proc = Processor(self.env)
     # create resource
     proc.run(POST, '/get-test/notvc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/get-test/notvc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/get-test/notvc/test.xml', StringIO(XML_DOC))
     # revision #1 always exist
     # without trailing slash
     res1 = proc.run(GET, '/get-test/notvc/test.xml/1')
     data1 = res1.render(proc)
     # with trailing slash
     res2 = proc.run(GET, '/get-test/notvc/test.xml/1/')
     data2 = res2.render(proc)
     # res must be RESTResource objects
     self.assertTrue(isinstance(res1, RESTResource))
     self.assertTrue(isinstance(res2, RESTResource))
     # both results should equal
     self.assertTrue(Set(data1) == Set(data2))
     # data must be a basestring
     self.assertTrue(isinstance(data1, basestring))
     # check content
     self.assertEquals(data1, XML_DOC)
     # try to GET revision 2
     try:
         proc.run(GET, '/get-test/notvc/test.xml/2')
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 27
0
 def test_addChild(self):
     # add a few children with absolute path to resource tree
     self.env.tree.putChild('/test/muh/muh', ATestResource('maeh'))
     self.env.tree.putChild('/test/muh/kuh', ATestResource('muh'))
     # add children with relative path to resource tree
     self.env.tree.putChild('maeh', ATestResource('you'))
     self.env.tree.putChild('test2', ATestResource('again'))
     # check the resource tree
     proc = Processor(self.env)
     # root
     data = proc.run(GET, '/')
     self.assertTrue(isinstance(data, dict))
     self.assertTrue('maeh' in data)
     self.assertTrue('test' in data)
     self.assertTrue('test2' in data)
     # sub folder
     data = proc.run(GET, '/test')
     self.assertTrue(isinstance(data, dict))
     self.assertTrue('muh' in data)
     # sub sub folder
     data = proc.run(GET, '/test/muh')
     self.assertTrue(isinstance(data, dict))
     self.assertTrue('kuh' in data)
     self.assertTrue('muh' in data)
     # resources
     data = proc.run(GET, '/test/muh/kuh')
     self.assertEquals('Hello muh!', data)
     data = proc.run(GET, '/maeh')
     self.assertEquals('Hello you!', data)
     data = proc.run(GET, '/test2')
     self.assertEquals('Hello again!', data)
     data = proc.run(GET, '/test/muh/muh')
     self.assertEquals('Hello maeh!', data)
Ejemplo n.º 28
0
 def test_deletePackage(self):
     """
     SeisHub processor does not allow deletion of packages.
     """
     proc = Processor(self.env)
     # without trailing slash
     try:
         proc.run(DELETE, '/delete-test')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 29
0
 def test_deletePackage(self):
     """
     SeisHub processor does not allow deletion of packages.
     """
     proc = Processor(self.env)
     # without trailing slash
     try:
         proc.run(DELETE, '/delete-test')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 30
0
 def test_deleteNotExistingPackage(self):
     """
     A not existing resource package can't be deleted.
     """
     proc = Processor(self.env)
     # without trailing slash
     try:
         proc.run(DELETE, '/xxx')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 31
0
 def test_oversizedURL(self):
     """
     Request URL is restricted by MAXIMAL_URL_LENGTH.
     """
     proc = Processor(self.env)
     for method in ALLOWED_HTTP_METHODS:
         try:
             proc.run(method, 'a' * MAXIMAL_URL_LENGTH, '')
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.REQUEST_URI_TOO_LONG)
Ejemplo n.º 32
0
 def test_invalidResourceIDs(self):
     """
     Resource names have to be alphanumeric, start with a character
     """
     proc = Processor(self.env)
     # root
     try:
         proc.run(POST, '/put-test/notvc/üö$%&', StringIO(XML_DOC))
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.BAD_REQUEST)
Ejemplo n.º 33
0
 def test_oversizedURL(self):
     """
     Request URL is restricted by MAXIMAL_URL_LENGTH.
     """
     proc = Processor(self.env)
     for method in ALLOWED_HTTP_METHODS:
         try:
             proc.run(method, 'a' * MAXIMAL_URL_LENGTH, '')
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.REQUEST_URI_TOO_LONG)
Ejemplo n.º 34
0
 def test_deleteNotExistingPackage(self):
     """
     A not existing resource package can't be deleted.
     """
     proc = Processor(self.env)
     # without trailing slash
     try:
         proc.run(DELETE, '/xxx')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 35
0
 def test_deleteResourceInNotExistingPackage(self):
     """
     Resource can't be deleted from not existing package.
     """
     proc = Processor(self.env)
     # with trailing slash
     try:
         proc.run(DELETE, '/delete-test2/notvc/test.xml')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 36
0
 def test_invalidResourceIDs(self):
     """
     Resource names have to be alphanumeric, start with a character
     """
     proc = Processor(self.env)
     # root
     try:
         proc.run(POST, '/put-test/notvc/üö$%&', StringIO(XML_DOC))
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.BAD_REQUEST)
Ejemplo n.º 37
0
 def test_deleteResourceInNotExistingPackage(self):
     """
     Resource can't be deleted from not existing package.
     """
     proc = Processor(self.env)
     # with trailing slash
     try:
         proc.run(DELETE, '/delete-test2/notvc/test.xml')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 38
0
 def test_moveWithoutAbsoluteDestination(self):
     """
     Destination header must be the absolute path to new destination.
     """
     proc = Processor(self.env)
     proc.run(POST, '/move-test/notvc/test.xml', StringIO(XML_DOC))
     try:
         proc.run(MOVE, '/move-test/notvc/test.xml',
                  received_headers={'Destination': '/test/notvc/muh.xml'})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.BAD_REQUEST)
Ejemplo n.º 39
0
 def test_moveWithoutDestinationHeader(self):
     """
     WebDAV HTTP MOVE request must submit a Destination header.
     """
     # create resource
     proc = Processor(self.env)
     proc.run(POST, '/move-test/notvc/test.xml', StringIO(XML_DOC))
     try:
         proc.run(MOVE, '/move-test/notvc/test.xml')
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.BAD_REQUEST)
Ejemplo n.º 40
0
 def test_moveToSameURI(self):
     """
     The source URI and the destination URI must not be the same.
     """
     proc = Processor(self.env)
     proc.run(POST, '/move-test/notvc/test.xml', StringIO(XML_DOC))
     uri = self.env.getRestUrl() + '/move-test/notvc/test.xml'
     try:
         proc.run(MOVE, '/move-test/notvc/test.xml',
                  received_headers={'Destination': uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.FORBIDDEN)
Ejemplo n.º 41
0
 def test_getPackage(self):
     proc = Processor(self.env)
     # without trailing slash
     data = proc.run(GET, '/get-test')
     # with trailing slash
     data2 = proc.run(GET, '/get-test')
     # both results should equal
     self.assertTrue(Set(data) == Set(data2))
     # data must be a dict
     self.assertTrue(isinstance(data, dict))
     # check content
     self.assertTrue('notvc' in data)
     self.assertTrue('vc' in data)
Ejemplo n.º 42
0
 def test_moveToNonExistingResourceType(self):
     """
     SeisHub allows moving resources only to existing resource types.
     """
     proc = Processor(self.env)
     proc.run(POST, '/move-test/notvc/test.xml', StringIO(XML_DOC))
     uri = self.env.getRestUrl() + '/muh/kuh/test2.xml'
     try:
         proc.run(MOVE, '/move-test/notvc/test.xml',
                  received_headers={'Destination': uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.FORBIDDEN)
Ejemplo n.º 43
0
 def test_moveToDifferentServer(self):
     """
     The destination URI is located on a different server.
     """
     proc = Processor(self.env)
     proc.run(POST, '/move-test/notvc/test.xml', StringIO(XML_DOC))
     uri = 'http://somewhere:8080/move-test/notvc/test.xml'
     try:
         proc.run(MOVE, '/move-test/notvc/test.xml',
                  received_headers={'Destination': uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.BAD_GATEWAY)
Ejemplo n.º 44
0
 def test_getPackage(self):
     proc = Processor(self.env)
     # without trailing slash
     data = proc.run(GET, '/get-test')
     # with trailing slash
     data2 = proc.run(GET, '/get-test')
     # both results should equal
     self.assertTrue(Set(data) == Set(data2))
     # data must be a dict
     self.assertTrue(isinstance(data, dict))
     # check content
     self.assertTrue('notvc' in data)
     self.assertTrue('vc' in data)
Ejemplo n.º 45
0
 def test_putOnExistingResource(self):
     """
     Put request on an already existing resource.
     """
     proc = Processor(self.env)
     # create resource
     proc.run(POST, '/put-test/notvc/test.xml', StringIO(XML_DOC))
     # create resource
     try:
         proc.run(POST, '/put-test/notvc/test.xml', StringIO(XML_DOC))
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.FORBIDDEN)
Ejemplo n.º 46
0
 def test_moveBuiltinResource(self):
     """
     SeisHub builtin resources can't be renamed or moved.
     """
     proc = Processor(self.env)
     # fetch a seishub stylesheet
     data = proc.run(GET, '/seishub/stylesheet/.meta')
     uri = '/seishub/stylesheet/' + data.keys()[0]
     to_uri = self.env.getRestUrl() + '/seishub/stylesheet/test.xml'
     try:
         proc.run(MOVE, uri, received_headers={'Destination': to_uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.FORBIDDEN)
Ejemplo n.º 47
0
 def test_getResourceIndexWithMultipleValuesAndGroupElement(self):
     """
     Tests resource index property.
     """
     proc = Processor(self.env)
     # create resource
     XML_DOC = XML_BASE_DOC2 % ("<v>1</v><v>2</v><v>3</v><u>-1</u><u>5</u>",
                                "<v>10</v><v>20</v><v>30</v>" + \
                                "<u>-10</u><u>-20</u>")
     proc.run(POST, '/property-test/notvc4/test.xml', StringIO(XML_DOC))
     # get data
     res = proc.run(GET, '/property-test/notvc4/test.xml')
     res.render_GET(proc)
     # get index
     res = proc.run(GET, '/property-test/notvc4/test.xml/.index')
     data = res.render_GET(proc)
     self.assertTrue("<label4>" in data)
     self.assertTrue("<value>1</value>" in data)
     self.assertTrue("<value>2</value>" in data)
     self.assertTrue("<value>3</value>" in data)
     self.assertTrue("<value>10</value>" in data)
     self.assertTrue("<value>20</value>" in data)
     self.assertTrue("<value>30</value>" in data)
     # remove resource
     proc.run(DELETE, '/property-test/notvc4/test.xml')
Ejemplo n.º 48
0
 def test_overwritingResourceTree(self):
     # add a few children with absolute path to resource tree
     self.env.tree.putChild('/test/muh/kuh/blub', ATestResource('World'))
     self.env.tree.putChild('/test/muh/muh/stub', ATestResource('muh'))
     # overwriting a resource
     self.env.tree.putChild('/test/muh', ATestResource('maeh'))
     # check the resource tree
     proc = Processor(self.env)
     data = proc.run(GET, '/test')
     self.assertTrue(isinstance(data, dict))
     self.assertTrue('muh' in data)
     self.assertEqual(len(data), 1)
     data = proc.run(GET, '/test/muh')
     self.assertTrue(isinstance(data, basestring))
Ejemplo n.º 49
0
 def test_getRoot(self):
     proc = Processor(self.env)
     # without trailing slash
     data = proc.run(GET, '')
     # with trailing slash
     data2 = proc.run(GET, '/')
     # both results should equal
     self.assertTrue(Set(data) == Set(data2))
     # data must be a dict
     self.assertTrue(isinstance(data, dict))
     # check content
     self.assertTrue('get-test' in data)
     self.assertTrue('seishub' in data)
     self.assertFalse('get-test2' in data)
Ejemplo n.º 50
0
 def test_moveWithoutFilename(self):
     """
     SeisHub expects as destination a full filename.
     """
     proc = Processor(self.env)
     proc.run(POST, '/move-test/notvc/test.xml', StringIO(XML_DOC))
     # directory only with trailing slash
     uri = self.env.getRestUrl() + '/move-test/vc/'
     try:
         proc.run(MOVE, '/move-test/notvc/test.xml',
                  received_headers={'Destination': uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.FORBIDDEN)
Ejemplo n.º 51
0
 def test_moveBuiltinResource(self):
     """
     SeisHub builtin resources can't be renamed or moved.
     """
     proc = Processor(self.env)
     # fetch a seishub stylesheet
     data = proc.run(GET, '/seishub/stylesheet')
     uri = '/seishub/stylesheet/' + data.keys()[0]
     to_uri = self.env.getRestUrl() + '/seishub/stylesheet/test.xml'
     try:
         proc.run(MOVE, uri, received_headers={'Destination': to_uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.FORBIDDEN)
Ejemplo n.º 52
0
 def test_moveWithOversizedDestination(self):
     """
     Destination path is restricted to MAX_URI_LENGTH chars.
     """
     proc = Processor(self.env)
     proc.run(POST, '/move-test/notvc/test.xml', StringIO(XML_DOC))
     uri = self.env.getRestUrl() + '/move-test/notvc/' + \
           'a' * (MAXIMAL_URL_LENGTH + 1)
     try:
         proc.run(MOVE, '/move-test/notvc/test.xml',
                  received_headers={'Destination': uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.REQUEST_URI_TOO_LONG)
Ejemplo n.º 53
0
 def test_deleteBuiltinResource(self):
     """
     SeisHub built-in resources can't be deleted.
     """
     proc = Processor(self.env)
     # fetch a seishub stylesheet
     data = proc.run(GET, '/seishub/stylesheet/.meta')
     for id in data:
         # skip indexes
         if id.startswith('/'):
             continue
         try:
             proc.run(DELETE, '/seishub/stylesheet/' + id)
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.FORBIDDEN)
Ejemplo n.º 54
0
 def test_moveToNewResource(self):
     """
     Resource was moved successfully to the specified destination URI.
     """
     proc = Processor(self.env)
     # create resource
     proc.run(POST, '/move-test/notvc/test.xml', StringIO(XML_DOC))
     # move
     uri = self.env.getRestUrl() + '/move-test/notvc/new.xml'
     data = proc.run(MOVE,
                     '/move-test/notvc/test.xml',
                     received_headers={'Destination': uri})
     # test if right response code
     self.assertFalse(data)
     self.assertEqual(proc.code, http.CREATED)
     # test if location header is set
     self.assertTrue(isinstance(proc.headers, dict))
     self.assertTrue('Location' in proc.headers)
     location = proc.headers.get('Location')
     self.assertEquals(location, uri)
     # get original resource
     try:
         proc.run(GET, '/move-test/notvc/test.xml').render_GET(proc)
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_FOUND)
Ejemplo n.º 55
0
 def test_processResourceType(self):
     proc = Processor(self.env)
     proc.path = '/xml/processor-test/notvc'
     # test valid GET method
     data = proc.run(GET, '/xml/processor-test/notvc/.meta')
     # data must be a dict
     self.assertTrue(isinstance(data, dict))
     # test valid POST method
     data = proc.run(POST, '/xml/processor-test/notvc', StringIO(XML_DOC))
     # check response; data should be empty; we look into request
     self.assertFalse(data)
     self.assertEqual(proc.code, http.CREATED)
     self.assertTrue(isinstance(proc.headers, dict))
     self.assertTrue('Location' in proc.headers)
     location = proc.headers.get('Location')
     self.assertTrue(location.startswith(self.env.getRestUrl() + proc.path))
     # strip REST url from location
     location = location[len(self.env.getRestUrl()):]
     # fetch resource and compare it with original
     data = proc.run(GET, location)
     self.assertTrue(data, XML_DOC)
     # delete uploaded resource
     data = proc.run(DELETE, location)
     # check response; data should be empty; we look into request
     self.assertFalse(data)
     self.assertEqual(proc.code, http.NO_CONTENT)
Ejemplo n.º 56
0
 def test_forbiddenMethodsOnRevision(self):
     proc = Processor(self.env)
     # create resource
     proc.run(POST, '/rest-test/vc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/rest-test/vc/test.xml', StringIO(XML_DOC))
     for method in [DELETE, MOVE, PUT, POST]:
         # without trailing slash
         try:
             proc.run(method, '/rest-test/vc/test.xml/2')
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.NOT_ALLOWED)
         # with trailing slash
         try:
             proc.run(method, '/rest-test/vc/test.xml/2/')
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 57
0
 def test_notImplementedMethodsOnRevision(self):
     proc = Processor(self.env)
     # create resource
     proc.run(POST, '/rest-test/vc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/rest-test/vc/test.xml', StringIO(XML_DOC))
     for method in NOT_IMPLEMENTED_HTTP_METHODS:
         # without trailing slash
         try:
             proc.run(method, '/rest-test/vc/2')
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.NOT_ALLOWED)
         # with trailing slash
         try:
             proc.run(method, '/rest-test/vc/2/')
             self.fail("Expected SeisHubError")
         except SeisHubError, e:
             self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 58
0
 def test_moveRevisionToRevision(self):
     """
     SeisHub does not allow to move revisions to revisions.
     """
     proc = Processor(self.env)
     # create resource
     proc.run(POST, '/move-test/vc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/move-test/vc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/move-test/vc/test.xml', StringIO(XML_DOC))
     proc.run(PUT, '/move-test/vc/test.xml', StringIO(XML_DOC))
     # try to move revision 2 to revision 1
     uri = self.env.getRestUrl() + '/move-test/vc/test.xml/1'
     try:
         proc.run(MOVE,
                  '/move-test/vc/test.xml/2',
                  received_headers={'Destination': uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.NOT_ALLOWED)
Ejemplo n.º 59
0
 def test_moveToNewRevision(self):
     """
     SeisHub does not allow to move a resource to a new revision.
     """
     proc = Processor(self.env)
     # create resources
     proc.run(POST, '/move-test/vc/test1.xml', StringIO(XML_DOC))
     proc.run(POST, '/move-test/vc/test2.xml', StringIO(XML_DOC))
     proc.run(PUT, '/move-test/vc/test2.xml', StringIO(XML_DOC))
     proc.run(PUT, '/move-test/vc/test2.xml', StringIO(XML_DOC))
     proc.run(PUT, '/move-test/vc/test2.xml', StringIO(XML_DOC))
     # try to create a new revision 4
     uri = self.env.getRestUrl() + '/move-test/vc/test2.xml/4'
     try:
         proc.run(MOVE,
                  '/move-test/vc/test1.xml',
                  received_headers={'Destination': uri})
         self.fail("Expected SeisHubError")
     except SeisHubError, e:
         self.assertEqual(e.code, http.FORBIDDEN)