climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1562260 - in /incubator/climate/trunk/ocw-ui/backend: run_webservices.py tests/ tests/__init__.py tests/test_run_webservices.py
Date Tue, 28 Jan 2014 22:19:00 GMT
Author: joyce
Date: Tue Jan 28 22:19:00 2014
New Revision: 1562260

URL: http://svn.apache.org/r1562260
Log:
CLIMATE-326 - Refactor main_ws

- Rename main_ws to run_webservices to better describe its purpose.
- Add 'status' URL as '/'
- Add test to ensure proper initialization of the Bottle application
  with WebTest. NOTE, the unit tests for the backend now require WebTest
  to be installed. Simply running 'pip install WebTest' should take care
  everything!

Added:
    incubator/climate/trunk/ocw-ui/backend/run_webservices.py
    incubator/climate/trunk/ocw-ui/backend/tests/
    incubator/climate/trunk/ocw-ui/backend/tests/__init__.py
    incubator/climate/trunk/ocw-ui/backend/tests/test_run_webservices.py

Added: incubator/climate/trunk/ocw-ui/backend/run_webservices.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/run_webservices.py?rev=1562260&view=auto
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/run_webservices.py (added)
+++ incubator/climate/trunk/ocw-ui/backend/run_webservices.py Tue Jan 28 22:19:00 2014
@@ -0,0 +1,52 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+''' OCW UI Backend web services initialization. '''
+
+from bottle import Bottle, get, hook, response
+
+app = Bottle()
+
+@app.get('/')
+def index():
+    return "OCW Backend is running!"
+
+@app.get('/static/evalResults/<filepath:path>')
+def get_eval_result_image(filepath):
+    ''' Return static file.
+    
+    Return static file specified by root + filepath where root defaults to:
+        /tmp/rcmet
+
+    The 'root' path should coincide with the work directory set used by the
+    OCW toolkit for processing.
+
+    :param filepath: The path component that when appended to the 'root' path
+        header specifies a file to return.
+    :type filepath: string
+
+    :returns: The requested file resource
+
+    '''
+    return static_file(filepath, root="/tmp/rcmet")
+
+@app.hook('after_request')
+def enable_cors():
+    ''' Allow Cross-Origin Resource Sharing for all URLs. '''
+    response.headers['Access-Control-Allow-Origin'] = '*'
+
+if __name__ == "__main__":
+    app.run(host='localhost', port=8082)

Added: incubator/climate/trunk/ocw-ui/backend/tests/__init__.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/tests/__init__.py?rev=1562260&view=auto
==============================================================================
    (empty)

Added: incubator/climate/trunk/ocw-ui/backend/tests/test_run_webservices.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/tests/test_run_webservices.py?rev=1562260&view=auto
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/tests/test_run_webservices.py (added)
+++ incubator/climate/trunk/ocw-ui/backend/tests/test_run_webservices.py Tue Jan 28 22:19:00
2014
@@ -0,0 +1,15 @@
+import unittest
+from webtest import TestApp
+
+from ..run_webservices import app
+
+test_app = TestApp(app)
+
+class TestInitialization(unittest.TestCase):
+    def test_status_page(self):
+        response = test_app.get('/')
+
+        self.assertEqual(response.status_int, 200)
+
+if __name__ == '__main__':
+    unittest.main()



Mime
View raw message