This repository was archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_codec.py
More file actions
91 lines (85 loc) · 2.53 KB
/
test_codec.py
File metadata and controls
91 lines (85 loc) · 2.53 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from coreapi import Document, Link, Field
from hal_codec import HALCodec
hal_bytestring = b'''{
"_links": {
"self": {"href": "/orders"},
"curies": [{"name": "ea", "href": "http://example.com/docs/rels/{rel}", "templated": true}],
"next": {"href": "/orders?page=2"},
"ea:find": {
"href": "/orders{?id}",
"templated": true
},
"ea:admin": [{
"href": "/admins/2",
"title": "Fred"
}, {
"href": "/admins/5",
"title": "Kate"
}]
},
"currentlyProcessing": 14,
"shippedToday": 20,
"_embedded": {
"ea:order": [{
"_links": {
"self": {"href": "/orders/123"},
"ea:basket": {"href": "/baskets/98712"},
"ea:customer": {"href": "/customers/7809"}
},
"total": 30.00,
"currency": "USD",
"status": "shipped"
}, {
"_links": {
"self": {"href": "/orders/124"},
"ea:basket": {"href": "/baskets/97213"},
"ea:customer": {"href": "/customers/12369"}
},
"total": 20.00,
"currency": "USD",
"status": "processing"
}]
}
}'''
hal_document = Document(
url=u'/orders',
title='',
content={
u'admin': [
Link(url=u'/admins/2'),
Link(url=u'/admins/5')
],
u'currentlyProcessing': 14,
u'order': [
Document(
url=u'/orders/123',
title='',
content={
u'currency': u'USD',
u'status': u'shipped',
u'total': 30.0,
u'basket': Link(url=u'/baskets/98712'),
u'customer': Link(url=u'/customers/7809')
}
),
Document(
url=u'/orders/124',
title='',
content={
u'currency': u'USD',
u'status': u'processing',
u'total': 20.0,
u'basket': Link(url=u'/baskets/97213'),
u'customer': Link(url=u'/customers/12369')
}
)
],
u'shippedToday': 20,
u'find': Link(url=u'/orders{?id}', fields=[Field(u'id', location='path')]),
u'next': Link(url=u'/orders?page=2')
}
)
def test_load():
codec = HALCodec()
doc = codec.load(hal_bytestring)
assert doc == hal_document