Skip to content

Commit 30b9421

Browse files
Merge pull request #146 from A-Baji/master
update api responses to valid json
2 parents 4ad1930 + 1e35c6a commit 30b9421

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
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.2] - 2022-11-10
6+
7+
### Fixed
8+
9+
- Convert the return of the insert route and normal record routes to valid json [#146](https://github.com/datajoint/pharus/pull/146)
10+
511
## [0.6.1] - 2022-11-04
612

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

223+
[0.6.2]: https://github.com/datajoint/pharus/compare/0.6.1...0.6.2
217224
[0.6.1]: https://github.com/datajoint/pharus/compare/0.6.0...0.6.1
218225
[0.6.0]: https://github.com/datajoint/pharus/compare/0.5.6...0.6.0
219226
[0.5.6]: https://github.com/datajoint/pharus/compare/0.5.5...0.5.6

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.1 docker-compose -f docker-compose-deploy.yaml up -d
32+
PHARUS_VERSION=0.6.2 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.1 docker-compose -f docker-compose-deploy.yaml down
38+
PHARUS_VERSION=0.6.2 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.1 docker-compose -f docker-compose-deploy.yaml pull
2-
# PHARUS_VERSION=0.6.1 docker-compose -f docker-compose-deploy.yaml up -d
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
33
#
44
# Intended for production deployment.
55
# Note: You must run both commands above for minimal outage

pharus/component_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def dj_query_route(self):
180180
for r in self.payload["submissions"]
181181
]
182182
)
183-
return "Insert successful"
183+
return {"response": "Insert Successful"}
184184

185185
def fields_route(self):
186186
parent_attributes = sorted(set(sum([p.primary_key for p in self.parents], [])))

pharus/server.py

Lines changed: 13 additions & 7 deletions
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.1"
129+
"version": "0.6.2"
130130
}
131131
132132
:statuscode 200: No error.
@@ -573,7 +573,9 @@ def record(
573573
Vary: Accept
574574
Content-Type: text/plain
575575
576-
Insert Successful
576+
{
577+
"response": "Insert Successful"
578+
}
577579
578580
**Example unexpected response**:
579581
@@ -631,7 +633,9 @@ def record(
631633
Vary: Accept
632634
Content-Type: text/plain
633635
634-
Update Successful
636+
{
637+
"response": "Update Successful"
638+
}
635639
636640
**Example unexpected response**:
637641
@@ -673,7 +677,9 @@ def record(
673677
Vary: Accept
674678
Content-Type: text/plain
675679
676-
Delete Successful
680+
{
681+
"response": "Delete Successful"
682+
}
677683
678684
**Example conflict response**:
679685
@@ -751,15 +757,15 @@ def record(
751757
_DJConnector._insert_tuple(
752758
connection, schema_name, table_name, request.json["records"]
753759
)
754-
return "Insert Successful"
760+
return {"response": "Insert Successful"}
755761
except Exception:
756762
return traceback.format_exc(), 500
757763
elif request.method == "PATCH":
758764
try:
759765
_DJConnector._update_tuple(
760766
connection, schema_name, table_name, request.json["records"]
761767
)
762-
return "Update Successful"
768+
return {"response": "Update Successful"}
763769
except Exception:
764770
return traceback.format_exc(), 500
765771
elif request.method == "DELETE":
@@ -779,7 +785,7 @@ def record(
779785
if k == "cascade"
780786
},
781787
)
782-
return "Delete Sucessful"
788+
return {"response": "Delete Successful"}
783789
except IntegrityError as e:
784790
match = foreign_key_error_regexp.match(e.args[0])
785791
return (

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.1"
2+
__version__ = "0.6.2"

tests/test_form.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_insert_map(token, client, connection, schemas_simple):
1919
headers=dict(Authorization=f"Bearer {token}"),
2020
)
2121
assert REST_response.status_code == 200, REST_response.data
22-
assert REST_response.data == b"Insert successful"
22+
assert REST_response.get_json() == {"response": "Insert Successful"}
2323

2424

2525
def test_insert_no_map(token, client, connection, schemas_simple):
@@ -33,7 +33,7 @@ def test_insert_no_map(token, client, connection, schemas_simple):
3333
headers=dict(Authorization=f"Bearer {token}"),
3434
)
3535
assert REST_response.status_code == 200
36-
assert REST_response.data == b"Insert successful"
36+
assert REST_response.get_json() == {"response": "Insert Successful"}
3737

3838

3939
def test_insert_fail(token, client, connection, schemas_simple):

0 commit comments

Comments
 (0)