Skip to content

Commit

Permalink
add segment to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atalyaalon committed Sep 26, 2024
1 parent 3fd5f9a commit 59c8c05
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions tests/test_news_flash_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
update_news_flash_qualifying,
)
from anyway.backend_constants import BE_CONST
from anyway.models import LocationVerificationHistory, NewsFlash, Users
from anyway.models import LocationVerificationHistory, NewsFlash, Users, RoadSegments
import tests.test_flask as tests_flask

# global application scope. create Session class, engine
Expand Down Expand Up @@ -79,12 +79,20 @@ def test_add_location_qualifiction_history(self, can, current_user, get_current_
db_mock.session = self.session
user_id = self.session.query(Users).all()[0].id
tests_flask.set_current_user_mock(current_user, user_id=user_id)
road_segment = RoadSegments(
segment_id=100,
road=1,
from_name='from_name',
to_name='to_name',
)
db_mock.session.add(road_segment)
db_mock.session.commit()
with patch("anyway.views.news_flash.api.db", db_mock):
mock_request = unittest.mock.MagicMock()
values = {"newsflash_location_qualification": "manual", "road_segment_id": 100, "road1": "1"}
mock_request.values.get = lambda key: values.get(key)
with patch("anyway.views.news_flash.api.request", mock_request):
id = self.session.query(NewsFlash).all()[0].id
id = db_mock.session.query(NewsFlash).all()[0].id
return_value = update_news_flash_qualifying(id)
self.assertEqual(return_value.status_code, HTTPStatus.OK.value)
location_verifiction_history = (
Expand Down Expand Up @@ -120,13 +128,24 @@ def _test_update_news_flash_qualifying_manual_with_location(self):
"""
the test tries to change manually the road_segment_name of a news flash.
"""
db_mock = unittest.mock.MagicMock()
db_mock.session = self.session
mock_request = unittest.mock.MagicMock()
values = {"newsflash_location_qualification": "manual", "road_segment_id": 100, "road1": "1"}
mock_request.values.get = lambda key: values.get(key)
with patch("anyway.views.news_flash.api.request", mock_request):
id = self.session.query(NewsFlash).all()[0].id
return_value = update_news_flash_qualifying(id)
self.assertEqual(return_value.status_code, HTTPStatus.OK.value, "1")
road_segment = RoadSegments(
segment_id=100,
road=1,
from_name='from_name',
to_name='to_name',
)
db_mock.session.add(road_segment)
db_mock.session.commit()
with patch("anyway.views.news_flash.api.db", db_mock):
with patch("anyway.views.news_flash.api.request", mock_request):
id = db_mock.session.query(NewsFlash).all()[0].id
return_value = update_news_flash_qualifying(id)
self.assertEqual(return_value.status_code, HTTPStatus.OK.value, "1")

def _test_update_news_flash_qualifying_manual_without_location(self):
"""
Expand Down

0 comments on commit 59c8c05

Please sign in to comment.