Browse Source

Use create-postgres.sql

ijl 11 years ago
parent
commit
e491fb6658

+ 16 - 16
config/create-postgres.sql

@@ -1,29 +1,29 @@
-DROP TABLE IF EXISTS World;
+DROP TABLE IF EXISTS "World";
 CREATE TABLE  "World" (
 CREATE TABLE  "World" (
   id integer NOT NULL,
   id integer NOT NULL,
-  randomNumber integer NOT NULL default 0,
+  "randomNumber" integer NOT NULL default 0,
   PRIMARY KEY  (id)
   PRIMARY KEY  (id)
 );
 );
 
 
-INSERT INTO "World" (id, randomNumber)
+INSERT INTO "World" (id, "randomNumber")
 SELECT x.id, random() * 10000 + 1 FROM generate_series(1,10000) as x(id);
 SELECT x.id, random() * 10000 + 1 FROM generate_series(1,10000) as x(id);
 
 
-DROP TABLE IF EXISTS Fortune;
+DROP TABLE IF EXISTS "Fortune";
 CREATE TABLE  "Fortune" (
 CREATE TABLE  "Fortune" (
   id integer NOT NULL,
   id integer NOT NULL,
   message varchar(2048) NOT NULL,
   message varchar(2048) NOT NULL,
   PRIMARY KEY  (id)
   PRIMARY KEY  (id)
 );
 );
 
 
-INSERT INTO fortune (id, message) VALUES (1, 'fortune: No such file or directory');
-INSERT INTO fortune (id, message) VALUES (2, 'A computer scientist is someone who fixes things that aren''t broken.');
-INSERT INTO fortune (id, message) VALUES (3, 'After enough decimal places, nobody gives a damn.');
-INSERT INTO fortune (id, message) VALUES (4, 'A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1');
-INSERT INTO fortune (id, message) VALUES (5, 'A computer program does what you tell it to do, not what you want it to do.');
-INSERT INTO fortune (id, message) VALUES (6, 'Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen');
-INSERT INTO fortune (id, message) VALUES (7, 'Any program that runs right is obsolete.');
-INSERT INTO fortune (id, message) VALUES (8, 'A list is only as strong as its weakest link. — Donald Knuth');
-INSERT INTO fortune (id, message) VALUES (9, 'Feature: A bug with seniority.');
-INSERT INTO fortune (id, message) VALUES (10, 'Computers make very fast, very accurate mistakes.');
-INSERT INTO fortune (id, message) VALUES (11, '<script>alert("This should not be displayed in a browser alert box.");</script>');
-INSERT INTO fortune (id, message) VALUES (12, 'フレームワークのベンチマーク');
+INSERT INTO "Fortune" (id, message) VALUES (1, 'fortune: No such file or directory');
+INSERT INTO "Fortune" (id, message) VALUES (2, 'A computer scientist is someone who fixes things that aren''t broken.');
+INSERT INTO "Fortune" (id, message) VALUES (3, 'After enough decimal places, nobody gives a damn.');
+INSERT INTO "Fortune" (id, message) VALUES (4, 'A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1');
+INSERT INTO "Fortune" (id, message) VALUES (5, 'A computer program does what you tell it to do, not what you want it to do.');
+INSERT INTO "Fortune" (id, message) VALUES (6, 'Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen');
+INSERT INTO "Fortune" (id, message) VALUES (7, 'Any program that runs right is obsolete.');
+INSERT INTO "Fortune" (id, message) VALUES (8, 'A list is only as strong as its weakest link. — Donald Knuth');
+INSERT INTO "Fortune" (id, message) VALUES (9, 'Feature: A bug with seniority.');
+INSERT INTO "Fortune" (id, message) VALUES (10, 'Computers make very fast, very accurate mistakes.');
+INSERT INTO "Fortune" (id, message) VALUES (11, '<script>alert("This should not be displayed in a browser alert box.");</script>');
+INSERT INTO "Fortune" (id, message) VALUES (12, 'フレームワークのベンチマーク');

+ 1 - 1
pyramid/README.md

