8
8
from pydatalab .models import Sample , StartingMaterial
9
9
10
10
11
- def test_single_starting_material (admin_client ):
11
+ def test_single_starting_material (admin_client , client ):
12
12
item_id = "material"
13
13
14
14
material = StartingMaterial (item_id = item_id )
15
15
16
- creation = admin_client .post (
16
+ creation = client .post (
17
17
"/new-sample/" ,
18
18
json = {"new_sample_data" : json .loads (material .json ())},
19
19
)
20
20
21
21
assert creation .status_code == 201
22
22
23
23
# A single material without connections should be ignored
24
- graph = admin_client .get ("/item-graph" ).json
24
+ graph = client .get ("/item-graph" ).json
25
25
assert len (graph ["nodes" ]) == 0
26
26
27
27
# Unless it is asked for directly
28
- graph = admin_client .get (f"/item-graph/{ item_id } " ).json
28
+ graph = client .get (f"/item-graph/{ item_id } " ).json
29
29
assert len (graph ["nodes" ]) == 1
30
30
31
31
# Now make a sample and connect it to the starting material; check that the
@@ -37,13 +37,73 @@ def test_single_starting_material(admin_client):
37
37
],
38
38
)
39
39
40
- creation = admin_client .post (
40
+ creation = client .post (
41
41
"/new-sample/" ,
42
42
json = {"new_sample_data" : json .loads (parent .json ())},
43
43
)
44
44
45
45
assert creation .status_code == 201
46
46
47
- graph = admin_client .get ("/item-graph" ).json
47
+ graph = client .get ("/item-graph" ).json
48
+ assert len (graph ["nodes" ]) == 2
49
+ assert len (graph ["edges" ]) == 1
50
+
51
+ # From both the starting material and the sample
52
+ graph = client .get (f"/item-graph/{ item_id } " ).json
53
+ assert len (graph ["nodes" ]) == 2
54
+ assert len (graph ["edges" ]) == 1
55
+
56
+ # From both the starting material and the sample
57
+ graph = client .get ("/item-graph/parent" ).json
58
+ assert len (graph ["nodes" ]) == 2
59
+ assert len (graph ["edges" ]) == 1
60
+
61
+ # Now add a few more samples in a chain and check that only the relevant ones are shown
62
+ child = Sample (
63
+ item_id = "child" ,
64
+ synthesis_constituents = [
65
+ {"item" : {"item_id" : "parent" , "type" : "samples" }, "quantity" : None }
66
+ ],
67
+ )
68
+
69
+ creation = client .post (
70
+ "/new-sample/" ,
71
+ json = {"new_sample_data" : json .loads (child .json ())},
72
+ )
73
+
74
+ grandchild = Sample (
75
+ item_id = "grandchild" ,
76
+ synthesis_constituents = [
77
+ {"item" : {"item_id" : "child" , "type" : "samples" }, "quantity" : None }
78
+ ],
79
+ )
80
+
81
+ creation = client .post (
82
+ "/new-sample/" ,
83
+ json = {"new_sample_data" : json .loads (grandchild .json ())},
84
+ )
85
+
86
+ great_grandchild = Sample (
87
+ item_id = "great-grandchild" ,
88
+ synthesis_constituents = [
89
+ {"item" : {"item_id" : "grandchild" , "type" : "samples" }, "quantity" : None }
90
+ ],
91
+ )
92
+
93
+ creation = client .post (
94
+ "/new-sample/" ,
95
+ json = {"new_sample_data" : json .loads (great_grandchild .json ())},
96
+ )
97
+
98
+ graph = client .get ("/item-graph" ).json
99
+ assert len (graph ["nodes" ]) == 5
100
+ assert len (graph ["edges" ]) == 4
101
+
102
+ # Check for bug where this behaviour was inconsistent between admin and non-admin users
103
+ graph = admin_client .get ("/item-graph/great-grandchild" ).json
104
+ assert len (graph ["nodes" ]) == 2
105
+ assert len (graph ["edges" ]) == 1
106
+
107
+ graph = client .get ("/item-graph/great-grandchild" ).json
48
108
assert len (graph ["nodes" ]) == 2
49
109
assert len (graph ["edges" ]) == 1
0 commit comments