Skip to content

Commit 4816146

Browse files
authored
Merge pull request #147 from A-Baji/form-response-defaults
add default value to form component output
2 parents 30b9421 + 08ae473 commit 4816146

File tree

9 files changed

+157
-54
lines changed

9 files changed

+157
-54
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.
44

5+
## [0.6.3] - 2022-11-18
6+
7+
### Added
8+
9+
- Added attribute default value to the form component field route response
10+
511
## [0.6.2] - 2022-11-10
612

713
### Fixed
@@ -220,6 +226,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
220226
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
221227
- Check dependency utility to determine child table references.
222228

229+
[0.6.3]: https://github.com/datajoint/pharus/compare/0.6.2...0.6.3
223230
[0.6.2]: https://github.com/datajoint/pharus/compare/0.6.1...0.6.2
224231
[0.6.1]: https://github.com/datajoint/pharus/compare/0.6.0...0.6.1
225232
[0.6.0]: https://github.com/datajoint/pharus/compare/0.5.6...0.6.0

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ To start the API server, use the command:
2929

3030
.. code-block:: bash
3131
32-
PHARUS_VERSION=0.6.2 docker-compose -f docker-compose-deploy.yaml up -d
32+
PHARUS_VERSION=0.6.3 docker-compose -f docker-compose-deploy.yaml up -d
3333
3434
To stop the API server, use the command:
3535

3636
.. code-block:: bash
3737
38-
PHARUS_VERSION=0.6.2 docker-compose -f docker-compose-deploy.yaml down
38+
PHARUS_VERSION=0.6.3 docker-compose -f docker-compose-deploy.yaml down
3939
4040
References
4141
----------

docker-compose-deploy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# PHARUS_VERSION=0.6.2 docker-compose -f docker-compose-deploy.yaml pull
2-
# PHARUS_VERSION=0.6.2 docker-compose -f docker-compose-deploy.yaml up -d
1+
# PHARUS_VERSION=0.6.3 docker-compose -f docker-compose-deploy.yaml pull
2+
# PHARUS_VERSION=0.6.3 docker-compose -f docker-compose-deploy.yaml up -d
33
#
44
# Intended for production deployment.
55
# Note: You must run both commands above for minimal outage

