Skip to content

Commit

Permalink
rename skip_in_tests to if_redis_present
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Nov 14, 2024
1 parent 93d87a4 commit 908e0d4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 104 deletions.
4 changes: 2 additions & 2 deletions papermerge/core/features/document/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
OrderBy,
)
from papermerge.core.config import get_settings, FileServer
from papermerge.core.utils.decorators import skip_in_tests
from papermerge.core.utils.decorators import if_redis_present
from papermerge.core.types import OrderEnum, PaginatedResponse


Expand Down Expand Up @@ -151,7 +151,7 @@ def upload_file(
return doc


@skip_in_tests
@if_redis_present
def send_task(*args, **kwargs):
logger.debug(f"Send task {args} {kwargs}")
celery_app.send_task(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions papermerge/core/features/document_types/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from papermerge.core import schema
from papermerge.core import constants as const
from papermerge.core import orm
from papermerge.core.utils.decorators import skip_in_tests
from papermerge.core.utils.decorators import if_redis_present

from .orm import DocumentType

Expand Down Expand Up @@ -146,7 +146,7 @@ def update_document_type(
return result


@skip_in_tests
@if_redis_present
def send_task(*args, **kwargs):
logger.debug(f"Send task {args} {kwargs}")
celery_app.send_task(*args, **kwargs)
4 changes: 2 additions & 2 deletions papermerge/core/features/nodes/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from papermerge.core.features.nodes.db import api as nodes_dbapi
from papermerge.core.routers.common import OPEN_API_GENERIC_JSON_DETAIL
from papermerge.core.routers.params import CommonQueryParams
from papermerge.core.utils.decorators import skip_in_tests
from papermerge.core.utils.decorators import if_redis_present
from papermerge.core.exceptions import EntityNotFound


Expand Down Expand Up @@ -389,7 +389,7 @@ def remove_node_tags(
return node


@skip_in_tests
@if_redis_present
def _notify_index(node_id: uuid.UUID):
id_as_str = str(node_id) # just in case, make sure it is str
current_app.send_task(
Expand Down
8 changes: 4 additions & 4 deletions papermerge/core/features/page_mngm/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from papermerge.core import constants as const
from papermerge.core.pathlib import abs_page_path
from papermerge.core.storage import get_storage_instance
from papermerge.core.utils.decorators import skip_in_tests
from papermerge.core.utils.decorators import if_redis_present
from papermerge.core.db import Session
from papermerge.core import orm, schema, types
from papermerge.core.features.document.db import api as doc_dbapi
Expand Down Expand Up @@ -683,7 +683,7 @@ def copy_without_pages(
]


@skip_in_tests
@if_redis_present
def notify_version_update(add_ver_id: str, remove_ver_id: str):
# Send tasks to the index to remove/add pages
current_app.send_task(const.INDEX_UPDATE, (add_ver_id, remove_ver_id))
Expand All @@ -700,7 +700,7 @@ def notify_version_update(add_ver_id: str, remove_ver_id: str):
)


@skip_in_tests
@if_redis_present
def notify_add_docs(add_doc_ids: List[str]):
# send task to index
logger.debug(f"Sending task {const.INDEX_ADD_DOCS} with {add_doc_ids}")
Expand All @@ -718,7 +718,7 @@ def notify_add_docs(add_doc_ids: List[str]):
)


@skip_in_tests
@if_redis_present
def notify_generate_previews(doc_id: list[str] | str):
if isinstance(doc_id, str):
current_app.send_task(
Expand Down
31 changes: 9 additions & 22 deletions papermerge/core/models/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from papermerge.core import constants as const
from papermerge.core.models import utils
from papermerge.core.models.node import BaseTreeNode
from papermerge.core.utils.decorators import skip_in_tests
from papermerge.core.utils.decorators import if_redis_present


class FolderManager(models.Manager):
Expand Down Expand Up @@ -35,19 +35,15 @@ def delete(self, *args, **kwargs):

self.publish_post_delete_task(deleted_node_ids)

@skip_in_tests
@if_redis_present
def publish_post_delete_task(self, node_ids: List[str]):
current_app.send_task(
const.INDEX_REMOVE_NODE,
kwargs={'item_ids': node_ids},
route_name='i3'
const.INDEX_REMOVE_NODE, kwargs={"item_ids": node_ids}, route_name="i3"
)

def get_by_breadcrumb(
self,
breadcrumb: str, # should this be pathlib.PurePath ?
user
) -> 'Folder':
self, breadcrumb: str, user # should this be pathlib.PurePath ?
) -> "Folder":
"""
Returns ``Folder`` instance of the node defined by given
breadcrumb path of specific ``User``.
Expand All @@ -57,11 +53,7 @@ def get_by_breadcrumb(
folder = Folder.objects.get_by_breadcrumb('.home/My Documents', user)
assert folder.title == 'My Documents'
"""
return utils.get_by_breadcrumb(
Folder,
breadcrumb,
user
)
return utils.get_by_breadcrumb(Folder, breadcrumb, user)


CustomFolderManager = FolderManager.from_queryset(FolderQuerySet)
Expand Down Expand Up @@ -91,17 +83,15 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)
self.publish_post_save_task()

@skip_in_tests # skip this method when running tests
@if_redis_present # skip this method when running tests
def publish_post_save_task(self):
"""Send task to worker to add folder changes to search index
This method WILL NOT be invoked during tests
"""
id_as_str = str(self.pk)
current_app.send_task(
const.INDEX_ADD_NODE,
kwargs={'node_id': id_as_str},
route_name='i3'
const.INDEX_ADD_NODE, kwargs={"node_id": id_as_str}, route_name="i3"
)

class Meta:
Expand All @@ -121,9 +111,6 @@ def get_inbox_children(user):
Returns a ``QuerySet`` containing the immediate children nodes
of given user's inbox folder
"""
inbox_node = BaseTreeNode.objects.get(
title=Folder.INBOX_TITLE,
user=user
)
inbox_node = BaseTreeNode.objects.get(title=Folder.INBOX_TITLE, user=user)

return inbox_node.get_children()
Loading

0 comments on commit 908e0d4

Please sign in to comment.