0001-grandlyon-street-sections-favor-troncon-with-explici.patch
passerelle/contrib/grandlyon_streetsections/models.py | ||
---|---|---|
29 | 29 |
'Vaulx-en-Velin': 'VAULX' |
30 | 30 |
} |
31 | 31 | |
32 |
DEFAULT_MIN = 0 |
|
33 |
DEFAULT_MAX = 99999 |
|
34 | ||
35 | ||
32 | 36 |
def normalize_street(street): |
33 | 37 |
return slugify(re.sub(r"[' ()-]", ' ', street)) |
34 | 38 | |
... | ... | |
78 | 82 |
# if no streetnumber, use the first section (it may happen street |
79 | 83 |
# number 1 doesn't exist, ex: rue des cuirassiers). |
80 | 84 |
streetnumber = sections[0].bornemindroite if len(sections) else 1 |
85 | ||
86 |
default_match = None |
|
81 | 87 |
for section in sections: |
82 | 88 |
if streetnumber < section.bornemindroite and streetnumber < section.bornemingauche: |
83 | 89 |
continue |
... | ... | |
89 | 95 |
# remove districts from commune name |
90 | 96 |
nomcommune = 'LYON' |
91 | 97 | |
92 |
return {
|
|
98 |
match = {
|
|
93 | 99 |
'err': 0, |
94 | 100 |
'data': { |
95 | 101 |
'domanialite': section.domanialite, |
... | ... | |
101 | 107 |
'codeinsee': section.codeinsee, |
102 | 108 |
} |
103 | 109 |
} |
110 |
if DEFAULT_MIN in (section.bornemindroite, section.bornemingauche) or \ |
|
111 |
DEFAULT_MAX in (section.bornemaxdroite, section.bornemaxgauche): |
|
112 |
default_match = match |
|
113 |
continue |
|
114 | ||
115 |
return match |
|
116 | ||
117 |
if default_match: |
|
118 |
return default_match |
|
119 | ||
104 | 120 |
return {'err': 1} |
105 | 121 | |
106 | 122 |
def daily(self): |
... | ... | |
119 | 135 |
'gid'): |
120 | 136 |
if value.get(attribute) == 'None': |
121 | 137 |
if 'min' in attribute: |
122 |
attribute_value = 0
|
|
138 |
attribute_value = DEFAULT_MIN
|
|
123 | 139 |
elif 'max' in attribute: |
124 |
attribute_value = 99999
|
|
140 |
attribute_value = DEFAULT_MAX
|
|
125 | 141 |
else: |
126 | 142 |
attribute_value = None |
127 | 143 |
else: |
tests/test_grandlyon_streetsections.py | ||
---|---|---|
1 | ||
2 |
from django.contrib.contenttypes.models import ContentType |
|
3 |
import pytest |
|
4 | ||
5 |
from passerelle.base.models import ApiUser, AccessRight |
|
6 |
from passerelle.contrib.grandlyon_streetsections.models import ( |
|
7 |
GrandLyonStreetSections, StreetSection, normalize_street |
|
8 |
) |
|
9 | ||
10 | ||
11 |
@pytest.fixture() |
|
12 |
def connector(db): |
|
13 |
api = ApiUser.objects.create(username='all', keytype='', key='') |
|
14 |
connector = GrandLyonStreetSections.objects.create(slug='gl-streetsections') |
|
15 |
obj_type = ContentType.objects.get_for_model(connector) |
|
16 |
AccessRight.objects.create( |
|
17 |
codename='can_access', apiuser=api, resource_type=obj_type, resource_pk=connector.pk) |
|
18 |
return connector |
|
19 | ||
20 | ||
21 |
def test_partial_bornes(app, connector): |
|
22 |
name = "Rue d'Essling" |
|
23 |
normalized_name = normalize_street(name) |
|
24 |
codefuv = '27862' |
|
25 |
codeinsee = '69383' |
|
26 |
nomcommune = 'LYON 3' |
|
27 |
StreetSection.objects.create( |
|
28 |
nom=normalized_name, |
|
29 |
nomcommune=nomcommune, |
|
30 |
codefuv=codefuv, |
|
31 |
codeinsee=codeinsee, |
|
32 |
codetroncon='T3162', |
|
33 |
bornemingauche=0, |
|
34 |
bornemaxgauche=99999, |
|
35 |
bornemindroite=14, |
|
36 |
bornemaxdroite=14, |
|
37 |
) |
|
38 |
StreetSection.objects.create( |
|
39 |
nom=normalized_name, |
|
40 |
nomcommune=nomcommune, |
|
41 |
codefuv=codefuv, |
|
42 |
codeinsee=codeinsee, |
|
43 |
codetroncon='T27587', |
|
44 |
bornemingauche=0, |
|
45 |
bornemaxgauche=99999, |
|
46 |
bornemindroite=0, |
|
47 |
bornemaxdroite=99999, |
|
48 |
) |
|
49 |
StreetSection.objects.create( |
|
50 |
nom=normalized_name, |
|
51 |
nomcommune=nomcommune, |
|
52 |
codefuv=codefuv, |
|
53 |
codeinsee=codeinsee, |
|
54 |
codetroncon='T3165', |
|
55 |
bornemingauche=19, |
|
56 |
bornemaxgauche=21, |
|
57 |
bornemindroite=16, |
|
58 |
bornemaxdroite=26, |
|
59 |
) |
|
60 | ||
61 |
response = app.get( |
|
62 |
"/grandlyon-streetsections/gl-streetsections/section_info" |
|
63 |
"?streetname=Rue d'Essling&commune=Lyon&streetnumber=20" |
|
64 |
) |
|
65 |
assert response.json['err'] == 0 |
|
66 |
assert response.json['data']['codetroncon'] == 'T3165' |
|
0 |
- |