当前位置: 首页>>代码示例>>Python>>正文


Python mock.PersonModel类代码示例

本文整理汇总了Python中tests.mock.PersonModel的典型用法代码示例。如果您正苦于以下问题:Python PersonModel类的具体用法?Python PersonModel怎么用?Python PersonModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PersonModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_filter_datetime_field

    def test_filter_datetime_field(self):
        """Test filtering by a datetime field."""
        PersonModel.mock()

        parameters = {'filter[created_at]': date.today().strftime('%Y-%m-%d')}
        query = Resource(self.model, parameters).filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:9,代码来源:filter_tests.py

示例2: test_filter_computed_field

    def test_filter_computed_field(self):
        """Test filtering by a computed field."""
        PersonModel.mock(is_employed=True)

        parameters = {'filter[employed_integer]': '1'}
        query = Resource(self.model, parameters).filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:9,代码来源:filter_tests.py

示例3: test_filter_decimal_field

    def test_filter_decimal_field(self):
        """Test filtering by a decimal field."""
        PersonModel.mock(rate='12.51')

        parameters = {'filter[rate]': '12.51'}
        query = Resource(self.model, parameters).filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:9,代码来源:filter_tests.py

示例4: test_filter_multiple_string_field

    def test_filter_multiple_string_field(self):
        """Test filtering by multiple string fields."""
        PersonModel.mock(name='A PRODUCT Wildcard')

        parameters = {'filter[name]': 'prod,test,card'}
        query = Resource(self.model, parameters).filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:9,代码来源:filter_tests.py

示例5: test_filter_enum_field

    def test_filter_enum_field(self):
        """Test filtering by an enum field."""
        PersonModel.mock(gender='male')

        parameters = {'filter[gender]': 'male'}
        query = Resource(self.model, parameters).filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:9,代码来源:filter_tests.py

示例6: test_filter_boolean_field

    def test_filter_boolean_field(self):
        """Test filtering by a boolean field."""
        PersonModel.mock(is_employed=True)

        parameters = {'filter[is_employed]': '1'}
        query = Resource(self.model, parameters).filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:9,代码来源:filter_tests.py

示例7: test_filter_integer_field

    def test_filter_integer_field(self):
        """Test filtering by an integer field."""
        PersonModel.mock(age=80)

        parameters = {'filter[age]': '80'}
        query = Resource(self.model, parameters).filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:9,代码来源:filter_tests.py

示例8: test_filter_many_to_many_relationship

    def test_filter_many_to_many_relationship(self):
        """Test filtering by a many-to-many relationship field."""
        company = CompanyModel.mock(name="company")
        PersonModel.mock(companies=[company])

        parameters = {'filter[companies.name]': 'COMPANY'}
        query = Resource(self.model, parameters).filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:10,代码来源:filter_tests.py

示例9: test_sort_field_descending

    def test_sort_field_descending(self):
        """Test sorting a field in descending order."""
        PersonModel.mock(name="A")
        PersonModel.mock(name="B")

        parameters = {'sort': '-name'}
        query = Resource(self.model, parameters).sort_query(self.query)

        result = query.all()
        self.assertEqual(result[0].name, 'B')
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:10,代码来源:sort_tests.py

示例10: test_filter_string_field

    def test_filter_string_field(self):
        """Test filtering by a string field."""
        PersonModel.mock(name='A PRODUCT Wildcard')

        parameters = {'filter[name]': 'prod'}
        query = Resource(
            self.model, parameters, MarshmallowDriver, PersonSchema).\
            filter_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:11,代码来源:filter_tests.py

示例11: test_offset

    def test_offset(self):
        """Test offsetting a page by the offset parameter."""
        PersonModel.mock(name='First')
        PersonModel.mock(name='Second')

        parameters = {'offset': '1'}
        query = Resource(self.model, parameters).paginate_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
        self.assertTrue(result[0].name == 'Second')
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:11,代码来源:page_tests.py

示例12: test_page_size

    def test_page_size(self):
        """Test limiting a page by the page[size] parameter."""
        PersonModel.mock(name='First')
        PersonModel.mock(name='Second')

        parameters = {'page[size]': '1'}
        query = Resource(self.model, parameters).paginate_query(self.query)

        result = query.all()
        self.assertEqual(len(result), 1)
        self.assertTrue(result[0].name == 'First')
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:11,代码来源:page_tests.py

示例13: test_include_foreign_key

    def test_include_foreign_key(self):
        """Test including a foreign key relationship field."""
        PersonModel.mock()
        model = EmployeeModel.mock(person_id=1)

        include = ['person']
        iv_objects, errors = IncludeValue.generate(EmployeeSchema, include)
        data = IncludeValue.include(iv_objects, model)

        self.assertTrue(errors == [])
        self.assertTrue(len(data) == 1)
开发者ID:Raistlfiren,项目名称:sqlalchemy-jsonapi-collections,代码行数:11,代码来源:include_tests.py

示例14: test_sort_field_ascending

    def test_sort_field_ascending(self):
        """Test sorting a field in ascending order."""
        PersonModel.mock(name="A")
        PersonModel.mock(name="B")

        parameters = {'sort': 'name'}
        query = Resource(
            self.model, parameters, marshmallow.MarshmallowDriver, self.view).\
            sort_query(self.query)

        result = query.all()
        self.assertEqual(result[0].name, 'A')
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:12,代码来源:sort_tests.py

示例15: test_filter_decimal_field_invalid_value

    def test_filter_decimal_field_invalid_value(self):
        """Test filtering by an invalid decimal value."""
        PersonModel.mock(rate='12.51')

        try:
            parameters = {'filter[rate]': 'a'}
            Resource(self.model, parameters).filter_query(self.query)
        except JSONAPIError as exc:
            message = exc.message
            self.assertIn('detail', message['errors'][0])
            self.assertTrue(
                message['errors'][0]['source']['parameter'] == 'filter[rate]')
开发者ID:caxiam,项目名称:sqlalchemy-jsonapi-collections,代码行数:12,代码来源:filter_tests.py


注:本文中的tests.mock.PersonModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。