Browse Source

API-Hour FrameworkBenchmark: Implement test 4: Fortunes finished

Ludovic Gasc (GMLudo) 10 years ago
parent
commit
d9c3b035d3

+ 5 - 0
frameworks/Python/API-Hour/hello/hello/services/world.py

@@ -1,5 +1,6 @@
 import asyncio
 import asyncio
 from random import randint
 from random import randint
+from operator import itemgetter
 
 
 @asyncio.coroutine
 @asyncio.coroutine
 def get_random_record(container):
 def get_random_record(container):
@@ -52,4 +53,8 @@ def get_fortunes(container):
         yield from cur.execute('SELECT * FROM fortune')
         yield from cur.execute('SELECT * FROM fortune')
         fortunes = yield from cur.fetchall()
         fortunes = yield from cur.fetchall()
 
 
+    fortunes.append({'id': 0, 'message': 'Additional fortune added at request time.'})
+
+    fortunes.sort(key=itemgetter('message'))
+
     return fortunes
     return fortunes

+ 2 - 2
frameworks/Python/API-Hour/hello/hello/templates/fortunes.html.j2

@@ -11,8 +11,8 @@
     </tr>
     </tr>
     {% for fortune in fortunes %}
     {% for fortune in fortunes %}
         <tr>
         <tr>
-            <td>{{ fortune['id'] }}</td>
-            <td>{{ fortune['message'] }}</td>
+            <td>{{ fortune['id']|e }}</td>
+            <td>{{ fortune['message']|e }}</td>
         </tr>
         </tr>
     {% endfor %}
     {% endfor %}
 </table>
 </table>

+ 4 - 2
frameworks/Python/API-Hour/requirements.txt

@@ -1,4 +1,4 @@
-api_hour==0.5.0
+api_hour==0.6.0
 aiopg==0.5.2
 aiopg==0.5.2
 gunicorn==19.1.1
 gunicorn==19.1.1
 psycopg2==2.5.4
 psycopg2==2.5.4
@@ -6,4 +6,6 @@ setproctitle==1.1.8
 six==1.8.0
 six==1.8.0
 ujson==1.33
 ujson==1.33
 aiohttp==0.13.1
 aiohttp==0.13.1
-PyYAML==3.11
+PyYAML==3.11
+aiohttp-jinja2==0.0.2
+MarkupSafe==0.23

+ 1 - 1
frameworks/Python/API-Hour/setup.sh

@@ -1,3 +1,3 @@
 #!/bin/bash
 #!/bin/bash
 
 
-$PY3_API_HOUR --chdir=hello/ --config_dir=hello/etc/hello/ hello:Container &
+$PY3_API_HOUR -ac --chdir=hello/ --config_dir=hello/etc/hello/ hello:Container &