Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #612 from StartupsPoleEmploi/fix/PELBB-11/api-empt…
Browse files Browse the repository at this point in the history
…y-url

fix: PELBB-11: empty api result return a valid url
  • Loading branch information
lmarvaud authored Feb 9, 2022
2 parents ee52c02 + 90a3798 commit 67d8d5c
Show file tree
Hide file tree
Showing 8 changed files with 622 additions and 91 deletions.
19 changes: 9 additions & 10 deletions labonneboite/common/es.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
import random
import string
from datetime import datetime
from typing import Optional

import elasticsearch

Expand All @@ -12,10 +13,10 @@


class ConnectionPool(object):
ELASTICSEARCH_INSTANCE = None
ELASTICSEARCH_INSTANCE: Optional[elasticsearch.Elasticsearch] = None


def Elasticsearch():
def Elasticsearch() -> elasticsearch.Elasticsearch:
"""
Elasticsearch client singleton. All connections to ES should go through
this client, so that we can reuse ES connections and not flood ES with new
Expand All @@ -26,15 +27,12 @@ def Elasticsearch():
return ConnectionPool.ELASTICSEARCH_INSTANCE


def new_elasticsearch_instance():
def new_elasticsearch_instance() -> elasticsearch.Elasticsearch:
"""
In some cases e.g. parallel jobs you may need a dedicated es connection for each
of your threads.
"""
return elasticsearch.Elasticsearch(
hosts=[settings.ES_HOST],
timeout=settings.ES_TIMEOUT
)
return elasticsearch.Elasticsearch(hosts=[settings.ES_HOST], timeout=settings.ES_TIMEOUT)


def drop_and_create_index():
Expand Down Expand Up @@ -182,7 +180,7 @@ def create_index(index):
"type": "string",
"index": "not_analyzed",
},
"autocomplete" : {
"autocomplete": {
"type": "string",
"analyzer": "autocomplete",
},
Expand Down Expand Up @@ -283,7 +281,7 @@ def create_index(index):
},
},
},
"mappings": {
"mappings": {
"ogr": mapping_ogr,
"location": mapping_location,
"office": mapping_office,
Expand All @@ -295,6 +293,7 @@ def create_index(index):
fake_doc = fake_office()
Elasticsearch().index(index=index, doc_type=OFFICE_TYPE, id=fake_doc['siret'], body=fake_doc)


# This fake office having a zero but existing score for each rome is designed
# as a workaround of the following bug:
#
Expand Down
144 changes: 68 additions & 76 deletions labonneboite/tests/web/api/test_api.py

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions labonneboite/web/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ def compute_frontend_url(fetcher, query_string, commune_id, departments):
Compute web page URL that corresponds to the API request.
"""

if not fetcher.office_count >= 1:
# Always return home URL if zero results
# (requested by PE.fr)
return url_for('root.home', _external=True, **query_string)

if fetcher.romes:
# preserve parameters from original API request
if fetcher.naf_codes:
Expand Down
123 changes: 123 additions & 0 deletions requirements.dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
-r requirements.txt

# dev tools
flake8
flake8-pylint
coverage
isort
flake8-mypy
mypy
yapf
pytest
pytest-env

# Development tools.
Flask-DebugToolbar
ipdb
ipython
pylint
pip-tools

# testing
# locust

##########
# typing #
##########
types-Flask<0.13
# *missing*: types-Flask-Script

### Flask assets.
# *missing*: types-Flask-Assets
# *missing*: types-Flask-cors
# *missing*: types-cssmin
# *missing*: types-jsmin

### Forms.
# *missing*: types-Flask-WTF
# *missing*: types-WTForms

### Flask admin.
# *missing*: types-Flask-Admin

### Localization With Flask-Babelex.
### http://flask-admin.readthedocs.io/en/latest/advanced/#localization-with-flask-babelex
# *missing*: types-Flask-BabelEx
# *missing*: types-speaklater

