Merge immortal/main into audit branch
This commit is contained in:
+46
-10
@@ -92,7 +92,7 @@ class TestPlayerAvailability:
|
||||
assert PlayerDisponibility.query.count() == 0
|
||||
|
||||
|
||||
class TestBulkAvailabilityReportsWhatItDropped:
|
||||
class TestBulkAvailabilityReplacementIsAtomic:
|
||||
def test_valid_slots_are_saved(self, app, client, as_role):
|
||||
from app.models import PlayerDisponibility
|
||||
|
||||
@@ -107,28 +107,64 @@ class TestBulkAvailabilityReportsWhatItDropped:
|
||||
with app.app_context():
|
||||
assert PlayerDisponibility.query.count() == 1
|
||||
|
||||
def test_a_dropped_slot_is_named(self, app, client, as_role):
|
||||
"""It used to `continue` and answer success, so the client could not
|
||||
tell nine saved from ten sent."""
|
||||
def test_a_good_payload_replaces_the_slots(self, app, client, as_role):
|
||||
from app.models import PlayerDisponibility
|
||||
|
||||
as_role('player')
|
||||
player_id = as_role('player')
|
||||
client.post(
|
||||
'/users/disponibilities/add_bulk',
|
||||
json={'slots': [{'day_of_week': 1, 'start_time': '09:00'}]},
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
'/users/disponibilities/add_bulk',
|
||||
json={'slots': [{'day_of_week': 3, 'start_time': '18:00'}]},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
with app.app_context():
|
||||
slots = PlayerDisponibility.query.filter_by(player_id=player_id).all()
|
||||
assert [(s.day_of_week, s.start_time) for s in slots] == [(3, time(18, 0))]
|
||||
|
||||
def test_an_empty_payload_clears_the_slots(self, app, client, as_role):
|
||||
from app.models import PlayerDisponibility
|
||||
|
||||
player_id = as_role('player')
|
||||
client.post(
|
||||
'/users/disponibilities/add_bulk',
|
||||
json={'slots': [{'day_of_week': 1, 'start_time': '09:00'}]},
|
||||
)
|
||||
|
||||
response = client.post('/users/disponibilities/add_bulk', json={'slots': []})
|
||||
|
||||
assert response.status_code == 200
|
||||
with app.app_context():
|
||||
assert PlayerDisponibility.query.filter_by(player_id=player_id).count() == 0
|
||||
|
||||
def test_a_malformed_slot_changes_nothing(self, app, client, as_role):
|
||||
from app.models import PlayerDisponibility
|
||||
|
||||
player_id = as_role('player')
|
||||
client.post(
|
||||
'/users/disponibilities/add_bulk',
|
||||
json={'slots': [{'day_of_week': 1, 'start_time': '09:00'}]},
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
'/users/disponibilities/add_bulk',
|
||||
json={
|
||||
'slots': [
|
||||
{'day_of_week': 1, 'start_time': '09:00'},
|
||||
{'day_of_week': 3, 'start_time': '18:00'},
|
||||
{'day_of_week': 1, 'start_time': 'nope'},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
body = response.get_json()
|
||||
assert len(body['created']) == 1
|
||||
assert len(body['rejected']) == 1, 'the caller must learn a slot was dropped'
|
||||
assert response.status_code == 400
|
||||
assert len(response.get_json()['rejected']) == 1
|
||||
with app.app_context():
|
||||
assert PlayerDisponibility.query.count() == 1
|
||||
slots = PlayerDisponibility.query.filter_by(player_id=player_id).all()
|
||||
assert [(s.day_of_week, s.start_time) for s in slots] == [(1, time(9, 0))]
|
||||
|
||||
|
||||
class TestCoachAvailabilityIsNotWipedByABadPayload:
|
||||
|
||||
Reference in New Issue
Block a user