Skip to content

Commit

Permalink
refactor:import paths for search module
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hareshkainthdbt committed Nov 29, 2024
1 parent 4ae6ed5 commit 1ebf0f0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
7 changes: 4 additions & 3 deletions fbr/cache/legislation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# isort: skip_file
# fmt: off
# flake8: noqa

import logging
import re
Expand All @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions fbr/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion fbr/search/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 12 additions & 12 deletions fbr/search/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
):
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -177,15 +177,15 @@ 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(
"test trial", search_type="phrase"
)
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
):
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 1 addition & 4 deletions fbr/search/utils/documents.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import base64
import logging
import re
import uuid

from numpy.f2py.auxfuncs import throw_error

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():
Expand Down
7 changes: 3 additions & 4 deletions fbr/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
3 changes: 0 additions & 3 deletions local_deployment/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1ebf0f0

Please sign in to comment.