### Development tools.
# *missing*: types-Flask-DebugToolbar
# *missing*: types-ipdb
# *missing*: types-ipython
# *missing*: types-pylint
# *missing*: types-pip-tools

### profiling tools used in create_index.py
### pycallgraph
# *missing*: types-pyprof2calltree
# *missing*: types-line-profiler
# *missing*: types-sentry-sdk>0.20.0

### Databases and migrations.
# *missing*: types-alembic
types-mysqlclient
# *missing*: types-SQLAlchemy-Utils
sqlalchemy2-stubs

### Elasticsearch
### as of Jan 2018 we are using Elasticsearch 1.7, a very old version.
### According to http://elasticsearch-py.readthedocs.io/en/master/index.html
### we should thus use the major 1.x.y version of the python library.
### To figure out which 1.x.y version is the latest, run:
### pip install --upgrade "elasticsearch>=1.0.0,<2.0.0"
elasticsearch-stubs<2.0.0

### Users and auth management.
# *missing*: types-Flask-Login
# *missing*: types-social-auth-app-flask-sqlalchemy
# *missing*: types-social-auth-app-flask
# *missing*: types-social-auth-core[openidconnect]

### Unit tests.
# *missing*: types-nose
types-selenium
# *missing*: types-PyVirtualDisplay
# *missing*: types-Flask-Testing
# *missing*: types-parameterized

### Data and Importer.
# *missing*: types-numpy
pandas-stubs
# *missing*: types-scikit-learn
# *missing*: types-scipy

### PDF utils and dependencies.
types-html5lib
# *missing*: types-xhtml2pdf

### Utils.
### *missing*: types-gevent # only used by geocode importer job and locust load testing
types-python-slugify
types-requests
# *missing*: types-validators
# *missing*: types-geopy
# *missing*: types-mailjet_rest
types-cryptography

### Deployment and production
# *missing*: types-uWSGI
# *missing*: types-uwsgitop
# *missing*: types-raven[flask]

### Load testing.
# *missing*: types-locustio
# *missing*: types-pyzmq
# *missing*: types-remote-pdb

#Fix markupsafe issue 1.0
types-markupsafe==1.1.1

