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()
예제 #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()
예제 #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)
예제 #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)
 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')
예제 #7
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()
예제 #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()
예제 #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)
예제 #10
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)
 def create_app(self, *models):
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(models)
     return app.test_client()