37
37
POOL2_DESCRIPTION = "Some Description"
38
38
39
39
40
+ POOL3_NAME = "pool3/with_slashes"
41
+ POOL3_SLOT = 5
42
+ POOL3_INCLUDE_DEFERRED = False
43
+ POOL3_DESCRIPTION = "Some Description"
44
+
45
+
40
46
@provide_session
41
47
def _create_pools (session ) -> None :
42
48
pool1 = Pool (pool = POOL1_NAME , slots = POOL1_SLOT , include_deferred = POOL1_INCLUDE_DEFERRED )
43
49
pool2 = Pool (pool = POOL2_NAME , slots = POOL2_SLOT , include_deferred = POOL2_INCLUDE_DEFERRED )
44
- session .add_all ([pool1 , pool2 ])
50
+ pool3 = Pool (
51
+ pool = POOL3_NAME ,
52
+ slots = POOL3_SLOT ,
53
+ include_deferred = POOL3_INCLUDE_DEFERRED ,
54
+ description = POOL3_DESCRIPTION ,
55
+ )
56
+ session .add_all ([pool1 , pool2 , pool3 ])
45
57
46
58
47
59
class TestPoolsEndpoint :
@@ -60,11 +72,11 @@ class TestDeletePool(TestPoolsEndpoint):
60
72
def test_delete_should_respond_204 (self , test_client , session ):
61
73
self .create_pools ()
62
74
pools = session .query (Pool ).all ()
63
- assert len (pools ) == 3
75
+ assert len (pools ) == 4
64
76
response = test_client .delete (f"/pools/{ POOL1_NAME } " )
65
77
assert response .status_code == 204
66
78
pools = session .query (Pool ).all ()
67
- assert len (pools ) == 2
79
+ assert len (pools ) == 3
68
80
check_last_log (session , dag_id = None , event = "delete_pool" , logical_date = None )
69
81
70
82
def test_delete_should_respond_401 (self , unauthenticated_test_client ):
@@ -87,6 +99,17 @@ def test_delete_should_respond_404(self, test_client):
87
99
body = response .json ()
88
100
assert f"The Pool with name: `{ POOL1_NAME } ` was not found" == body ["detail" ]
89
101
102
+ def test_delete_pool3_should_respond_204 (self , test_client , session ):
103
+ """Test deleting POOL3 with forward slash in name"""
104
+ self .create_pools ()
105
+ pools = session .query (Pool ).all ()
106
+ assert len (pools ) == 4
107
+ response = test_client .delete (f"/pools/{ POOL3_NAME } " )
108
+ assert response .status_code == 204
109
+ pools = session .query (Pool ).all ()
110
+ assert len (pools ) == 3
111
+ check_last_log (session , dag_id = None , event = "delete_pool" , logical_date = None )
112
+
90
113
91
114
class TestGetPool (TestPoolsEndpoint ):
92
115
def test_get_should_respond_200 (self , test_client , session ):
@@ -120,24 +143,42 @@ def test_get_should_respond_404(self, test_client):
120
143
body = response .json ()
121
144
assert f"The Pool with name: `{ POOL1_NAME } ` was not found" == body ["detail" ]
122
145
146
+ def test_get_pool3_should_respond_200 (self , test_client , session ):
147
+ """Test getting POOL3 with forward slash in name"""
148
+ self .create_pools ()
149
+ response = test_client .get (f"/pools/{ POOL3_NAME } " )
150
+ assert response .status_code == 200
151
+ assert response .json () == {
152
+ "deferred_slots" : 0 ,
153
+ "description" : "Some Description" ,
154
+ "include_deferred" : False ,
155
+ "name" : "pool3/with_slashes" ,
156
+ "occupied_slots" : 0 ,
157
+ "open_slots" : 5 ,
158
+ "queued_slots" : 0 ,
159
+ "running_slots" : 0 ,
160
+ "scheduled_slots" : 0 ,
161
+ "slots" : 5 ,
162
+ }
163
+
123
164
124
165
class TestGetPools (TestPoolsEndpoint ):
125
166
@pytest .mark .parametrize (
126
167
"query_params, expected_total_entries, expected_ids" ,
127
168
[
128
169
# Filters
129
- ({}, 3 , [Pool .DEFAULT_POOL_NAME , POOL1_NAME , POOL2_NAME ]),
130
- ({"limit" : 1 }, 3 , [Pool .DEFAULT_POOL_NAME ]),
131
- ({"limit" : 1 , "offset" : 1 }, 3 , [POOL1_NAME ]),
170
+ ({}, 4 , [Pool .DEFAULT_POOL_NAME , POOL1_NAME , POOL2_NAME , POOL3_NAME ]),
171
+ ({"limit" : 1 }, 4 , [Pool .DEFAULT_POOL_NAME ]),
172
+ ({"limit" : 1 , "offset" : 1 }, 4 , [POOL1_NAME ]),
132
173
# Sort
133
- ({"order_by" : "-id" }, 3 , [POOL2_NAME , POOL1_NAME , Pool .DEFAULT_POOL_NAME ]),
134
- ({"order_by" : "id" }, 3 , [Pool .DEFAULT_POOL_NAME , POOL1_NAME , POOL2_NAME ]),
135
- ({"order_by" : "name" }, 3 , [Pool .DEFAULT_POOL_NAME , POOL1_NAME , POOL2_NAME ]),
174
+ ({"order_by" : "-id" }, 4 , [POOL3_NAME , POOL2_NAME , POOL1_NAME , Pool .DEFAULT_POOL_NAME ]),
175
+ ({"order_by" : "id" }, 4 , [Pool .DEFAULT_POOL_NAME , POOL1_NAME , POOL2_NAME , POOL3_NAME ]),
176
+ ({"order_by" : "name" }, 4 , [Pool .DEFAULT_POOL_NAME , POOL1_NAME , POOL2_NAME , POOL3_NAME ]),
136
177
# Search
137
178
(
138
179
{"pool_name_pattern" : "~" },
139
- 3 ,
140
- [Pool .DEFAULT_POOL_NAME , POOL1_NAME , POOL2_NAME ],
180
+ 4 ,
181
+ [Pool .DEFAULT_POOL_NAME , POOL1_NAME , POOL2_NAME , POOL3_NAME ],
141
182
),
142
183
({"pool_name_pattern" : "default" }, 1 , [Pool .DEFAULT_POOL_NAME ]),
143
184
],
@@ -314,6 +355,32 @@ def test_should_respond_403(self, unauthorized_test_client):
314
355
response = unauthorized_test_client .patch (f"/pools/{ POOL1_NAME } " , params = {}, json = {})
315
356
assert response .status_code == 403
316
357
358
+ def test_patch_pool3_should_respond_200 (self , test_client , session ):
359
+ """Test patching POOL3 with forward slash in name"""
360
+ self .create_pools ()
361
+ body = {
362
+ "slots" : 10 ,
363
+ "description" : "Updated Description" ,
364
+ "name" : POOL3_NAME ,
365
+ "include_deferred" : True ,
366
+ }
367
+ response = test_client .patch (f"/pools/{ POOL3_NAME } " , json = body )
368
+ assert response .status_code == 200
369
+ expected_response = {
370
+ "deferred_slots" : 0 ,
371
+ "description" : "Updated Description" ,
372
+ "include_deferred" : True ,
373
+ "name" : "pool3/with_slashes" ,
374
+ "occupied_slots" : 0 ,
375
+ "open_slots" : 10 ,
376
+ "queued_slots" : 0 ,
377
+ "running_slots" : 0 ,
378
+ "scheduled_slots" : 0 ,
379
+ "slots" : 10 ,
380
+ }
381
+ assert response .json () == expected_response
382
+ check_last_log (session , dag_id = None , event = "patch_pool" , logical_date = None )
383
+
317
384
318
385
class TestPostPool (TestPoolsEndpoint ):
319
386
@pytest .mark .parametrize (
0 commit comments