#Impact retour emploi.
# *Could not find a version that matches*: google-api-python-client-stubs
# *missing*: types-google-auth-httplib2
# *missing*: types-google-auth-oauthlib
163 changes: 163 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements.dev.txt requirements.dev.in
#
alembic==0.9.10
astroid==1.6.5
attrs==21.4.0 # via flake8-mypy, pytest
babel==2.6.0
backcall==0.1.0
blinker==1.4
cachetools==4.0.0
certifi==2017.4.17
cffi==1.13.1
chardet==3.0.4
click==6.7
coverage==6.2
cryptography==2.8
cssmin==0.2.0
decorator==4.3.0
defusedxml==0.5.0
easyprocess==0.3
elasticsearch-stubs==0
elasticsearch==1.9.0
first==2.0.1
flake8-mypy==17.8.0
flake8-pylint==0.1.3
flake8==4.0.1
flask-admin==1.5.3
flask-assets==0.12
flask-babelex==0.9.3
flask-cors==3.0.7
flask-debugtoolbar==0.10.1
flask-login==0.4.1
flask-script==2.0.6
flask-testing==0.7.1
flask-wtf==0.14.2
flask==0.12.4
future==0.16.0
geographiclib==1.49
geopy==1.19.0
gevent==1.1.1
google-api-python-client==1.7.11
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.4.1
google-auth==1.11.0
greenlet==0.4.12
html5lib==1.0.1
httplib2==0.11.3
idna==2.5
importlib-metadata==4.2.0 # via flake8, pluggy, pytest
iniconfig==1.1.1 # via pytest
ipdb==0.13.9
ipython-genutils==0.2.0
ipython==7.16.1
isort==4.2.15
itsdangerous==0.24
jedi==0.12.0
jinja2==2.10.1
jsmin==3.0.0
lazy-object-proxy==1.3.1
line-profiler==2.0
locustio==0.7.5
mailjet-rest==1.3.3
mako==1.0.7
markupsafe==1.1.1
mccabe==0.6.1
msgpack-python==0.5.6
mypy-extensions==0.4.3 # via mypy
mypy==0.931
mysqlclient==1.4.2.post1
nose==1.3.7
numpy==1.16.1
oauthlib==2.0.2
packaging==21.3 # via pytest
pandas-stubs==1.2.0.40
pandas==0.22.0
parameterized==0.7.0
parso==0.2.1
pexpect==4.6.0
pickleshare==0.7.4
pillow==6.0.0
pip-tools==2.0.2
pluggy==1.0.0 # via pytest
prompt-toolkit==3.0.21
ptyprocess==0.6.0
py==1.11.0 # via pytest
pyasn1-modules==0.2.8
pyasn1==0.4.8
pycodestyle==2.8.0 # via flake8
pycparser==2.19
pycryptodomex==3.6.3
pyflakes==2.4.0 # via flake8
pygments==2.2.0
pyjwkest==1.4.0
pyjwt==1.5.2
pylint==1.9.2
pyparsing==3.0.6 # via packaging
pypdf2==1.26.0
pyprof2calltree==1.4.3
pytest-env==0.6.2
pytest==6.2.5
python-dateutil==2.6.1
python-editor==1.0.3
python-slugify==1.2.5
python3-openid==3.1.0
pytz==2017.2
pyvirtualdisplay==2.2
pyzmq==16.0.2
raven[flask]==6.9.0
remote-pdb==1.3.0
reportlab==3.5.21
requests-oauthlib==0.8.0
requests==2.21.0
rsa==4.0
scikit-learn==0.16.1
scipy==1.2.1
selenium==3.141.0
sentry-sdk==0.20.3
six==1.10.0
social-auth-app-flask-sqlalchemy==1.0.1
social-auth-app-flask==1.0.0
social-auth-core[openidconnect]==1.4.0
social-auth-storage-sqlalchemy==1.1.0
speaklater==1.3
sqlalchemy-utils==0.32.13
sqlalchemy2-stubs==0.0.2a19
sqlalchemy==1.3.3
toml==0.10.2
tomli==1.2.3 # via mypy
traitlets==4.3.2
typed-ast==1.5.1 # via mypy
types-click==7.1.8 # via types-flask
types-cryptography==3.3.12
types-enum34==1.1.2 # via types-cryptography
types-flask==0.1.2
types-html5lib==1.1.5
types-ipaddress==1.0.2 # via types-cryptography
types-jinja2==2.11.9 # via types-flask
types-markupsafe==1.1.1
types-mysqlclient==2.0.4
types-python-slugify==5.0.3
types-requests==2.27.6
types-selenium==3.141.7
types-urllib3==1.26.6 # via types-requests
types-werkzeug==1.0.9 # via types-flask
typing-extensions==4.0.1 # via importlib-metadata, mypy, pandas-stubs, sqlalchemy2-stubs
unidecode==0.4.21
uritemplate==3.0.1
urllib3==1.24.3
uwsgi==2.0.18
uwsgitop==0.11
validators==0.11.2
wcwidth==0.1.7
webassets==0.12.1
webencodings==0.5.1
werkzeug==0.11.10
wrapt==1.10.10
wtforms==2.1
xhtml2pdf==0.2.2
yapf==0.32.0
zipp==3.6.0
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ alembic
mysqlclient
SQLAlchemy-Utils
SQLAlchemy
zipp<3.7.0 # No matching distribution found for zipp==3.7.0

# Elasticsearch
# as of Jan 2018 we are using Elasticsearch 1.7, a very old version.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ werkzeug==0.11.10 # via flask, flask-debugtoolbar
wrapt==1.10.10 # via astroid
wtforms==2.1
xhtml2pdf==0.2.2
zipp==3.6.0
Loading

0 comments on commit 67d8d5c

Please # to comment.