@@ -1,7 +1,7 @@
 # Pyramid benchmark test
 # Pyramid benchmark test
 
 
 [Pyramid](http://www.pylonsproject.org/) is a flexible Python 2/3 framework.
 [Pyramid](http://www.pylonsproject.org/) is a flexible Python 2/3 framework.
-It uses [SQLAlchemy](http://www.sqlalchemy.org/) as its ORM, the default
+This test uses [SQLAlchemy](http://www.sqlalchemy.org/) as its ORM, the default
 [Chameleon](http://www.pylonsproject.org/) for its templating, and
 [Chameleon](http://www.pylonsproject.org/) for its templating, and
 [Gunicorn](https://github.com/benoitc/gunicorn) for the application server.
 [Gunicorn](https://github.com/benoitc/gunicorn) for the application server.
 
 

+ 5 - 29
pyramid/create_database.py

@@ -1,37 +1,13 @@
-from random import randint
-from sqlalchemy.orm import sessionmaker
-from sqlalchemy import create_engine
-from frameworkbenchmarks.models import pg, DBSession, metadata, World, Fortune
+import codecs
+from frameworkbenchmarks.models import DBSession
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     """
     """
     Initialize database
     Initialize database
     """
     """
-    World.__table__.drop(pg, checkfirst=True)
-    Fortune.__table__.drop(pg, checkfirst=True)
-    DBSession.commit()
-    World.__table__.create(pg)
-    Fortune.__table__.create(pg)
-    DBSession.commit()
-    DBSession.execute(
-        World.__table__.insert([(num, randint(1, 10001)) for num in range(1, 10001)])
-    )
-    DBSession.execute(
-        Fortune.__table__.insert([
-            ("1", "fortune: No such file or directory"),
-            ("2", "A computer scientist is someone who fixes things that aren't broken."),
-            ("3", "After enough decimal places, nobody gives a damn."),
-            ("4", "A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1"),
-            ("5", "A computer program does what you tell it to do, not what you want it to do."),
-            ("6", "Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen"),
-            ("7", "Any program that runs right is obsolete."),
-            ("8", "A list is only as strong as its weakest link. — Donald Knuth"),
-            ("9", "Feature: A bug with seniority."),
-            ("10", "Computers make very fast, very accurate mistakes."),
-            ("11", """<script>alert("This should not be displayed in a browser alert box.");</script>"""),
-            ("12", "フレームワークのベンチマーク"),
-        ])
-    )
+    with codecs.open('../config/create-postgres.sql', 'r', encoding='utf-8') as fp:
+        sql = fp.read()
+    DBSession.execute(sql)
     DBSession.commit()
     DBSession.commit()
 
 
 
 

+ 4 - 4
pyramid/frameworkbenchmarks/models.py

@@ -48,20 +48,20 @@ class SQLAlchemyEncoder(json.JSONEncoder):
 
 
 
 
 class World(DatabaseBase):
 class World(DatabaseBase):
-    __tablename__ = 'world'
+    __tablename__ = 'World'
 
 
     id = Column('id', Integer, primary_key=True)
     id = Column('id', Integer, primary_key=True)
-    randomNumber = Column('randomNumber', Integer)
+    randomNumber = Column('randomNumber', Integer, nullable=False, server_default='0')
 
 
     def __json__(self):
     def __json__(self):
         return {'id': self.id, 'randomNumber': self.randomNumber}
         return {'id': self.id, 'randomNumber': self.randomNumber}
 
 
 
 
 class Fortune(DatabaseBase):
 class Fortune(DatabaseBase):
-    __tablename__ = 'fortune'
+    __tablename__ = 'Fortune'
 
 
     id = Column('id', Integer, primary_key=True)
     id = Column('id', Integer, primary_key=True)
-    message = Column('message', String)
+    message = Column('message', String, nullable=False)
 
 
     def __json__(self):
     def __json__(self):
         return {'id': self.id, 'message': self.message}
         return {'id': self.id, 'message': self.message}

+ 2 - 8
pyramid/frameworkbenchmarks/tests.py

@@ -15,11 +15,6 @@ class FunctionalTests(unittest.TestCase):
     def _get(self, url, content_type='application/json'):
     def _get(self, url, content_type='application/json'):
         res = self.testapp.get(url, status=200)
         res = self.testapp.get(url, status=200)
         self.assertTrue('Content-Length' in res.headers)
         self.assertTrue('Content-Length' in res.headers)
-        # apparently these are all set by waitress, and so not
-        # available for testing here...
-        # self.assertTrue('Server' in res.headers)
-        # self.assertTrue('Date' in res.headers)
-        # self.assertTrue(content_type in res.headers['Content-Type'])
         return res
         return res
 
 
     def _str_compat(self, obj):
     def _str_compat(self, obj):
@@ -27,7 +22,6 @@ class FunctionalTests(unittest.TestCase):
             return obj.decode('utf-8')
             return obj.decode('utf-8')
         return obj
         return obj
 
 
-
     def _test_obj(self, obj):
     def _test_obj(self, obj):
         self.assertTrue('id' in obj)
         self.assertTrue('id' in obj)
         self.assertTrue('randomNumber' in obj)
         self.assertTrue('randomNumber' in obj)
@@ -126,7 +120,7 @@ fortunes = """
     </tr>
     </tr>
     <tr>
     <tr>
         <td>8</td>
         <td>8</td>
-        <td>A list is only as strong as its weakest link. — Donald Knuth</td>
+        <td>A list is only as strong as its weakest link.  Donald Knuth</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>0</td>
         <td>0</td>
@@ -146,7 +140,7 @@ fortunes = """
     </tr>
     </tr>
     <tr>
     <tr>
         <td>6</td>
         <td>6</td>
-        <td>Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen</td>
+        <td>Emacs is a nice operating system, but I prefer UNIX.  Tom Christaensen</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>9</td>
         <td>9</td>