From 1ebf0f06fa50f76ced213da1266bd27d46a6dc73 Mon Sep 17 00:00:00 2001 From: Haresh Kainth Date: Fri, 29 Nov 2024 18:11:07 +0000 Subject: [PATCH] refactor:import paths for search module Updated the import paths in several files to make them more consistent and streamlined by removing unnecessary "fbr" prefix. This change aims to improve readability and maintainability of the codebase without affecting the functional behavior. The entry script was also cleaned up by removing commented-out migration checks. --- fbr/cache/legislation.py | 7 ++++--- fbr/config/urls.py | 16 ++++++++-------- fbr/search/apps.py | 2 +- fbr/search/tests/test_search.py | 24 ++++++++++++------------ fbr/search/utils/documents.py | 5 +---- fbr/search/views.py | 7 +++---- local_deployment/entry.sh | 3 --- 7 files changed, 29 insertions(+), 35 deletions(-) diff --git a/fbr/cache/legislation.py b/fbr/cache/legislation.py index 8e522e2..03f419d 100644 --- a/fbr/cache/legislation.py +++ b/fbr/cache/legislation.py @@ -1,5 +1,6 @@ # isort: skip_file # fmt: off +# flake8: noqa import logging import re @@ -9,9 +10,9 @@ import requests # type: ignore -from fbr.cache.construction_legislation import construction_legislation_dataframe # noqa: E501 -from fbr.search.config import SearchDocumentConfig # noqa: E501 -from fbr.search.utils.date import convert_date_string_to_obj # noqa: E501 +from fbr.cache.construction_legislation import construction_legislation_dataframe +from fbr.search.config import SearchDocumentConfig +from fbr.search.utils.date import convert_date_string_to_obj from fbr.search.utils.documents import ( # noqa: E501 generate_short_uuid, insert_or_update_document, diff --git a/fbr/config/urls.py b/fbr/config/urls.py index 8cb9817..d7a0553 100644 --- a/fbr/config/urls.py +++ b/fbr/config/urls.py @@ -11,13 +11,13 @@ from django.contrib import admin from django.urls import include, path -import fbr.core.views as core_views -import fbr.search.views as search_views +import core.views as core_views +import search.views as search_views -from fbr.search.config import SearchDocumentConfig -from fbr.search.models import DataResponseModel -from fbr.search.utils.documents import clear_all_documents -from fbr.search.utils.search import get_publisher_names, search +from search.config import SearchDocumentConfig +from search.models import DataResponseModel +from search.utils.documents import clear_all_documents +from search.utils.search import get_publisher_names, search urls_logger = logging.getLogger(__name__) @@ -94,8 +94,8 @@ def search(self, request, *args, **kwargs): class RebuildCacheViewSet(viewsets.ViewSet): @action(detail=False, methods=["post"], url_path="rebuild") def rebuild_cache(self, request, *args, **kwargs): - from fbr.cache.legislation import Legislation - from fbr.cache.public_gateway import PublicGateway + from search.legislation import Legislation + from search.public_gateway import PublicGateway tx_begin = time.time() try: diff --git a/fbr/search/apps.py b/fbr/search/apps.py index f063631..608fabf 100644 --- a/fbr/search/apps.py +++ b/fbr/search/apps.py @@ -13,6 +13,6 @@ class SearchConfig(AppConfig): """ - name = "fbr.search" + name = "search" verbose_name = "Find business regulations application functionality" default_auto_field = "django.db.models.BigAutoField" diff --git a/fbr/search/tests/test_search.py b/fbr/search/tests/test_search.py index fa9d8d7..fcc1161 100644 --- a/fbr/search/tests/test_search.py +++ b/fbr/search/tests/test_search.py @@ -2,18 +2,18 @@ from unittest.mock import MagicMock, call, patch -from fbr.search.utils.search import create_search_query +from search.utils.search import create_search_query class TestCreateSearchQuery(unittest.TestCase): - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_single_word_query(self, mock_search_query): result = create_search_query("test") mock_search_query.assert_called_with("test", search_type="plain") self.assertEqual(result, mock_search_query.return_value) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_implicit_and_search_operator_query(self, mock_search_query): # Mock SearchQuery instances mock_query1 = MagicMock(name="MockQuery1") @@ -35,7 +35,7 @@ def test_implicit_and_search_operator_query(self, mock_search_query): # Assert the AND operation was applied mock_query1.__and__.assert_called_once_with(mock_query2) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_multiple_implicit_and_search_operator_query( self, mock_search_query ): @@ -61,7 +61,7 @@ def test_multiple_implicit_and_search_operator_query( # Assert the AND operation was applied mock_query1.__and__.assert_called_with(mock_query3) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_and_search_operator_query(self, mock_search_query): # Mock SearchQuery instances mock_query1 = MagicMock(name="MockQuery1") @@ -83,7 +83,7 @@ def test_and_search_operator_query(self, mock_search_query): # Assert the AND operation was applied mock_query1.__and__.assert_called_once_with(mock_query2) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_multiple_and_search_operator_query(self, mock_search_query): # Mock SearchQuery instances mock_query1 = MagicMock(name="MockQuery1") @@ -107,7 +107,7 @@ def test_multiple_and_search_operator_query(self, mock_search_query): # Assert the AND operation was applied mock_query1.__and__.assert_called_with(mock_query3) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_or_search_operator_query(self, mock_search_query): # Mock SearchQuery instances mock_query1 = MagicMock(name="MockQuery1") @@ -129,7 +129,7 @@ def test_or_search_operator_query(self, mock_search_query): # Assert the AND operation was applied mock_query1.__or__.assert_called_once_with(mock_query2) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_multple_or_search_operator_query(self, mock_search_query): # Mock SearchQuery instances mock_query1 = MagicMock(name="MockQuery1") @@ -153,7 +153,7 @@ def test_multple_or_search_operator_query(self, mock_search_query): # Assert the AND operation was applied mock_query1.__or__.assert_called_with(mock_query3) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_multiple_or_search_operator_query(self, mock_search_query): # Mock SearchQuery instances mock_query1 = MagicMock(name="MockQuery1") @@ -177,7 +177,7 @@ def test_multiple_or_search_operator_query(self, mock_search_query): # Assert the AND operation was applied mock_query1.__or__.assert_called_with(mock_query3) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_phrase_search_query(self, mock_search_query): result = create_search_query('"test trial"') mock_search_query.assert_called_with( @@ -185,7 +185,7 @@ def test_phrase_search_query(self, mock_search_query): ) self.assertEqual(result, mock_search_query.return_value) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_and_multiple_single_single_phrase_search_query( self, mock_search_query ): @@ -221,7 +221,7 @@ def test_and_multiple_single_single_phrase_search_query( # Assert the AND operation was applied mock_query1.__and__.assert_called_with(mock_query5) - @patch("fbr.search.utils.search.SearchQuery", autospec=True) + @patch("search.utils.search.SearchQuery", autospec=True) def test_single_or_and_search_operator_query(self, mock_search_query): # Mock SearchQuery instances mock_query1 = MagicMock(name="MockQuery1") diff --git a/fbr/search/utils/documents.py b/fbr/search/utils/documents.py index 949aba5..28207b6 100644 --- a/fbr/search/utils/documents.py +++ b/fbr/search/utils/documents.py @@ -1,5 +1,4 @@ import base64 -import logging import re import uuid @@ -7,9 +6,7 @@ from django.db.models import QuerySet -from fbr.search.models import DataResponseModel - -logger = logging.getLogger(__name__) +from search.models import DataResponseModel, logger def clear_all_documents(): diff --git a/fbr/search/views.py b/fbr/search/views.py index 992929b..7a14d0e 100644 --- a/fbr/search/views.py +++ b/fbr/search/views.py @@ -3,16 +3,15 @@ import pandas as pd -from models import DataResponseModel -from utils.search import search, search_database - from django.conf import settings from django.core.serializers import serialize from django.http import HttpRequest, HttpResponse from django.shortcuts import render from django.views.decorators.http import require_http_methods -from config import SearchDocumentConfig +from search.config import SearchDocumentConfig +from search.models import DataResponseModel +from search.utils.search import search, search_database logger = logging.getLogger(__name__) diff --git a/local_deployment/entry.sh b/local_deployment/entry.sh index 245d9e4..b644ad4 100755 --- a/local_deployment/entry.sh +++ b/local_deployment/entry.sh @@ -11,8 +11,5 @@ npm run build echo "Collecting Static Files" python fbr/manage.py collectstatic --noinput -# echo "Check missing migrations" -# python prompt_payments/manage.py makemigrations --check --dry-run - echo "Starting server" python fbr/manage.py runserver 0.0.0.0:8080