round 3
This commit is contained in:
@@ -125,9 +125,9 @@ def test_list_child_tasks_returns_tasks(client):
|
||||
resp = client.get('/child/child_list_1/list-tasks')
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
returned_ids = {t['id'] for t in data['child_tasks']}
|
||||
returned_ids = {t['id'] for t in data['tasks']}
|
||||
assert returned_ids == {'t_list_1', 't_list_2'}
|
||||
for t in data['child_tasks']:
|
||||
for t in data['tasks']:
|
||||
assert 'name' in t and 'points' in t and 'is_good' in t
|
||||
|
||||
def test_list_assignable_tasks_returns_expected_ids(client):
|
||||
@@ -143,8 +143,8 @@ def test_list_assignable_tasks_returns_expected_ids(client):
|
||||
resp = client.get(f'/child/{child_id}/list-assignable-tasks')
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
assert len(data['assignable_tasks']) == 1
|
||||
assert data['assignable_tasks'][0]['id'] == 'tB'
|
||||
assert len(data['tasks']) == 1
|
||||
assert data['tasks'][0]['id'] == 'tB'
|
||||
assert data['count'] == 1
|
||||
|
||||
def test_list_assignable_tasks_when_none_assigned(client):
|
||||
@@ -158,7 +158,7 @@ def test_list_assignable_tasks_when_none_assigned(client):
|
||||
resp = client.get(f'/child/{child_id}/list-assignable-tasks')
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
returned_ids = {t['id'] for t in data['assignable_tasks']}
|
||||
returned_ids = {t['id'] for t in data['tasks']}
|
||||
assert returned_ids == set(ids)
|
||||
assert data['count'] == len(ids)
|
||||
|
||||
@@ -170,10 +170,60 @@ def test_list_assignable_tasks_empty_task_db(client):
|
||||
resp = client.get(f'/child/{child_id}/list-assignable-tasks')
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
assert data['assignable_tasks'] == []
|
||||
assert data['tasks'] == []
|
||||
assert data['count'] == 0
|
||||
|
||||
def test_list_assignable_tasks_child_not_found(client):
|
||||
resp = client.get('/child/does-not-exist/list-assignable-tasks')
|
||||
assert resp.status_code == 404
|
||||
assert b'Child not found' in resp.data
|
||||
|
||||
def setup_child_with_tasks(child_name='TestChild', age=8, assigned=None):
|
||||
child_db.truncate()
|
||||
task_db.truncate()
|
||||
assigned = assigned or []
|
||||
# Seed tasks
|
||||
task_db.insert({'id': 't1', 'name': 'Task 1', 'points': 1, 'is_good': True})
|
||||
task_db.insert({'id': 't2', 'name': 'Task 2', 'points': 2, 'is_good': False})
|
||||
task_db.insert({'id': 't3', 'name': 'Task 3', 'points': 3, 'is_good': True})
|
||||
# Seed child
|
||||
child = Child(name=child_name, age=age, image_id='boy01').to_dict()
|
||||
child['tasks'] = assigned[:]
|
||||
child_db.insert(child)
|
||||
return child['id']
|
||||
|
||||
def test_list_all_tasks_partitions_assigned_and_assignable(client):
|
||||
child_id = setup_child_with_tasks(assigned=['t1', 't3'])
|
||||
resp = client.get(f'/child/{child_id}/list-all-tasks')
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
assigned_ids = {t['id'] for t in data['assigned_tasks']}
|
||||
assignable_ids = {t['id'] for t in data['assignable_tasks']}
|
||||
assert assigned_ids == {'t1', 't3'}
|
||||
assert assignable_ids == {'t2'}
|
||||
assert data['assigned_count'] == 2
|
||||
assert data['assignable_count'] == 1
|
||||
|
||||
def test_set_child_tasks_replaces_existing(client):
|
||||
child_id = setup_child_with_tasks(assigned=['t1', 't2'])
|
||||
# Provide new set including a valid and an invalid id (invalid should be filtered)
|
||||
payload = {'task_ids': ['t3', 'missing', 't3']}
|
||||
resp = client.put(f'/child/{child_id}/set-tasks', json=payload)
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
assert data['task_ids'] == ['t3']
|
||||
assert data['count'] == 1
|
||||
ChildQuery = Query()
|
||||
child = child_db.get(ChildQuery.id == child_id)
|
||||
assert child['tasks'] == ['t3']
|
||||
|
||||
def test_set_child_tasks_requires_list(client):
|
||||
child_id = setup_child_with_tasks(assigned=['t2'])
|
||||
resp = client.put(f'/child/{child_id}/set-tasks', json={'task_ids': 'not-a-list'})
|
||||
assert resp.status_code == 400
|
||||
assert b'task_ids must be a list' in resp.data
|
||||
|
||||
def test_set_child_tasks_child_not_found(client):
|
||||
resp = client.put('/child/does-not-exist/set-tasks', json={'task_ids': ['t1', 't2']})
|
||||
assert resp.status_code == 404
|
||||
assert b'Child not found' in resp.data
|
||||
|
||||
Reference in New Issue
Block a user