Exemplo n.º 1
0
    def test_uppercase_resource_names(self):
        # Sanity Check: the Default Setting is Uppercase Off
        response = self.client.get('/SimpleDoc')
        self.assertEqual(response.status_code, 404)

        # Create a new Eve App with settings to allow Uppercase Resource Names
        # in the URI.
        app = Eve(settings=SETTINGS)
        app.debug = True
        ext = EveMongoengine(app)
        ext.add_model(SimpleDoc, lowercase=False)
        client = app.test_client()
        d = SimpleDoc(a='Tom', b=223).save()

        # Sanity Check: Lowercase is Disabled
        response = client.get('/simpledoc/')
        self.assertEqual(response.status_code, 404)

        # Use the Uppercase Resource Name
        response = client.get('/SimpleDoc/')
        self.assertEqual(response.status_code, 200)
        json_data = response.get_json()
        expected_url = json_data[config.LINKS]['self']['href']
        if ':' in expected_url:
            expected_url = '/' + '/'.join( expected_url.split('/')[1:] )
        self.assertTrue('SimpleDoc' in expected_url)
Exemplo n.º 2
0
 def setUpClass(cls):
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(TwoFaceDoc)
     cls.app = app
     cls.client = app.test_client()
 def setUpClass(cls):
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(TwoFaceDoc)
     cls.app = app
     cls.client = app.test_client()
Exemplo n.º 4
0
    def test_uppercase_resource_names(self):
        # Sanity Check: the Default Setting is Uppercase Off
        response = self.client.get('/SimpleDoc')
        self.assertEqual(response.status_code, 404)

        # Create a new Eve App with settings to allow Uppercase Resource Names
        # in the URI.
        app = Eve(settings=SETTINGS)
        app.debug = True
        ext = EveMongoengine(app)
        ext.add_model(SimpleDoc, lowercase=False)
        client = app.test_client()
        d = SimpleDoc(a='Tom', b=223).save()

        # Sanity Check: Lowercase is Disabled
        response = client.get('/simpledoc/')
        self.assertEqual(response.status_code, 404)

        # Use the Uppercase Resource Name
        response = client.get('/SimpleDoc/')
        self.assertEqual(response.status_code, 200)
        json_data = response.get_json()
        expected_url = json_data[config.LINKS]['self']['href']
        if ':' in expected_url:
            expected_url = '/' + '/'.join(expected_url.split('/')[1:])
        self.assertTrue('SimpleDoc' in expected_url)
Exemplo n.º 5
0
 def setUpClass(cls):
     SETTINGS['DOMAIN'] = {'eve-mongoengine':{}}
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model([SimpleDoc, ComplexDoc, LimitedDoc, FieldsDoc,
                    NonStructuredDoc, Inherited, HawkeyDoc])
     cls.ext = ext
     cls.client = app.test_client()
     cls.app = app
Exemplo n.º 6
0
 def test_init_app(self):
     ext = EveMongoengine()
     ext.add_model(Dummy)
     self.assertEqual(ext.models, {})
     app = Eve(settings={
         'MONGO_HOST': 'localhost',
         'MONGO_PORT': 27017,
         'MONGO_DBNAME': 'eve_mongoengine_test',
         'DOMAIN': {}
     })
     ext.init_app(app)
     self.assertEqual(ext.models, {'dummy': Dummy})
Exemplo n.º 7
0
 def setUpClass(cls):
     SETTINGS['DOMAIN'] = {'eve-mongoengine': {}}
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model([
         SimpleDoc, ComplexDoc, LimitedDoc, FieldsDoc, NonStructuredDoc,
         Inherited, HawkeyDoc
     ])
     cls.ext = ext
     cls.client = app.test_client()
     cls.app = app
 def test_nondefault_date_created_field(self):
     # redefine to get entirely new class
     class SimpleDoc(Document):
         a = StringField()
         b = IntField()
     sett = SETTINGS.copy()
     sett['DATE_CREATED'] = 'created_at'
     app = Eve(settings=sett)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(SimpleDoc)
     app = app.test_client()
     self._test_default_values(app, SimpleDoc, created_name='created_at')
Exemplo n.º 9
0
 def test_init_app(self):
     ext = EveMongoengine()
     ext.add_model(Dummy)
     self.assertEqual(ext.models, {})
     app = Eve(
         settings={
             'MONGO_HOST': 'localhost',
             'MONGO_PORT': 27017,
             'MONGO_DBNAME': 'eve_mongoengine_test',
             'DOMAIN': {}
         })
     ext.init_app(app)
     self.assertEqual(ext.models, {'dummy': Dummy})
 def test_nondefault_last_updated_field(self):
     # redefine to get entirely new class
     class SimpleDoc(Document):
         a = StringField()
         b = IntField()
     sett = SETTINGS.copy()
     sett['LAST_UPDATED'] = 'last_change'
     app = Eve(settings=sett)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(SimpleDoc)
     client = app.test_client()
     with app.app_context(): # to get current app's config
         self._test_default_values(client, SimpleDoc, updated_name='last_change')
