photon: add a stable identifiant (#53984)
This commit is contained in:
parent
c738b8e70f
commit
a2bbf0eaea
|
@ -15,10 +15,13 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.http import urlencode
|
||||
from django.utils.six.moves.urllib import parse as urlparse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -92,8 +95,11 @@ class Photon(BaseResource):
|
|||
result['text'] += '%s ' % result['address']['postcode']
|
||||
if result['address'].get('city'):
|
||||
result['text'] += '%s' % result['address']['city']
|
||||
result['text'] = result['text'].strip()
|
||||
result['display_name'] = result['text']
|
||||
result['id'] = data['properties']['osm_id']
|
||||
|
||||
dict_dump = json.dumps(result['address'], sort_keys=True)
|
||||
result['id'] = hashlib.md5(force_bytes(dict_dump)).hexdigest()
|
||||
return result
|
||||
|
||||
@endpoint(
|
||||
|
|
|
@ -195,7 +195,7 @@ def test_photon_addresses(mocked_get, app, photon):
|
|||
assert data['lon'] == '4.8522272'
|
||||
assert data['display_name'] == '208, Rue Garibaldi 69003 Lyon 3ème Arrondissement'
|
||||
assert data['text'] == '208, Rue Garibaldi 69003 Lyon 3ème Arrondissement'
|
||||
assert data['id'] == 154419
|
||||
assert data['id'] == '2644ca352fdfef476b3f83ee99f0e8e5'
|
||||
assert data['address']['city'] == 'Lyon 3ème Arrondissement'
|
||||
assert data['address']['postcode'] == '69003'
|
||||
assert data['address']['road'] == 'Rue Garibaldi'
|
||||
|
@ -277,7 +277,7 @@ def test_photon_addresses_clean_cache(app, photon, freezer, mock_photon_search):
|
|||
assert AddressCacheModel.objects.count() == 2
|
||||
|
||||
freezer.move_to(datetime.timedelta(hours=1, seconds=1))
|
||||
app.get('/photon/%s/addresses?id=%s' % (photon.slug, '154419'))
|
||||
app.get('/photon/%s/addresses?id=%s' % (photon.slug, '2644ca352fdfef476b3f83ee99f0e8e5'))
|
||||
call_command('cron', 'hourly')
|
||||
assert AddressCacheModel.objects.count() == 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue