コード例 #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()
コード例 #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)
コード例 #5
0
 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')
コード例 #6
0
 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
ファイル: test_get.py プロジェクト: kcaylor/eve-mongoengine
 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)
コード例 #11
0
 def create_app(self, *models):
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(models)
     return app.test_client()