當前位置: 首頁>>代碼示例>>Python>>正文


Python PersonModel.mock方法代碼示例

本文整理匯總了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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:11,代碼來源:filter_tests.py

示例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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:11,代碼來源:filter_tests.py

示例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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:11,代碼來源:filter_tests.py

示例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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:11,代碼來源:filter_tests.py

示例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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:11,代碼來源:filter_tests.py

示例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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:11,代碼來源:filter_tests.py

示例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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:11,代碼來源:filter_tests.py

示例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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:12,代碼來源:filter_tests.py

示例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')
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:12,代碼來源:sort_tests.py

示例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)
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:13,代碼來源:filter_tests.py

示例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')
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:13,代碼來源:page_tests.py

示例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')
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:13,代碼來源:page_tests.py

示例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)
開發者ID:Raistlfiren,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:13,代碼來源:include_tests.py

示例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')
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:14,代碼來源:sort_tests.py

示例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]')
開發者ID:caxiam,項目名稱:sqlalchemy-jsonapi-collections,代碼行數:14,代碼來源:filter_tests.py


注:本文中的tests.mock.PersonModel.mock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。