-
-
Notifications
You must be signed in to change notification settings - Fork 29
fix: test: Smart/Origin unit tests and various fixes #2116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
02574c4
e798b04
78809dd
dacb3ee
3129ac4
fec12b3
19c2da4
468136c
fb23ddd
adaeebd
dbb7763
af30a28
029bd4b
f38b991
3bb3318
7d3e912
249f7ae
4abff59
023db80
c922e2d
5880724
649fbdf
260c375
ce567e8
a3f3f8c
ec6e6ba
8b855f4
3f2d576
eee337f
226957b
7bca72f
64ecacf
80e4b57
d210b92
f591613
899a7a1
fc431ad
ebd713d
d5e56fd
3cfdb14
1a947c2
d28cae5
0ff3982
01b4b68
c7b5d10
fab54ce
170277a
8e1fa06
4db858f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,14 @@ def delete_waypoint_stopareas(connection, waypoint_id): | |
| def process_new_waypoint(mapper, connection, geometry): | ||
| """Processes a new waypoint to find its public transports after | ||
| inserting it into documents_geometries.""" | ||
|
|
||
| # When GHCI runs without access to GH secrets | ||
| # (eg. for PR triggered by dependabot) | ||
| # return immediatly by matching test key from .env | ||
| api_key = os.getenv("NAVITIA_API_KEY") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cela me paraît être une mauvaise pratique de changer le comportement du code en fonction de:
ça me paraît préférable de gérer ça au niveau des tests
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c'est exactement ce bout de code qui permet de gérer ça au niveau des tests : la fonction dans laquelle on se trouve est un trigger, et il n'est donc pas possible de l'exclure des tests directement puisqu'elle est appelée par alembic sur la création de waypoint.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. je précise que l'inconvénient, c'est que les tests avec la vraie clef consomment quelques requêtes navitia, même si c'est normalement assez peu |
||
| if api_key == "test-key": | ||
| return | ||
|
|
||
| # Check if document is a waypoint | ||
| waypoint_id = geometry.document_id | ||
|
|
||
|
|
@@ -147,7 +155,6 @@ def process_new_waypoint(mapper, connection, geometry): | |
| max_stop_area_for_1_waypoint = int( | ||
| os.getenv("MAX_STOP_AREA_FOR_1_WAYPOINT") | ||
| ) | ||
| api_key = os.getenv("NAVITIA_API_KEY") | ||
| max_duration = int(max_distance_waypoint_to_stoparea / walking_speed) | ||
|
|
||
| # increase number of retrieved stop areas, | ||
|
|
@@ -226,7 +233,7 @@ def process_new_waypoint(mapper, connection, geometry): | |
| stop_id = place["id"] | ||
|
|
||
| # Get informations of stopareas to know its transports | ||
| stop_info_url = "https://api.navitia.io/v1/places/%d", stop_id | ||
| stop_info_url = f"https://api.navitia.io/v1/places/{stop_id}" | ||
| stop_info_response = requests.get( | ||
| stop_info_url, headers=navitia_headers | ||
| ) | ||
|
|
@@ -619,8 +626,12 @@ def _update_route_duration(connection, route_id, calculated_duration_in_days): | |
| ), | ||
| {"duration": calculated_duration_in_days, "route_id": route_id}, | ||
| ) | ||
| if (calculated_duration_in_days is None): | ||
| calculated_duration_in_days_str = "None" | ||
| else: | ||
| calculated_duration_in_days_str = "%f", calculated_duration_in_days | ||
| log.info( | ||
| "Route %d: Database updated with calculated_duration = %f days.", | ||
| "Route %d: Database updated with calculated_duration = %s days.", | ||
| route_id, | ||
| calculated_duration_in_days | ||
| calculated_duration_in_days_str | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/usr/bin/env python | ||
| """ | ||
| Creates (or recreates) the ES index with the correct mappings. | ||
| Must be run before fill_index.py when building the index from scratch. | ||
|
|
||
| Usage: python create_index.py <config>.ini | ||
| """ | ||
| import sys | ||
| import logging | ||
|
|
||
| from pyramid.paster import get_appsettings, setup_logging | ||
| from pyramid.scripts.common import parse_vars | ||
|
|
||
| from c2corg_api.search import configure_es_from_config, elasticsearch_config, \ | ||
| search_documents | ||
| from c2corg_api.search.mapping import analysis_settings | ||
|
|
||
|
|
||
| def main(argv=sys.argv): | ||
| if len(argv) < 2: | ||
| print('Usage: %s <config_uri> [var=value]' % argv[0]) | ||
| sys.exit(1) | ||
|
|
||
| config_uri = argv[1] | ||
| options = parse_vars(argv[2:]) | ||
| setup_logging(config_uri) | ||
| logging.getLogger('sqlalchemy.engine').setLevel(logging.ERROR) | ||
|
|
||
| settings = get_appsettings(config_uri, options=options) | ||
| configure_es_from_config(settings) | ||
|
|
||
| client = elasticsearch_config['client'] | ||
| index_name = elasticsearch_config['index'] | ||
|
|
||
| # Delete index if it exists (to fix potentially wrong mappings) | ||
| if client.indices.exists(index=index_name): | ||
| print('Deleting existing index: {}'.format(index_name)) | ||
| client.indices.delete(index=index_name) | ||
|
|
||
| # Create index with analysis settings | ||
| print('Creating index: {}'.format(index_name)) | ||
| client.indices.create(index=index_name, body={ | ||
| 'settings': { | ||
| 'analysis': analysis_settings | ||
| } | ||
| }) | ||
|
|
||
| # Apply the correct mapping for every document type | ||
| # (if we let ES infer types by directly running fill_index.py, | ||
| # we could run into type errors on some fields like | ||
| # a mapping geom -> double instead of geo_point). | ||
| for doc_type, search_class in search_documents.items(): | ||
| print('Applying mapping for doc_type: {}'.format(doc_type)) | ||
| search_class._doc_type.mapping.save(index_name) | ||
|
|
||
| print('Done. Index "{}" created with correct mappings.'.format(index_name)) | ||
| print('You can now run fill_index.py safely.') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Les tests devraient tourner de la même manière, qui que ce soit qui fasse la PR
Il faudrait trouver une manière de lancer les tests navitia sans que la pipeline nécessite le secret de navitia
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ce n'est pas vraiment possible de tester l'API sans clef d'accès... Et cette différence est due à votre bot qui pour une raison que j'ignore ne peut pas avoir accès au secret. On peut toujours enlever les tests qui nécessitent la clef si vous le demandez.