Exemplo n.º 11
0
 def test_datasource_projection(self):
     SETTINGS['DOMAIN'] = {'eve-mongoengine': {}}
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(SimpleDoc, datasource={'projection': {'b': 0}})
     client = app.test_client()
     d = SimpleDoc(a='Tom', b=223).save()
     response = client.get('/simpledoc/%s' % d.id)
     try:
         self.assertNotIn('b', response.get_json().keys())
         # here it should return the field, but sadly, does not
         #response = client.get('/simpledoc/%s?projection={"b":1}' % d.id)
         #self.assertIn('b', response.get_json().keys())
     finally:
         d.delete()
Exemplo n.º 12
0
 def test_datasource_projection(self):
     SETTINGS['DOMAIN'] = {'eve-mongoengine':{}}
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(SimpleDoc, datasource={'projection': {'b': 0}})
     client = app.test_client()
     d = SimpleDoc(a='Tom', b=223).save()
     response = client.get('/simpledoc/%s' % d.id)
     try:
         self.assertNotIn('b', response.get_json().keys())
         # here it should return the field, but sadly, does not
         #response = client.get('/simpledoc/%s?projection={"b":1}' % d.id)
         #self.assertIn('b', response.get_json().keys())
     finally:
         d.delete()
Exemplo n.º 13
0
 def test_uppercase_resource_names(self):
     # test default lowercase
     response = self.client.get('/SimpleDoc')
     self.assertEqual(response.status_code, 404)
     # uppercase
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(SimpleDoc, lowercase=False)
     client = app.test_client()
     d = SimpleDoc(a='Tom', b=223).save()
     response = client.get('/SimpleDoc/')
     self.assertEqual(response.status_code, 200)
     json_data = response.get_json()
     expected_url = json_data[config.LINKS]['self']['href']
     if ':' in expected_url:
         expected_url = '/' + '/'.join(expected_url.split('/')[1:])
     self.assertEqual(expected_url, '/SimpleDoc')
     # not lowercase when uppercase
     response = client.get('/simpledoc/')
     self.assertEqual(response.status_code, 404)
Exemplo n.º 14
0
 def test_uppercase_resource_names(self):
     # test default lowercase
     response = self.client.get('/SimpleDoc')
     self.assertEqual(response.status_code, 404)
     # uppercase
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(SimpleDoc, lowercase=False)
     client = app.test_client()
     d = SimpleDoc(a='Tom', b=223).save()
     response = client.get('/SimpleDoc/')
     self.assertEqual(response.status_code, 200)
     json_data = response.get_json()
     expected_url = json_data[config.LINKS]['self']['href']
     if ':' in expected_url:
         expected_url = '/' + '/'.join( expected_url.split('/')[1:] )
     self.assertEqual(expected_url, '/SimpleDoc')
     # not lowercase when uppercase
     response = client.get('/simpledoc/')
     self.assertEqual(response.status_code, 404)
Exemplo n.º 15
0
def setup_eve_mongoengine(host='localhost', port=27017):
    # app settings
    my_settings = {
        'MONGO_HOST': host,
        'MONGO_PORT': int(port),
        'MONGO_PASSWORD': None,
        'MONGO_USERNAME': None,
        'MONGO_DBNAME': 'munerator',
        'DOMAIN': {'eve-mongoengine': {}},
    }
    app = Eve(settings=my_settings)

    # setup eve mongodb database
    ext = EveMongoengine(app)

    # add models
    ext.add_model([Players, Games, Votes, Gamemaps, PlaylistItems])

    db = MongoClient(host, int(port))['munerator']

    return db
Exemplo n.º 16
0
def configure_ext(app):
    ext = EveMongoengine(app)
    admin = Admin(app)
    for model_cls in (Media, Contact, Event, Subscription, Acknowledgement):
        ext.add_model(
            model_cls,
            resource_methods=model_cls.resource_methods,
            item_methods=model_cls.item_methods)
        model_view = getattr(model_views, '%sAdmin' % model_cls.__name__)
        admin.add_view(model_view(model_cls))
    # configure redis for eve rate limit
    redis_settings = _get_ext_settings(app.settings, 'REDIS')
    redis_url = redis_settings.pop('URL')
    redis = StrictRedis.from_url(redis_url, **redis_settings)
    app.redis = redis
    # notification service
    ns = Client(app.settings['NOTIFICATION_API_URL'])
    app.extensions['notification_service'] = ns
    # docs
    Bootstrap(app)
    app.register_blueprint(eve_docs, url_prefix='/docs')
    return app
Exemplo n.º 17
0
 def setUpClass(cls):
     SETTINGS["DOMAIN"] = {"eve-mongoengine": {}}
     app = Eve(settings=SETTINGS)
     app.debug = True
     with app.app_context():
         ext = EveMongoengine(app)
         for Doc in (
                 SimpleDoc,
                 ComplexDoc,
                 LimitedDoc,
                 FieldsDoc,
                 NonStructuredDoc,
                 Inherited,
                 SensitiveInfoDoc,
         ):
             ext.add_model(
                 Doc,
                 resource_methods=["GET", "POST", "DELETE"],
                 item_methods=["GET", "PATCH", "PUT", "DELETE"],
             )
         ext.add_model(SensitiveInfoDoc, resource_name="user")
         cls.ext = ext
         cls.client = app.test_client()
         cls.app = app
