예제 #1
0
 def test_get_columns(self):
     """Test for getting the names of columns as strings."""
     columns = get_columns(self.Person)
     assert sorted(columns.keys()) == sorted([
         'age', 'birth_date', 'computers', 'id', 'is_above_21', 'is_minor',
         'name', 'other'
     ])
예제 #2
0
 def test_get_columns(self):
     """Test for getting the names of columns as strings."""
     columns = get_columns(self.Person)
     self.assertEqual(sorted(columns.keys()), sorted(['age', 'birth_date',
                                                      'computers', 'id',
                                                      'is_minor', 'name',
                                                      'other']))
    def test_exclude_columns(self):
        """Tests that the ``exclude_columns`` argument specifies which columns
        to exclude in the JSON representation of instances of the model.

        """
        all_columns = get_columns(self.Person)
        # allow all
        self.manager.create_api(self.Person,
                                exclude_columns=None,
                                url_prefix='/all')
        self.manager.create_api(self.Person,
                                exclude_columns=(),
                                url_prefix='/all2')
        # allow some
        exclude = ('other', 'birth_date', 'computers')
        self.manager.create_api(self.Person,
                                exclude_columns=exclude,
                                url_prefix='/some')
        # allow none
        self.manager.create_api(self.Person,
                                exclude_columns=all_columns,
                                url_prefix='/none')

        # create a test person
        self.manager.create_api(self.Person,
                                methods=['POST'],
                                url_prefix='/add')
        d = dict(name=u'Test',
                 age=10,
                 other=20,
                 birth_date=datetime.date(1999, 12, 31).isoformat())
        response = self.app.post('/add/person', data=dumps(d))
        assert response.status_code == 201
        personid = loads(response.data)['id']

        # get all
        response = self.app.get('/all/person/{0}'.format(personid))
        for column in 'name', 'age', 'other', 'birth_date', 'computers':
            assert column in loads(response.data)
        response = self.app.get('/all2/person/{0}'.format(personid))
        for column in 'name', 'age', 'other', 'birth_date', 'computers':
            assert column in loads(response.data)

        # get some
        response = self.app.get('/some/person/{0}'.format(personid))
        for column in 'name', 'age':
            assert column in loads(response.data)
        for column in 'other', 'birth_date', 'computers':
            assert column not in loads(response.data)

        # get none
        response = self.app.get('/none/person/{0}'.format(personid))
        for column in 'name', 'age', 'other', 'birth_date', 'computers':
            assert column not in loads(response.data)
예제 #4
0
    def test_exclude_columns(self):
        """Tests that the ``exclude_columns`` argument specifies which columns
        to exclude in the JSON representation of instances of the model.

        """
        all_columns = get_columns(self.Person)
        # allow all
        self.manager.create_api(self.Person, exclude_columns=None,
                                url_prefix='/all')
        self.manager.create_api(self.Person, exclude_columns=(),
                                url_prefix='/all2')
        # allow some
        exclude = ('other', 'birth_date', 'computers')
        self.manager.create_api(self.Person, exclude_columns=exclude,
                                url_prefix='/some')
        # allow none
        self.manager.create_api(self.Person, exclude_columns=all_columns,
                                url_prefix='/none')

        # create a test person
        self.manager.create_api(self.Person, methods=['POST'],
                                url_prefix='/add')
        d = dict(name=u'Test', age=10, other=20,
                 birth_date=datetime.date(1999, 12, 31).isoformat())
        response = self.app.post('/add/person', data=dumps(d))
        assert response.status_code == 201
        personid = loads(response.data)['id']

        # get all
        response = self.app.get('/all/person/%s' % personid)
        for column in 'name', 'age', 'other', 'birth_date', 'computers':
            assert column in loads(response.data)
        response = self.app.get('/all2/person/%s' % personid)
        for column in 'name', 'age', 'other', 'birth_date', 'computers':
            assert column in loads(response.data)

        # get some
        response = self.app.get('/some/person/%s' % personid)
        for column in 'name', 'age':
            assert column in loads(response.data)
        for column in 'other', 'birth_date', 'computers':
            assert column not in loads(response.data)

        # get none
        response = self.app.get('/none/person/%s' % personid)
        for column in 'name', 'age', 'other', 'birth_date', 'computers':
            assert column not in loads(response.data)
예제 #5
0
    def test_exclude_columns(self):
        """Tests that the ``exclude_columns`` argument specifies which columns
        to exclude in the JSON representation of instances of the model.

        """
        all_columns = get_columns(self.Person)
        # allow all
        self.manager.create_api(self.Person, exclude_columns=None, url_prefix="/all")
        self.manager.create_api(self.Person, exclude_columns=(), url_prefix="/all2")
        # allow some
        exclude = ("other", "birth_date", "computers")
        self.manager.create_api(self.Person, exclude_columns=exclude, url_prefix="/some")
        # allow none
        self.manager.create_api(self.Person, exclude_columns=all_columns, url_prefix="/none")

        # create a test person
        self.manager.create_api(self.Person, methods=["POST"], url_prefix="/add")
        d = dict(name=u"Test", age=10, other=20, birth_date=datetime.date(1999, 12, 31).isoformat())
        response = self.app.post("/add/person", data=dumps(d))
        assert response.status_code == 201
        personid = loads(response.data)["id"]

        # get all
        response = self.app.get("/all/person/{0}".format(personid))
        for column in "name", "age", "other", "birth_date", "computers":
            assert column in loads(response.data)
        response = self.app.get("/all2/person/{0}".format(personid))
        for column in "name", "age", "other", "birth_date", "computers":
            assert column in loads(response.data)

        # get some
        response = self.app.get("/some/person/{0}".format(personid))
        for column in "name", "age":
            assert column in loads(response.data)
        for column in "other", "birth_date", "computers":
            assert column not in loads(response.data)

        # get none
        response = self.app.get("/none/person/{0}".format(personid))
        for column in "name", "age", "other", "birth_date", "computers":
            assert column not in loads(response.data)