pharus/component_interface.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ def fields_route(self):
194194
for p in self.parents
195195
},
196196
**{
197-
a: {"datatype": v.type, "type": "attribute", "name": v.name}
197+
a: {
198+
"datatype": v.type,
199+
"type": "attribute",
200+
"name": v.name,
201+
"default": v.default,
202+
}
198203
for t in self.tables
199204
for a, v in t.heading.attributes.items()
200205
if a not in parent_attributes

pharus/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def api_version() -> str:
126126
Content-Type: application/json
127127
128128
{
129-
"version": "0.6.2"
129+
"version": "0.6.3"
130130
}
131131
132132
:statuscode 200: No error.

pharus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Package metadata."""
2-
__version__ = "0.6.2"
2+
__version__ = "0.6.3"

tests/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ class TableC(dj.Lookup):
149149
-> TableB
150150
c_id: int
151151
---
152-
c_int: int
152+
c_name = John Smith : varchar(30)
153153
"""
154154
contents = [
155155
(0, 10, 100, -8),
156156
(
157157
0,
158158
11,
159159
200,
160-
-9,
160+
"Josh",
161161
),
162162
(
163163
0,
164164
11,
165165
300,
166-
-7,
166+
"Lumberjack",
167167
),
168168
]
169169

@@ -273,7 +273,7 @@ class TableW(dj.Lookup):
273273
-> TableX
274274
w_id: int
275275
---
276-
w_int: int
276+
w_int = 123 : int
277277
"""
278278

279279
@group1_simple

tests/init/test_dynamic_api_spec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ SciViz: # top level tab
4343
input: C Id
4444
destination: c_id
4545
- type: attribute #omitted input means display is session_note
46-
destination: c_int
46+
destination: c_name
4747
insert2:
4848
route: /insert2
4949
x: 1
@@ -68,7 +68,7 @@ SciViz: # top level tab
6868
input: C Id
6969
destination: c_id
7070
- type: attribute #omitted input means display is session_note
71-
destination: c_int
71+
destination: c_name
7272
insert3:
7373
route: /insert3
7474
x: 1

tests/test_form.py

Lines changed: 132 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_insert_map(token, client, connection, schemas_simple):
1313
"/insert",
1414
json={
1515
"submissions": [
16-
{"A Id": 1, "B Id": 32, "B Number": 1.23, "C Id": 400, "c_int": 99}
16+
{"A Id": 1, "B Id": 32, "B Number": 1.23, "C Id": 400, "c_name": "John"}
1717
]
1818
},
1919
headers=dict(Authorization=f"Bearer {token}"),
@@ -27,7 +27,13 @@ def test_insert_no_map(token, client, connection, schemas_simple):
2727
"/insert3?group=test_group1",
2828
json={
2929
"submissions": [
30-
{"a_id": 1, "b_id": 32, "b_number": 1.23, "c_id": 400, "c_int": 99}
30+
{
31+
"a_id": 1,
32+
"b_id": 32,
33+
"b_number": 1.23,
34+
"c_id": 400,
35+
"c_name": "Smith",
36+
}
3137
]
3238
},
3339
headers=dict(Authorization=f"Bearer {token}"),
@@ -39,7 +45,7 @@ def test_insert_no_map(token, client, connection, schemas_simple):
3945
def test_insert_fail(token, client, connection, schemas_simple):
4046
REST_response = client.post(
4147
"/insert3?group=test_group1",
42-
json={"submissions": [{"a_id": 1, "b_id": 32, "b_number": 1.23, "c_id": 400}]},
48+
json={"submissions": [{"a_id": 1, "b_id": 32, "b_number": 1.23}]},
4349
headers=dict(Authorization=f"Bearer {token}"),
4450
)
4551
assert REST_response.status_code == 500
@@ -61,11 +67,21 @@ def test_form_response(token, client, connection, schemas_simple):
6167
assert REST_response.status_code == 200, f"Error: {REST_response.data}"
6268
assert REST_response.get_json() == {
6369
"fields": [
64-
{"datatype": "int", "name": "B Id", "type": "attribute"},
65-
{"datatype": "float", "name": "B Number", "type": "attribute"},
70+
{"datatype": "int", "name": "B Id", "type": "attribute", "default": None},
71+
{
72+
"datatype": "float",
73+
"name": "B Number",
74+
"type": "attribute",
75+
"default": None,
76+
},
6677
{"name": "Table A", "type": "table", "values": [{"A Id": 0}, {"A Id": 1}]},
67-
{"datatype": "int", "name": "C Id", "type": "attribute"},
68-
{"datatype": "int", "name": "c_int", "type": "attribute"},
78+
{"datatype": "int", "name": "C Id", "type": "attribute", "default": None},
79+
{
80+
"datatype": "varchar(30)",
81+
"name": "c_name",
82+
"type": "attribute",
83+
"default": '"John Smith"',
84+
},
6985
],
7086
}
7187

@@ -78,11 +94,21 @@ def test_form_response_no_table_map(token, client, connection, schemas_simple):
7894
assert REST_response.status_code == 200, f"Error: {REST_response.data}"
7995
assert REST_response.get_json() == {
8096
"fields": [
81-
{"datatype": "int", "name": "B Id", "type": "attribute"},
82-
{"datatype": "float", "name": "B Number", "type": "attribute"},
97+
{"datatype": "int", "name": "B Id", "type": "attribute", "default": None},
98+
{
99+
"datatype": "float",
100+
"name": "B Number",
101+
"type": "attribute",
102+
"default": None,
103+
},
83104
{"name": "Table A", "type": "table", "values": [{"a_id": 0}, {"a_id": 1}]},
84-
{"datatype": "int", "name": "C Id", "type": "attribute"},
85-
{"datatype": "int", "name": "c_int", "type": "attribute"},
105+
{"datatype": "int", "name": "C Id", "type": "attribute", "default": None},
106+
{
107+
"datatype": "varchar(30)",
108+
"name": "c_name",
109+
"type": "attribute",
110+
"default": '"John Smith"',
111+
},
86112
],
87113
}
88114

@@ -100,10 +126,20 @@ def test_form_response_no_map(token, client, connection, schemas_simple):
100126
"type": "table",
101127
"values": [{"a_id": 0}, {"a_id": 1}],
102128
},
103-
{"datatype": "int", "name": "b_id", "type": "attribute"},
104-
{"datatype": "float", "name": "b_number", "type": "attribute"},
105-
{"datatype": "int", "name": "c_id", "type": "attribute"},
106-
{"datatype": "int", "name": "c_int", "type": "attribute"},
129+
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
130+
{
131+
"datatype": "float",
132+
"name": "b_number",
133+
"type": "attribute",
134+
"default": None,
135+
},
136+
{"datatype": "int", "name": "c_id", "type": "attribute", "default": None},
137+
{
138+
"datatype": "varchar(30)",
139+
"name": "c_name",
140+
"type": "attribute",
141+
"default": '"John Smith"',
142+
},
107143
],
108144
}
109145

@@ -132,10 +168,20 @@ def test_form_response_no_map_shared_FK_hierarchy(
132168
{"a_id": 1, "b_id": 21},
133169
],
134170
},
135-
{"datatype": "int", "name": "bs_id", "type": "attribute"},
136-
{"datatype": "float", "name": "bs_number", "type": "attribute"},
137-
{"datatype": "int", "name": "c_id", "type": "attribute"},
138-
{"datatype": "int", "name": "c_int", "type": "attribute"},
171+
{"datatype": "int", "name": "bs_id", "type": "attribute", "default": None},
172+
{
173+
"datatype": "float",
174+
"name": "bs_number",
175+
"type": "attribute",
176+
"default": None,
177+
},
178+
{"datatype": "int", "name": "c_id", "type": "attribute", "default": None},
179+
{
180+
"datatype": "varchar(30)",
181+
"name": "c_name",
182+
"type": "attribute",
183+
"default": '"John Smith"',
184+
},
139185
]
140186
}
141187

@@ -153,10 +199,20 @@ def test_form_response_no_map_shared_FK(token, client, connection, schemas_simpl
153199
"type": "table",
154200
"values": [{"a_id": 0}, {"a_id": 1}],
155201
},
156-
{"datatype": "int", "name": "b_id", "type": "attribute"},
157-
{"datatype": "float", "name": "b_number", "type": "attribute"},
158-
{"datatype": "int", "name": "bs_id", "type": "attribute"},
159-
{"datatype": "float", "name": "bs_number", "type": "attribute"},
202+
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
203+
{
204+
"datatype": "float",
205+
"name": "b_number",
206+
"type": "attribute",
207+
"default": None,
208+
},
209+
{"datatype": "int", "name": "bs_id", "type": "attribute", "default": None},
210+
{
211+
"datatype": "float",
212+
"name": "bs_number",
213+
"type": "attribute",
214+
"default": None,
215+
},
160216
],
161217
}
162218

@@ -179,10 +235,20 @@ def test_form_response_no_map_diff_FK(token, client, connection, schemas_simple)
179235
"type": "table",
180236
"values": [{"zs_id": 0}, {"zs_id": 1}],
181237
},
182-
{"datatype": "int", "name": "y_id", "type": "attribute"},
183-
{"datatype": "float", "name": "y_number", "type": "attribute"},
184-
{"datatype": "int", "name": "ys_id", "type": "attribute"},
185-
{"datatype": "float", "name": "ys_number", "type": "attribute"},
238+
{"datatype": "int", "name": "y_id", "type": "attribute", "default": None},
239+
{
240+
"datatype": "float",
241+
"name": "y_number",
242+
"type": "attribute",
243+
"default": None,
244+
},
245+
{"datatype": "int", "name": "ys_id", "type": "attribute", "default": None},
246+
{
247+
"datatype": "float",
248+
"name": "ys_number",
249+
"type": "attribute",
250+
"default": None,
251+
},
186252
]
187253
}
188254

@@ -203,8 +269,8 @@ def test_form_response_no_map_multi_FPK(token, client, connection, schemas_simpl
203269
{"x_id": 1, "x_int": 20, "x_name": "Oscar"},
204270
],
205271
},
206-
{"datatype": "int", "name": "w_id", "type": "attribute"},
207-
{"datatype": "int", "name": "w_int", "type": "attribute"},
272+
{"datatype": "int", "name": "w_id", "type": "attribute", "default": None},
273+
{"datatype": "int", "name": "w_int", "type": "attribute", "default": "123"},
208274
],
209275
}
210276

@@ -240,17 +306,42 @@ def test_form_response_no_map_many_tables(token, client, connection, schemas_sim
240306
"type": "table",
241307
"values": [{"zs_id": 0}, {"zs_id": 1}],
242308
},
243-
{"datatype": "int", "name": "b_id", "type": "attribute"},
244-
{"datatype": "float", "name": "b_number", "type": "attribute"},
245-
{"datatype": "int", "name": "bs_id", "type": "attribute"},
246-
{"datatype": "float", "name": "bs_number", "type": "attribute"},
247-
{"datatype": "int", "name": "c_id", "type": "attribute"},
248-
{"datatype": "int", "name": "c_int", "type": "attribute"},
249-
{"datatype": "int", "name": "y_id", "type": "attribute"},
250-
{"datatype": "float", "name": "y_number", "type": "attribute"},
251-
{"datatype": "int", "name": "ys_id", "type": "attribute"},
252-
{"datatype": "float", "name": "ys_number", "type": "attribute"},
253-
{"datatype": "int", "name": "w_id", "type": "attribute"},
254-
{"datatype": "int", "name": "w_int", "type": "attribute"},
309+
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
310+
{
311+
"datatype": "float",
312+
"name": "b_number",
313+
"type": "attribute",
314+
"default": None,
315+
},
316+
{"datatype": "int", "name": "bs_id", "type": "attribute", "default": None},
317+
{
318+
"datatype": "float",
319+
"name": "bs_number",
320+
"type": "attribute",
321+
"default": None,
322+
},
323+
{"datatype": "int", "name": "c_id", "type": "attribute", "default": None},
324+
{
325+
"datatype": "varchar(30)",
326+
"name": "c_name",
327+
"type": "attribute",
328+
"default": '"John Smith"',
329+
},
330+
{"datatype": "int", "name": "y_id", "type": "attribute", "default": None},
331+
{
332+
"datatype": "float",
333+
"name": "y_number",
334+
"type": "attribute",
335+
"default": None,
336+
},
337+
{"datatype": "int", "name": "ys_id", "type": "attribute", "default": None},
338+
{
339+
"datatype": "float",
340+
"name": "ys_number",
341+
"type": "attribute",
342+
"default": None,
343+
},
344+
{"datatype": "int", "name": "w_id", "type": "attribute", "default": None},
345+
{"datatype": "int", "name": "w_int", "type": "attribute", "default": "123"},
255346
]
256347
}

0 commit comments

Comments
 (0)