Ejemplo n.º 1
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()
Ejemplo 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()
Ejemplo n.º 3
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)
Ejemplo 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)
Ejemplo 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
 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')
 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')
Ejemplo n.º 8
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()
Ejemplo n.º 9
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)
Ejemplo n.º 10
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})
Ejemplo n.º 11
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
 def create_app(self, *models):
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(models)
     return app.test_client()
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
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()