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


Python serializers.DateField方法代碼示例

本文整理匯總了Python中rest_framework.serializers.DateField方法的典型用法代碼示例。如果您正苦於以下問題:Python serializers.DateField方法的具體用法?Python serializers.DateField怎麽用?Python serializers.DateField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.serializers的用法示例。


在下文中一共展示了serializers.DateField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_to_representation_list

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_representation_list():
    """
    When given a valid list, the ListOrItemField to_representation method should utilize the list to-native
    logic.
    """
    field = ListOrItemField(child=DateField(format=ISO_8601))
    data = field.to_representation([date.today()])
    assert [date.today().isoformat()] == data 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:10,代碼來源:test_listoritemfield.py

示例2: test_to_internal_value_list

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_internal_value_list():
    """
    When given a valid list, the ListOrItemField to_internal_value method should utilize the list
    from-native logic.
    """
    field = ListOrItemField(child=DateField(format=ISO_8601))
    data = field.to_internal_value([date.today().isoformat()])
    assert [date.today()] == data 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:10,代碼來源:test_listoritemfield.py

示例3: test_to_representation_item

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_representation_item():
    """
    When given a valid item, the ListOrItemField to_representation method should utilize the item to-native
    logic.
    """
    field = ListOrItemField(child=DateField(format=ISO_8601))
    data = field.to_representation(date.today())
    assert date.today().isoformat() == data 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:10,代碼來源:test_listoritemfield.py

示例4: test_to_internal_value_item

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_internal_value_item():
    """
    When given a valid item, the ListOrItemField to_internal_value method should utilize the item
    from-native logic.
    """
    field = ListOrItemField(child=DateField(format=ISO_8601))
    data = field.to_internal_value(date.today().isoformat())
    assert date.today() == data 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:10,代碼來源:test_listoritemfield.py

示例5: test_validate_required_missing

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_validate_required_missing():
    """
    When given a None value the ListOrItemField validate method should raise a ValidationError.
    """
    field = ListOrItemField(child=DateField(format=ISO_8601))
    with pytest.raises(ValidationError):
        field.to_internal_value(None) 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:9,代碼來源:test_listoritemfield.py

示例6: test_to_representation_with_item_field

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_representation_with_item_field():
    """
    When a ListField has an item-field, to_representation should return a list of elements resulting from
    the application of the item-field's to_representation method to each element of the input object list.
    """
    field = ListField(child=DateField(format=ISO_8601))
    obj = [date(2000, 1, 1), date(2000, 1, 2)]
    data = field.to_representation(obj)
    assert ["2000-01-01", "2000-01-02"] == data 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:11,代碼來源:test_listfield.py

示例7: test_missing_required_list

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_missing_required_list():
    """
    When a ListField requires a value, then validate should raise a ValidationError on a missing
    (None) value.
    """
    field = ListField(child=DateField())
    with pytest.raises(ValidationError):
        field.to_internal_value(None) 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:10,代碼來源:test_listfield.py

示例8: test_validate_non_list

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_validate_non_list():
    """
    When a ListField is given a non-list value, then validate should raise a ValidationError.
    """
    field = ListField(child=DateField())
    with pytest.raises(ValidationError):
        field.to_internal_value('notAList') 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:9,代碼來源:test_listfield.py

示例9: test_errors_non_list

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_errors_non_list():
    """
    When a ListField is given a non-list value, then there should be one error related to the type
    mismatch.
    """
    field = ListField(child=DateField())
    try:
        field.to_internal_value('notAList')
        assert False, 'Expected ValidationError'
    except ValidationError as e:
        pass 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:13,代碼來源:test_listfield.py

示例10: test_to_internal_value_with_included_keys

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_internal_value_with_included_keys():
    """
    When a PartialDictField has an included_keys, to_internal_value should return a dict of elmenents
    resulting from the application of the value-field's to_internal_value method to values of the input
    data dict that are includeded by included_keys.
    """
    field = PartialDictField(included_keys=['a'], child=DateField())
    data = {"a": "2000-01-01", "b": "2000-01-02"}
    obj = field.to_internal_value(data)
    assert {"a": date(2000, 1, 1)} == obj 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:12,代碼來源:test_partialdictfield.py

示例11: test_to_internal_value_with_nonexisting_included_keys

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_internal_value_with_nonexisting_included_keys():
    """
    When a PartialDictField has an included_keys that includes nonexisting keys, to_internal_value should
    ignore them.
    """
    field = PartialDictField(included_keys=['a', 'c'], child=DateField())
    data = {"a": "2000-01-01", "b": "2000-01-02"}
    obj = field.to_internal_value(data)
    assert {"a": date(2000, 1, 1)} == obj 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:11,代碼來源:test_partialdictfield.py

示例12: test_to_representation_with_nonexisting_included_keys

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_representation_with_nonexisting_included_keys():
    """
    When a PartialDictField has an included_keys that includes nonexisting keys, to_representation should
    ignore them.
    """
    field = PartialDictField(included_keys=['a', 'c'], child=DateField(format=ISO_8601))
    obj = {"a": date(2000, 1, 1), "b": date(2000, 1, 2)}
    data = field.to_representation(obj)
    assert {"a": "2000-01-01"} == data 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:11,代碼來源:test_partialdictfield.py

示例13: test_to_internal_value_with_child

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_internal_value_with_child():
    """
    When a DictField has an value-field, to_internal_value should return a dict of elements resulting
    from the application of the value-field's to_internal_value method to each value of the input
    data dict.
    """
    field = DictField(child=DateField())
    data = {"a": "2000-01-01", "b": "2000-01-02"}
    obj = field.to_internal_value(data)
    assert {"a": date(2000, 1, 1), "b": date(2000, 1, 2)} == obj 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:12,代碼來源:test_dictfield.py

示例14: test_to_representation_with_child

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_to_representation_with_child():
    """
    When a DictField has an value-field, to_representation should return a dict of elements resulting from
    the application of the value-field's to_representation method to each value of the input object dict.
    """
    field = DictField(child=DateField(format=ISO_8601))
    obj = {"a": date(2000, 1, 1), "b": date(2000, 1, 2)}
    data = field.to_representation(obj)
    assert {"a": "2000-01-01", "b": "2000-01-02"} == data 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:11,代碼來源:test_dictfield.py

示例15: test_validate_non_dict

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DateField [as 別名]
def test_validate_non_dict():
    """
    When a DictField is given a non-dict value, then validate should raise a ValidationError.
    """
    field = DictField(child=DateField())
    with pytest.raises(ValidationError):
        field.to_internal_value('notADict') 
開發者ID:estebistec,項目名稱:drf-compound-fields,代碼行數:9,代碼來源:test_dictfield.py


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