Skip to content

Commit e242d3c

Browse files
committed
Refactor tests
1 parent c314aac commit e242d3c

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

tests/integration/test_labor.py

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,23 @@ def wrapper(*args, **kwargs):
3737

3838

3939
@retry_with_backoff()
40-
def create_team_member() -> str:
40+
def get_first_team_member() -> str:
4141
client = helpers.test_client()
4242

43-
team_response = client.team_members.create(
44-
idempotency_key=str(uuid.uuid4()),
45-
team_member={"given_name": "Sherlock", "family_name": "Holmes"},
43+
# Search for active team members at the default location
44+
team_response = client.team_members.search(
45+
query={
46+
"filter": {
47+
"location_ids": [helpers.get_default_location_id(client)],
48+
"status": "ACTIVE"
49+
}
50+
},
4651
request_options=RequestOptions(timeout_in_seconds=MAX_TIMEOUT),
4752
)
48-
team_member = team_response.team_member
53+
if not team_response.team_members or len(team_response.team_members) == 0:
54+
raise Exception(f"No team members available at location {helpers.get_default_location_id(client)}")
55+
56+
team_member = team_response.team_members[0]
4957
assert team_member is not None
5058
assert isinstance(team_member, TeamMember)
5159
assert team_member.id is not None
@@ -138,7 +146,7 @@ def test_get_break_type():
138146
time.sleep(3)
139147

140148
client = helpers.test_client()
141-
team_member_id = create_team_member()
149+
team_member_id = get_first_team_member()
142150
time.sleep(2) # Add delay between operations
143151
break_type_id = create_break_type()
144152
time.sleep(2) # Add delay between operations
@@ -166,7 +174,7 @@ def test_get_break_type():
166174
@retry_with_backoff()
167175
def test_update_break_type():
168176
client = helpers.test_client()
169-
team_member_id = create_team_member()
177+
team_member_id = get_first_team_member()
170178
time.sleep(2) # Add delay between operations
171179
break_type_id = create_break_type()
172180
time.sleep(2) # Add delay between operations
@@ -195,7 +203,7 @@ def test_update_break_type():
195203
@retry_with_backoff()
196204
def test_search_shifts():
197205
client = helpers.test_client()
198-
team_member_id = create_team_member()
206+
team_member_id = get_first_team_member()
199207
time.sleep(2) # Add delay between operations
200208
break_type_id = create_break_type()
201209
time.sleep(2) # Add delay between operations
@@ -216,7 +224,7 @@ def test_search_shifts():
216224
@retry_with_backoff()
217225
def test_get_shift():
218226
client = helpers.test_client()
219-
team_member_id = create_team_member()
227+
team_member_id = get_first_team_member()
220228
time.sleep(2) # Add delay between operations
221229
break_type_id = create_break_type()
222230
time.sleep(2) # Add delay between operations
@@ -238,7 +246,7 @@ def test_get_shift():
238246
@retry_with_backoff()
239247
def test_update_shift():
240248
client = helpers.test_client()
241-
team_member_id = create_team_member()
249+
team_member_id = get_first_team_member()
242250
time.sleep(2) # Add delay between operations
243251
break_type_id = create_break_type()
244252
time.sleep(2) # Add delay between operations
@@ -278,23 +286,37 @@ def test_update_shift():
278286
def test_delete_shift():
279287
client = helpers.test_client()
280288

281-
team_member_response = client.team_members.create(
282-
idempotency_key=str(uuid.uuid4()),
283-
team_member={"given_name": "Sherlock", "family_name": "Holmes"},
289+
# Search for existing shifts for this team member
290+
team_member_id = get_first_team_member()
291+
292+
# Search for existing shifts
293+
existing_shifts = client.labor.shifts.search(
294+
query={
295+
"filter": {
296+
"team_member_ids": [team_member_id]
297+
}
298+
},
299+
limit=100,
284300
request_options=RequestOptions(timeout_in_seconds=MAX_TIMEOUT),
285301
)
286302

287-
assert team_member_response.team_member is not None
288-
assert isinstance(team_member_response.team_member, TeamMember)
289-
assert team_member_response.team_member.id is not None
303+
# Delete any existing shifts
304+
if existing_shifts.shifts:
305+
for shift in existing_shifts.shifts:
306+
if shift.id:
307+
delete_shift(shift.id)
290308

291-
time.sleep(2) # Add delay between operations
309+
# Start the shift 10 seconds from now and end it 20 seconds from now
310+
start_time = datetime.now() + timedelta(seconds=10)
311+
end_time = start_time + timedelta(seconds=10)
292312

313+
# Create shift
293314
shift_response = client.labor.shifts.create(
294315
shift={
295316
"location_id": helpers.get_default_location_id(client),
296-
"start_at": helpers.format_date_string(datetime.now()),
297-
"team_member_id": team_member_response.team_member.id,
317+
"start_at": helpers.format_date_string(start_time),
318+
"end_at": helpers.format_date_string(end_time),
319+
"team_member_id": team_member_id,
298320
},
299321
idempotency_key=str(uuid.uuid4()),
300322
request_options=RequestOptions(timeout_in_seconds=MAX_TIMEOUT),
@@ -305,7 +327,7 @@ def test_delete_shift():
305327
assert shift_response.shift.id is not None
306328
shift_id = shift_response.shift.id
307329

308-
time.sleep(2) # Add delay before delete
330+
time.sleep(1) # Add small delay to ensure the shift is fully created
309331

310332
response = client.labor.shifts.delete(
311333
id=shift_id,

0 commit comments

Comments
 (0)