Browse Source

Add an app file to use in production

Gu1 11 years ago
parent
commit
ab6fece2f9
2 changed files with 38 additions and 1 deletions
  1. 34 0
      app_prod.py
  2. 4 1
      test_ffdnispdb.py

+ 34 - 0
app_prod.py

@@ -0,0 +1,34 @@
+
+import os; os.environ.setdefault('FFDNISPDB_SETTINGS', '../settings_prod.py')
+from ffdnispdb import create_app
+
+
+app=create_app()
+if not app.debug:
+    import logging
+    from logging.handlers import SMTPHandler
+    from logging import FileHandler
+    mail_handler = SMTPHandler('127.0.0.1',
+                               'server-error@db.ffdn.org',
+                               app.config['ADMINS'], 'FFDN DB Error')
+    mail_handler.setLevel(logging.ERROR)
+    mail_handler.setFormatter(logging.Formatter('''
+Message type:       %(levelname)s
+Location:           %(pathname)s:%(lineno)d
+Module:             %(module)s
+Function:           %(funcName)s
+Time:               %(asctime)s
+
+Message:
+
+%(message)s
+    '''))
+    app.logger.addHandler(mail_handler)
+
+    file_handler = FileHandler('application.log')
+    file_handler.setLevel(logging.WARNING)
+    file_handler.setFormatter(logging.Formatter(
+        '%(asctime)s %(levelname)s: %(message)s '
+        '[in %(pathname)s:%(lineno)d]'
+    ))
+    app.logger.addHandler(file_handler)

+ 4 - 1
test_ffdnispdb.py

@@ -1,6 +1,6 @@
 
 from ffdnispdb import create_app, db, utils
-from ffdnispdb.models import ISP
+from ffdnispdb.models import ISP, CoveredArea
 from flask import Flask
 from flask.ext.sqlalchemy import SQLAlchemy
 import unittest
@@ -116,6 +116,9 @@ class TestForm(TestCase):
         })
         self.assertNotEqual(resp.location, None)
         self.assertEqual(ISP.query.filter_by(name='Test').count(), 1)
+        self.assertEqual(
+            CoveredArea.query.filter_by(name='Somewhere over the rainbow').count(), 1
+        )
 
 
 class TestAPI(TestCase):