-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_models.py
52 lines (38 loc) · 1.46 KB
/
test_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
import pytest
try:
from pydantic.v1 import ValidationError
except ImportError:
from pydantic import ValidationError
import iscc_core as ic
import iscc_sdk as idk
def test_IsccMeta_extra_forbid():
with pytest.raises(ValidationError):
idk.IsccMeta(iscc="ISCC:MEAJU5AXCPOIOYFL", somefield="not allowed")
with pytest.raises(ValueError):
im = idk.IsccMeta(iscc="ISCC:MEAJU5AXCPOIOYFL")
im.other = "test"
def test_IsccMeta_validate_assignment():
im = idk.IsccMeta(iscc="ISCC:MEAJU5AXCPOIOYFL")
with pytest.raises(ValidationError):
im.iscc = "MEAJU5AXCPOIOYFL"
def test_IsccMeta_dict_defaults_exclude_none_unset():
im = idk.IsccMeta(iscc="ISCC:MEAJU5AXCPOIOYFL")
assert im == {"iscc": "ISCC:MEAJU5AXCPOIOYFL"}
def test_IsccMeta_json():
im = idk.IsccMeta(iscc="ISCC:MEAJU5AXCPOIOYFL")
assert im.json() == (
'{"@context": "http://purl.org/iscc/context", "@type": '
'"CreativeWork", "$schema": "http://purl.org/iscc/schema", "iscc": '
'"ISCC:MEAJU5AXCPOIOYFL"}'
)
def test_IsccMeta_jcs():
im = idk.IsccMeta(iscc="ISCC:MEAJU5AXCPOIOYFL")
assert im.jcs() == (
b'{"$schema":"http://purl.org/iscc/schema","@context":"http://purl.'
b'org/iscc/context","@type":"CreativeWork","iscc":"ISCC:MEAJU5AXC'
b'POIOYFL"}'
)
def test_IsccMeta_iscc_obj():
im = idk.IsccMeta(iscc="ISCC:MEAJU5AXCPOIOYFL")
assert isinstance(im.iscc_obj, ic.Code)