Beispiel #1
0
    def test_custom_datalayer(self):
        class MyTestDataLayer(DataLayer):
            def init_app(self, app):
                pass

        self.app = Eve(data=MyTestDataLayer, settings=self.settings_file)
        self.assertEqual(type(self.app.data), MyTestDataLayer)
Beispiel #2
0
 def test_mongodb_settings(self):
     # Create custom app with mongodb settings.
     settings = {
         'DOMAIN': {
             'contacts': {}
         },
         'MONGO_OPTIONS': {
             'connect': False
         }
     }
     app = Eve(settings=settings)
     # Check if settings are set.
     self.assertEqual(app.config['MONGO_OPTIONS']['connect'],
                      app.config['MONGO_CONNECT'])
     # Prepare a specific schema with mongo specific settings.
     settings = {
         'schema': {
             'name': {
                 'type': 'string'
             },
         },
         'MONGO_OPTIONS': {
             'connect': False
         }
     }
     self.app.register_resource('mongodb_settings', settings)
     # check that settings are set.
     resource_settings = self.app.config['DOMAIN']['mongodb_settings']
     self.assertEqual(resource_settings['MONGO_OPTIONS'],
                      settings['MONGO_OPTIONS'])
     # check that settings are set.
     self.assertEqual(resource_settings['MONGO_OPTIONS']['connect'],
                      settings['MONGO_OPTIONS']['connect'])
Beispiel #3
0
 def test_mongodb_settings(self):
     # Create custom app with mongodb settings.
     settings = {
         "DOMAIN": {
             "contacts": {}
         },
         "MONGO_OPTIONS": {
             "connect": False
         }
     }
     app = Eve(settings=settings)
     # Check if settings are set.
     self.assertEqual(app.config["MONGO_OPTIONS"]["connect"],
                      app.config["MONGO_CONNECT"])
     # Prepare a specific schema with mongo specific settings.
     settings = {
         "schema": {
             "name": {
                 "type": "string"
             }
         },
         "MONGO_OPTIONS": {
             "connect": False
         },
     }
     self.app.register_resource("mongodb_settings", settings)
     # check that settings are set.
     resource_settings = self.app.config["DOMAIN"]["mongodb_settings"]
     self.assertEqual(resource_settings["MONGO_OPTIONS"],
                      settings["MONGO_OPTIONS"])
     # check that settings are set.
     self.assertEqual(
         resource_settings["MONGO_OPTIONS"]["connect"],
         settings["MONGO_OPTIONS"]["connect"],
     )
 def test_allow_unknown_with_soft_delete(self):
     my_settings = {
         'ALLOW_UNKNOWN': True,
         'SOFT_DELETE': True,
         'DOMAIN': {'contacts': {}}
     }
     try:
         self.app = Eve(settings=my_settings)
     except TypeError:
         self.fail("ALLOW_UNKNOWN and SOFT_DELETE enabled should not cause "
                   "a crash.")
Beispiel #5
0
 def test_allow_unknown_with_soft_delete(self):
     my_settings = {
         "ALLOW_UNKNOWN": True,
         "SOFT_DELETE": True,
         "DOMAIN": {"contacts": {}},
     }
     try:
         self.app = Eve(settings=my_settings)
     except TypeError:
         self.fail(
             "ALLOW_UNKNOWN and SOFT_DELETE enabled should not cause " "a crash."
         )
 def test_custom_import_name(self):
     self.app = Eve('unittest', settings=self.settings_file)
     self.assertEqual(self.app.import_name, 'unittest')
 def test_custom_validator(self):
     class MyTestValidator(Validator):
         pass
     self.app = Eve(validator=MyTestValidator,
                    settings=self.settings_file)
     self.assertEqual(self.app.validator, MyTestValidator)
Beispiel #8
0
 def test_existing_env_config(self):
     env = os.environ
     os.environ = {'EVE_SETTINGS': 'test_settings_env.py'}
     self.app = Eve()
     self.assertTrue('env_domain' in self.app.config['DOMAIN'])
     os.environ = env
Beispiel #9
0
 def test_custom_import_name(self):
     self.app = Eve('custom_import_name',
                    settings='eve/tests/test_settings.py')
     self.assertEqual(self.app.import_name, 'custom_import_name')
Beispiel #10
0
 def test_custom_kwargs(self):
     self.app = Eve("unittest", static_folder="static/", settings=self.settings_file)
     self.assertTrue(self.app.static_folder.endswith("static"))
Beispiel #11
0
 def test_existing_env_config(self):
     env = os.environ
     os.environ = {"EVE_SETTINGS": "test_settings_env.py"}
     self.app = Eve()
     self.assertTrue("env_domain" in self.app.config["DOMAIN"])
     os.environ = env
Beispiel #12
0
 def test_custom_kwargs(self):
     self.app = Eve("unittest",
                    static_folder="/",
                    settings=self.settings_file)
     self.assertEqual(self.app.static_folder, "/")
Beispiel #13
0
 def test_custom_kwargs(self):
     self.app = Eve('custom_import_name',
                    static_folder='/',
                    settings='eve/tests/test_settings.py')
     self.assertEqual(self.app.static_folder, '/')
 def test_custom_kwargs(self):
     self.app = Eve('unittest', static_folder='/',
                    settings=self.settings_file)
     self.assertEqual(self.app.static_folder, '/')
Beispiel #15
0
 def test_settings_as_dict(self):
     my_settings = {"API_VERSION": "override!", "DOMAIN": {"contacts": {}}}
     self.app = Eve(settings=my_settings)
     self.assertEqual(self.app.config["API_VERSION"], "override!")
     # did not reset other defaults
     self.assertEqual(self.app.config["MONGO_WRITE_CONCERN"], {"w": 1})
 def test_settings_as_dict(self):
     my_settings = {'API_VERSION': 'override!', 'DOMAIN': {'contacts': {}}}
     self.app = Eve(settings=my_settings)
     self.assertEqual(self.app.config['API_VERSION'], 'override!')
     # did not reset other defaults
     self.assertEqual(self.app.config['MONGO_WRITE_CONCERN'], {'w': 1})
Beispiel #17
0
#!/usr/local/bin/python2.7
# -*-coding:UTF-8-sig -*-
from eve.flaskapp import Eve
from eve_sqlalchemy import SQL

from base import Base

app = Eve(auth=None, settings='config/eve-config.py', data=SQL)
db = app.data.driver
Base.metadata.bind = db.engine
db.Model = Base
db.create_all()

if __name__ == '__main__':
    app.run(host="0.0.0.0",port=5000,debug=True)