本文整理汇总了Python中tests.mock.PersonModel.mock方法的典型用法代码示例。如果您正苦于以下问题:Python PersonModel.mock方法的具体用法?Python PersonModel.mock怎么用?Python PersonModel.mock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.mock.PersonModel
的用法示例。
在下文中一共展示了PersonModel.mock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_datetime_field
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例2: test_filter_computed_field
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例3: test_filter_decimal_field
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例4: test_filter_multiple_string_field
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例5: test_filter_enum_field
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例6: test_filter_boolean_field
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例7: test_filter_integer_field
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例8: test_filter_many_to_many_relationship
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例9: test_sort_field_descending
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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')
示例10: test_filter_string_field
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例11: test_offset
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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')
示例12: test_page_size
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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')
示例13: test_include_foreign_key
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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)
示例14: test_sort_field_ascending
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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')
示例15: test_filter_decimal_field_invalid_value
# 需要导入模块: from tests.mock import PersonModel [as 别名]
# 或者: from tests.mock.PersonModel import mock [as 别名]
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]')