Projet

Général

Profil

0001-planitec-eventually-ignore-places-with-no-capacity-4.patch

Emmanuel Cazenave, 13 juillet 2020 17:23

Télécharger (5,1 ko)

Voir les différences:

Subject: [PATCH] planitec: eventually ignore places with no capacity (#45076)

If a filtering on capactiy is explicitly asked,
ignore places with no capacity.
 passerelle/contrib/planitech/models.py | 16 ++++++++++++----
 tests/test_planitech.py                | 20 +++++++++++++++++---
 2 files changed, 29 insertions(+), 7 deletions(-)
passerelle/contrib/planitech/models.py
37 37
from passerelle.utils.jsonresponse import APIError
38 38

  
39 39

  
40
DEFAULT_MIN_CAPACITY = 0
41
DEFAULT_MAX_CAPACITY = 100000
42

  
43

  
40 44
CREATE_RESERVATION_SCHEMA = {
41 45
    "$schema": "http://json-schema.org/draft-04/schema#",
42 46
    "title": "Planitech createreservation",
......
353 357
            cache.set(cache_key, ref)
354 358
        return ref
355 359

  
356
    def _get_places_referential(self, min_capacity=0, max_capacity=100000, **kwargs):
360
    def _get_places_referential(
361
            self, min_capacity=DEFAULT_MIN_CAPACITY, max_capacity=DEFAULT_MAX_CAPACITY, **kwargs
362
    ):
357 363

  
358 364
        ref = self._raw_get_places_referential()
359 365
        res = {}
......
365 371

  
366 372
        for place_id, place_data in ref.items():
367 373
            # Filter on capacity
368
            if 'capacity' in place_data:
374
            if min_capacity != DEFAULT_MIN_CAPACITY or max_capacity != DEFAULT_MAX_CAPACITY:
375
                if place_data.get('capacity') is None:
376
                    continue
369 377
                if place_data['capacity'] < min_capacity or place_data['capacity'] > max_capacity:
370 378
                    continue
371 379

  
......
636 644
            },
637 645
        })
638 646
    def getfreegaps(
639
            self, request, display, start_time, end_time, min_capacity=0, start_date=None,
640
            start_days=None, end_date=None, end_days=None, max_capacity=100000, weekdays=None,
647
            self, request, display, start_time, end_time, min_capacity=DEFAULT_MIN_CAPACITY, start_date=None,
648
            start_days=None, end_date=None, end_days=None, max_capacity=DEFAULT_MAX_CAPACITY, weekdays=None,
641 649
            place_id=None, **kwargs):
642 650

  
643 651
        # Additional parameters check
tests/test_planitech.py
360 360
            'placesList': [
361 361
                {'identifier': 1.0, 'label': 'salle 1'},
362 362
                {'identifier': 2.0, 'label': 'salle 2'},
363
                {'identifier': 3.0, 'label': 'salle 3'}
363
                {'identifier': 3.0, 'label': 'salle 3'},
364
                {'identifier': 4.0, 'label': 'salle 4'}
364 365
            ]
365 366
        },
366 367
        {
......
377 378
                {
378 379
                    'identifier': 3.0, 'capacity': 30.0,
379 380
                    'some_custom_field': 'Yes'
381
                },
382
                {
383
                    'identifier': 4.0, 'capacity': None
380 384
                }
381 385
            ]
382 386
        }
......
384 388
    mock_planitech(monkeypatch, side_effect=side_effect)
385 389
    response = app.get('/planitech/slug-planitech/getplacesreferential')
386 390
    expected_res = {
391
        '4': {
392
            'capacity': None, 'label': 'salle 4', 'identifier': 4,
393
            'street_number': None, 'address': None,
394
            'city': None, 'zipcode': None, 'some_custom_field': None
395
        },
387 396
        '3': {
388 397
            u'capacity': 30, u'label': u'salle 3', u'identifier': 3,
389 398
            'street_number': None, 'address': None,
......
435 444
    # Unkown filter filters nothing
436 445
    response = app.get('/planitech/slug-planitech/getplacesreferential?unkownfilter=foo')
437 446
    expected_res = {
447
        '4': {
448
            'capacity': None, 'label': 'salle 4', 'identifier': 4,
449
            'street_number': None, 'address': None,
450
            'city': None, 'zipcode': None, 'some_custom_field': None
451
        },
438 452
        '3': {
439 453
            u'capacity': 30, u'label': u'salle 3', u'identifier': 3,
440 454
            'street_number': None, 'address': None,
......
549 563

  
550 564
def test_getplaces_referential_use_cache(app, connector):
551 565
    cache_key = 'planitech-%s-places' % connector.id
552
    cache.set(cache_key, {'some': 'data'})
566
    cache.set(cache_key, {'some': {'data': 'foo'}})
553 567
    response = app.get('/planitech/slug-planitech/getplacesreferential')
554
    assert response.json_body['data'] == {'some': 'data'}
568
    assert response.json_body['data'] == {'some': {'data': 'foo'}}
555 569
    cache.delete(cache_key)
556 570

  
557 571

  
558
-