Exemplo n.º 18
0
#!/usr/bin/env python
import config
from flask import request
from eve import Eve
from eve_mongoengine import EveMongoengine
from eve.auth import TokenAuth

from models import *

class ApiTokenAuth(TokenAuth):
    def authorized(self, allowed_roles, resource, method):
        token = request.headers.get(config.EVE_AUTH_HEADER_NAME)
        if User.check_api_token(token):
            return True
        else:
            return False

if __name__=='__main__':
    app = Eve(auth=ApiTokenAuth, settings=config.EVE_SETTINGS)
    ext = EveMongoengine(app)
    ext.add_model(User)
    ext.add_model(Message)
    ext.add_model(GPSDevice)
    app.debug = True
    app.run(host='0.0.0.0', port=5000)
Exemplo n.º 19
0
    'DOMAIN': {'eve-mongoengine': {}} # sadly this is needed for eve
}

import JumpScale.grid.osis

client = j.core.osis.getClientByInstance('main')
json=client.getOsisSpecModel("oss")

from generators.MongoEngineGenerator import *

gen=MongoEngineGenerator("generated/oss.py")
gen.generate(json)

# init application
app = Eve(settings=my_settings)
# init extension
ext = EveMongoengine(app)
# register model to eve

from generated.oss import *

for classs in classes:
    ext.add_model(classs)

Bootstrap(app)
app.register_blueprint(eve_docs, url_prefix='/docs')

print "visit:\nhttp://localhost:5000/docs/"

# let's roll
app.run()
Exemplo n.º 20
0

class Invoice(mongoengine.Document):
    container = mongoengine.ReferenceField(Container)
    flight = mongoengine.ReferenceField(Flight)
    consignee = mongoengine.ReferenceField(Consignee)


# default eve settings
my_settings = {
    'DOMAIN': {},
    'MONGO_HOST': 'localhost',
    'MONGO_PORT': 27017,
    'MONGO_DBNAME': 'app-transportation'
}

# init application
app = Eve(settings=my_settings)
# init extension
ext = EveMongoengine(app)
# register model to eve
ext.add_model(Port)
ext.add_model(Ship)
ext.add_model(Container)
ext.add_model(Consignee)
ext.add_model(Flight)
ext.add_model(Invoice)

# let's roll
app.run(port=2323)
Exemplo n.º 21
0
    }  # sadly this is needed for eve
}

import JumpScale.grid.osis

client = j.core.osis.getClient(user='******')
json = client.getOsisSpecModel("oss")

from generators.MongoEngineGenerator import *

gen = MongoEngineGenerator("generated/oss.py")
gen.generate(json)

# init application
app = Eve(settings=my_settings)
# init extension
ext = EveMongoengine(app)
# register model to eve

from generated.oss import *

for classs in classes:
    ext.add_model(classs)

Bootstrap(app)
app.register_blueprint(eve_docs, url_prefix='/docs')

print "visit:\nhttp://localhost:5000/docs/"

# let's roll
app.run()
 def create_app(self, *models):
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(models)
     return app.test_client()
Exemplo n.º 23
0
#!/usr/bin/env python
import config
from flask import request
from eve import Eve
from eve_mongoengine import EveMongoengine
from eve.auth import TokenAuth

from models import *


class ApiTokenAuth(TokenAuth):
    def authorized(self, allowed_roles, resource, method):
        token = request.headers.get(config.EVE_AUTH_HEADER_NAME)
        if User.check_api_token(token):
            return True
        else:
            return False


if __name__ == '__main__':
    app = Eve(auth=ApiTokenAuth, settings=config.EVE_SETTINGS)
    ext = EveMongoengine(app)
    ext.add_model(User)
    ext.add_model(Message)
    ext.add_model(GPSDevice)
    app.debug = True
    app.run(host='0.0.0.0', port=5000)
Exemplo n.º 24
0
Arquivo: api.py Projeto: nikitph/Ashrm
    # 'MONGO_HOST': 'localhost',
    #     'MONGO_PORT': 27017,
    #     'MONGO_USERNAME' : None,
    # 'MONGO_PASSWORD': None,
    'MONGO_DBNAME': 'ashrm3',
    'X_DOMAINS': '*',
    'ALLOW_OVERRIDE_HTTP_METHOD':'true',
    'JSON_SORT_KEYS	':'true',
                   'DOMAIN': {'student': {}}
}

app = Eve(settings=MONGODB_SETTINGS)
# init extension
ext = EveMongoengine(app)
# register model to eve
ext.add_model(Student)
ext.add_model(BusRoute)
ext.add_model(Transportation)
ext.add_model(Hostel)
ext.add_model(HostelRoom)
ext.add_model(User)
ext.add_model(Subject)
ext.add_model(Teacher)
ext.add_model(ClassRoom)
ext.add_model(BusStop)
ext.add_model(Driver)
ext.add_model(Conveyance)



# let's roll