コード例 #1
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_string_type():
    assert is_value_of_type('', STRING)
    if six.PY2:
        assert is_value_of_type(six.binary_type('string'), STRING)
    else:
        assert is_value_of_type(six.binary_type('string', encoding='utf-8'), STRING)
    assert is_value_of_type(six.text_type('string'), STRING)
コード例 #2
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_string_type():
    assert is_value_of_type('', STRING)
    if six.PY2:
        assert is_value_of_type(six.binary_type('string'), STRING)
    else:
        assert is_value_of_type(six.binary_type('string', encoding='utf-8'),
                                STRING)
    assert is_value_of_type(six.text_type('string'), STRING)
コード例 #3
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_non_boolean_types():
    assert not is_value_of_type(None, BOOLEAN)
    assert not is_value_of_type('1', BOOLEAN)
    assert not is_value_of_type(1, BOOLEAN)
    assert not is_value_of_type('0', BOOLEAN)
    assert not is_value_of_type(0, BOOLEAN)
    assert not is_value_of_type([], BOOLEAN)
コード例 #4
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_non_boolean_types():
    assert not is_value_of_type(None, BOOLEAN)
    assert not is_value_of_type('1', BOOLEAN)
    assert not is_value_of_type(1, BOOLEAN)
    assert not is_value_of_type('0', BOOLEAN)
    assert not is_value_of_type(0, BOOLEAN)
    assert not is_value_of_type([], BOOLEAN)
コード例 #5
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_non_object_types():
    assert not is_value_of_type([], OBJECT)
    assert not is_value_of_type(tuple(), OBJECT)
コード例 #6
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_non_number_types():
    assert not is_value_of_type('0', NUMBER)
    assert not is_value_of_type(True, NUMBER)
    assert not is_value_of_type([], NUMBER)
コード例 #7
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_number_type():
    assert is_value_of_type(0, NUMBER)
    assert is_value_of_type(1, NUMBER)
    assert is_value_of_type(1.0, NUMBER)
コード例 #8
0
ファイル: test_utils.py プロジェクト: dhilton/flex
def test_string_type():
    assert is_value_of_type('', STRING)
    assert is_value_of_type(six.binary_type('string'), STRING)
    assert is_value_of_type(six.text_type('string'), STRING)
コード例 #9
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_non_integer_type():
    assert not is_value_of_type(1.0, INTEGER)
    assert not is_value_of_type(True, INTEGER)
    assert not is_value_of_type(False, INTEGER)
コード例 #10
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_non_null_type():
    assert not is_value_of_type(False, NULL)
    assert not is_value_of_type('', NULL)
    assert not is_value_of_type([], NULL)
コード例 #11
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_non_array_types():
    assert not is_value_of_type({}, ARRAY)
    assert not is_value_of_type(1, ARRAY)
    assert not is_value_of_type('1234', ARRAY)
コード例 #12
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_non_object_types():
    assert not is_value_of_type([], OBJECT)
    assert not is_value_of_type(tuple(), OBJECT)
コード例 #13
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_object_types():
    assert is_value_of_type({}, OBJECT)
コード例 #14
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_non_string_type():
    assert not is_value_of_type(1, STRING)
    assert not is_value_of_type(True, STRING)
    assert not is_value_of_type(None, STRING)
    assert not is_value_of_type([], STRING)
コード例 #15
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_non_array_types():
    assert not is_value_of_type({}, ARRAY)
    assert not is_value_of_type(1, ARRAY)
    assert not is_value_of_type('1234', ARRAY)
コード例 #16
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_array_type():
    assert is_value_of_type([], ARRAY)
    assert is_value_of_type(tuple(), ARRAY)
コード例 #17
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_non_string_type():
    assert not is_value_of_type(1, STRING)
    assert not is_value_of_type(True, STRING)
    assert not is_value_of_type(None, STRING)
    assert not is_value_of_type([], STRING)
コード例 #18
0
ファイル: validators.py プロジェクト: jmdcal/flex
def is_array_validator(value):
    if not is_value_of_type(value, ARRAY):
        raise serializers.ValidationError(
            "Must be an array",
        )
コード例 #19
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_non_number_types():
    assert not is_value_of_type('0', NUMBER)
    assert not is_value_of_type(True, NUMBER)
    assert not is_value_of_type([], NUMBER)
コード例 #20
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_array_type():
    assert is_value_of_type([], ARRAY)
    assert is_value_of_type(tuple(), ARRAY)
コード例 #21
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_null_type():
    assert is_value_of_type(None, NULL)
コード例 #22
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_object_types():
    assert is_value_of_type({}, OBJECT)
コード例 #23
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_non_null_type():
    assert not is_value_of_type(False, NULL)
    assert not is_value_of_type('', NULL)
    assert not is_value_of_type([], NULL)
コード例 #24
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_null_type():
    assert is_value_of_type(None, NULL)
コード例 #25
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_boolean_type():
    assert is_value_of_type(True, BOOLEAN)
    assert is_value_of_type(False, BOOLEAN)
コード例 #26
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_boolean_type():
    assert is_value_of_type(True, BOOLEAN)
    assert is_value_of_type(False, BOOLEAN)
コード例 #27
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_integer_type():
    assert is_value_of_type(0, INTEGER)
    assert is_value_of_type(-1, INTEGER)
    assert is_value_of_type(1, INTEGER)
コード例 #28
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_integer_type():
    assert is_value_of_type(0, INTEGER)
    assert is_value_of_type(-1, INTEGER)
    assert is_value_of_type(1, INTEGER)
コード例 #29
0
ファイル: test_utils.py プロジェクト: waltton/flex
def test_non_integer_type():
    assert not is_value_of_type(1.0, INTEGER)
    assert not is_value_of_type(True, INTEGER)
    assert not is_value_of_type(False, INTEGER)
コード例 #30
0
ファイル: test_utils.py プロジェクト: pipermerriam/flex
def test_number_type():
    assert is_value_of_type(0, NUMBER)
    assert is_value_of_type(1, NUMBER)
    assert is_value_of_type(1.0, NUMBER)
コード例 #31
0
ファイル: mixins.py プロジェクト: dhilton/flex
 def validate_default_type(self, attrs, errors):
     if 'default' in attrs and 'type' in attrs:
         if not is_value_of_type(attrs['default'], attrs['type']):
             errors['default'].append(
                 self.error_messages['default_is_incorrect_type'],
             )