Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ziv17 committed Dec 9, 2023
1 parent 26ff3b6 commit abb0887
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions anyway/widgets/widget_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_query(table_obj, filters, start_time, end_time):
location_fields, other_fields = split_location_fields_and_others(filters)
if other_fields:
query = query.filter(get_expression_for_fields(filters, table_obj, and_))
query = query.filter(get_expression_for_location_fields(location_fields, table_obj))
query = query.filter(get_expression_for_road_segment_location_fields(location_fields, table_obj))
return query


Expand All @@ -45,7 +45,7 @@ def get_expression_for_fields(filters, table_obj, op):


# todo: remove road_segment_name if road_segment_id exists.
def get_expression_for_location_fields(filters, table_obj):
def get_expression_for_road_segment_location_fields(filters, table_obj):
ex = get_expression_for_fields(filters, table_obj, and_)
segment_id = filters["road_segment_id"]
junctions_ex = get_expression_for_segment_junctions(segment_id, table_obj)
Expand Down
13 changes: 11 additions & 2 deletions tests/test_infographics_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import unittest
from anyway.widgets.widget_utils import format_2_level_items, get_query, get_filter_expression
from unittest.mock import patch
from anyway.widgets.widget_utils import (format_2_level_items, get_query, get_filter_expression,
get_expression_for_segment_junctions)
from anyway.backend_constants import AccidentSeverity
from anyway.models import AccidentMarkerView

Expand Down Expand Up @@ -53,7 +55,7 @@ def test_get_filter_expression(self):
actual = get_filter_expression(AccidentMarkerView, "road_segment_name", "seg1")
self.assertEqual('markers_hebrew.road_segment_name', str(actual.left), "1")
self.assertEqual('seg1', actual.right.value, "2")
actual = get_filter_expression(AccidentMarkerView, "street1_hebrew", "s1")
actual = get_filter_expression(AccidentMarkerView, "street1_hebrew", ["s1"])
self.assertEqual(2, len(actual.expression.clauses), "3")
self.assertEqual('markers_hebrew.street1_hebrew', str(actual.expression.clauses[0].left), "4")
self.assertEqual('s1', actual.clauses[0].right.element.clauses[0].value, "5")
Expand All @@ -66,5 +68,12 @@ def test_get_filter_expression(self):
self.assertEqual('markers_hebrew.street2', str(actual.expression.clauses[1].left), "11")
self.assertEqual('1', actual.clauses[1].right.element.clauses[0].value, "12")

@patch("anyway.widgets.widget_utils.SegmentJunctions")
def test_get_expression_for_segment_junctions(self, sg):
sg.get_instance.return_value = sg
sg.get_segment_junctions.return_value = []
actual = get_expression_for_segment_junctions(17, AccidentMarkerView)
self.assertEqual('1 != 1', str(actual.expression), "1")

if __name__ == '__main__':
unittest.main()

0 comments on commit abb0887

Please sign in to comment.