def permissive_restriction(new_user): start_time = datetime.datetime.utcnow() - timedelta(days=10) end_time = None restriction = Restriction(name='PermissiveRestriction', starts_at=start_time, ends_at=end_time, is_global=True) restriction.apply_to_user(new_user) restriction.save() return restriction
def test_create_reservation_that_is_covered_by_two_separate_restrictions( tables, client, new_user): r1_start = '2101-01-01T00:00:00.000Z' r1_end = '2101-01-02T00:00:00.000Z' r2_start = '2101-01-02T00:00:00.000Z' r2_end = '2101-01-02T23:59:00.000Z' r1 = Restriction(name='FirstRestriction', starts_at=r1_start, ends_at=r1_end, is_global=False) r2 = Restriction(name='SecondRestriction', starts_at=r2_start, ends_at=r2_end, is_global=False) new_user.save() r1.apply_to_user(new_user) r2.apply_to_user(new_user) resource = Resource(id='0123456789012345678901234567890123456789') resource.save() r1.apply_to_resource(resource) r2.apply_to_resource(resource) data = { 'title': 'Test reservation', 'description': 'Test reservation', 'resourceId': '0123456789012345678901234567890123456789', 'userId': new_user.id, 'start': '2101-01-01T10:00:00.000Z', 'end': '2101-01-02T12:00:00.000Z' } resp = client.post(ENDPOINT, headers=HEADERS, data=json.dumps(data)) resp_json = json.loads(resp.data.decode('utf-8')) assert resp.status_code == HTTPStatus.CREATED assert Reservation.get(resp_json['reservation']['id']) is not None