Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ def generate_items(self) -> None:

@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
location_info = request_params.location_info
street_num = location_info.get('street1')[0] if location_info.get('street1') else ''
items["data"]["text"] = {
"title": _("Pedestrian accidents by severity and year"),
"subtitle": _(request_params.location_text),
"subtitle": _(f"{location_info.get('yishuv_name')}, {location_info.get('street1_hrebew')} {street_num}"),
"labels": gen_entity_labels(InjurySeverity),
}
return items
Binary file added tests/mock_data_dictionary.pickle
Binary file not shown.
42 changes: 16 additions & 26 deletions tests/test_infographic_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import pytest
import pickle
import os
import anyway.request_params
import anyway.widgets.widget_utils as widget_utils

Expand All @@ -10,38 +12,19 @@
from anyway.app_and_db import db
from anyway.vehicle_type import VehicleCategory
from anyway.widgets.road_segment_widgets.accident_count_by_car_type_widget import AccidentCountByCarTypeWidget
from anyway.backend_constants import NewsflashLocationQualification


def insert_infographic_mock_data(app):
# Reading the mock data into the dictionary and only using the supported resolutions.
MOCK_DATA_DICTIONARY_PATH = os.path.join('tests','mock_data_dictionary.pickle')
with open(MOCK_DATA_DICTIONARY_PATH, 'rb') as f:
mock_data_dictionary = pickle.load(f).get('supported')

def insert_infographic_mock_data(app, values_str=mock_data_dictionary['orig']):
sql_insert = f"""
insert into news_flash
(accident, author, date, description, lat, link, lon, title, source, location, road1, road2, resolution,
tweet_id, district_hebrew, non_urban_intersection_hebrew, region_hebrew, road_segment_name, street1_hebrew, street2_hebrew, yishuv_name, newsflash_location_qualification, location_qualifying_user)
values (
true,
'ynet',
'2020-01-19 02:03:30',
'גבר בשנות ה-30 בחייו נהרג בתאונת דרכים בין רכב למשאית בכביש 90, סמוך למפגש הבקעה שבבקעת הירדן. הוא חולץ מרכבו שעלה באש ללא סימני חיים. נהג המשאית, גבר כבן 50, נפצע באורח קל. צוות מד"א פינה אותו לבית החולים העמק בעפולה.',
32.0554748,
'http://www.ynet.co.il/articles/0,7340,L-5662301,00.html',
35.4699107,
'גבר נהרג בתאונת דרכים עם משאית בכביש הבקעה',
'ynet',
'מפגש הבקעה שבבקעת הירדןסמוך לכביש 90, ',
90,
null,
'כביש בינעירוני',
null,
null,
null,
null,
'כניסה למצפה שלם - צומת שדי תרומות',
null,
null,
null,
{NewsflashLocationQualification.NOT_VERIFIED.value},
null) returning id;
values ({values_str}) returning id;
"""
insert_id = db.session.execute(sql_insert).fetchone()[0]
db.session.commit()
Expand Down Expand Up @@ -144,6 +127,13 @@ def mock_get_accidents_stats(table_obj, filters=None, group_by=None, count=None,
assert len(actual) == len(expected)
assert actual == expected

def test_different_resolutions(self, app):
for resolution in mock_data_dictionary:
inserted_id = insert_infographic_mock_data(app, values_str=mock_data_dictionary[resolution])
rv = app.get(f"/api/infographics-data?news_flash_id={inserted_id}")
delete_new_infographic_data(inserted_id)
assert(rv.status_code == http_client.OK)

def _get_widget_by_name(self, name):
if self.infographic_data is None:
self.infographic_data = get_infographic_data()
Expand Down