Skip to content

Commit

Permalink
pre-commit run --all-files
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCharmes committed Sep 10, 2024
1 parent 6bee0a7 commit 6f17a6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
8 changes: 6 additions & 2 deletions pydatalab/pydatalab/routes/v0_1/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,19 @@ def add_items_to_collection(collection_id):
data = request.get_json()
refcodes = data.get("data", {}).get("refcodes", [])

collection = flask_mongo.db.collections.find_one({"collection_id": collection_id, **get_default_permissions()})
collection = flask_mongo.db.collections.find_one(
{"collection_id": collection_id, **get_default_permissions()}
)

if not collection:
return jsonify({"error": "Collection not found"}), 404

if not refcodes:
return jsonify({"error": "No item provided"}), 400

item_count = flask_mongo.db.items.count_documents({"refcode": {"$in": refcodes}, **get_default_permissions()})
item_count = flask_mongo.db.items.count_documents(
{"refcode": {"$in": refcodes}, **get_default_permissions()}
)

if item_count == 0:
return jsonify({"error": "No matching items found"}), 404
Expand Down
30 changes: 13 additions & 17 deletions pydatalab/tests/server/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,36 @@ def test_simple_graph(admin_client):
child_1 = Sample(
item_id="child_1",
synthesis_constituents=[
Constituent(item={"type": "samples",
"item_id": "parent"}, quantity=None),
Constituent(item={"type": "samples", "item_id": "parent"}, quantity=None),
],
)

child_2 = Sample(
item_id="child_2",
refcode="test:TEST02",
synthesis_constituents=[
Constituent(item={"type": "samples",
"item_id": "parent"}, quantity=None),
Constituent(item={"type": "samples", "item_id": "parent"}, quantity=None),
],
)

child_3 = Sample(
item_id="child_3",
synthesis_constituents=[
Constituent(item={"type": "samples",
"item_id": "parent"}, quantity=None),
Constituent(item={"type": "samples", "item_id": "parent"}, quantity=None),
],
)

child_4 = Sample(
item_id="child_4",
synthesis_constituents=[
Constituent(item={"type": "samples",
"item_id": "parent"}, quantity=None),
Constituent(item={"type": "samples", "item_id": "parent"}, quantity=None),
],
)

missing_child = Sample(
item_id="missing_child",
synthesis_constituents=[
Constituent(item={"type": "samples",
"item_id": "parent"}, quantity=None),
Constituent(item={"type": "samples", "item_id": "parent"}, quantity=None),
],
)

Expand All @@ -65,8 +60,10 @@ def test_simple_graph(admin_client):
cell_format="swagelok",
)

new_samples = [json.loads(d.json()) for d in [
parent, child_1, child_2, child_3, child_4, missing_child, cell]]
new_samples = [
json.loads(d.json())
for d in [parent, child_1, child_2, child_3, child_4, missing_child, cell]
]

sample_list = admin_client.post(
"/new-samples/",
Expand All @@ -88,8 +85,7 @@ def test_simple_graph(admin_client):
}
assert len(graph["edges"]) == 6

response = admin_client.post(
"/delete-sample/", json={"item_id": "missing_child"})
response = admin_client.post("/delete-sample/", json={"item_id": "missing_child"})
assert response

graph = admin_client.get("/item-graph").json
Expand Down Expand Up @@ -148,9 +144,9 @@ def test_simple_graph(admin_client):
refcode_child_4 = item["sample_list_entry"].get("refcode")

response = admin_client.post(
f"/collections/{collection_id}", json={
"data": {"refcodes": [refcode_child_3, refcode_child_4]}
})
f"/collections/{collection_id}",
json={"data": {"refcodes": [refcode_child_3, refcode_child_4]}},
)

assert response.status_code == 200
assert response.json["status"] == "success"
Expand Down

0 comments on commit 6f17a6d

Please sign in to comment.