Skip to content

Commit

Permalink
Merge pull request #104 from certego/develop
Browse files Browse the repository at this point in the history
0.11.1
  • Loading branch information
0ssigeno authored May 29, 2023
2 parents 1cef9f1 + 3bc8a46 commit 3818c1d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
19 changes: 9 additions & 10 deletions atlasq/queryset/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
from mongoengine import Q, QuerySet
from pymongo.command_cursor import CommandCursor

logger = logging.getLogger(__name__)


def clock(func):
def clocked(self, *args, **kwargs):
start_time = time.perf_counter()
result = func(self, *args, **kwargs)
elapsed = time.perf_counter() - start_time
floor = f"{elapsed:0.3f}"
logger.info(f"{floor} - {result}")
self.logger.info(f"{floor} - {result}")
return result

return clocked
Expand Down Expand Up @@ -51,6 +49,7 @@ def __init__(self, document, collection):
self._count: bool = False
self._return_objects: bool = True
self._other_aggregations: List[Dict] = []
self.logger = logging.getLogger(f"{__name__}.{self._document._get_collection_name()}")

# pylint: disable=too-many-arguments
def upload_index(
Expand All @@ -69,7 +68,7 @@ def upload_index(
json_index["database"] = db_name
if "name" not in json_index:
json_index["name"] = self.index._index # pylint: disable=protected-access
logger.info(f"Sending {json_index} to create new index")
self.logger.info(f"Sending {json_index} to create new index")
return self.index.upload_index(json_index, user, password, group_id, cluster_name)

def ensure_index(self, user: str, password: str, group_id: str, cluster_name: str):
Expand Down Expand Up @@ -149,14 +148,14 @@ def _query(self):
if obj:
ids.append(obj["_id"])
self._query_obj = Q(id__in=ids)
logger.debug(self._query_obj.to_query(self._document))
self.logger.debug(self._query_obj.to_query(self._document))
return super()._query

def __collection_aggregate(self, final_pipeline, **kwargs):
collection = self._collection
if self._read_preference is not None or self._read_concern is not None:
collection = self._collection.with_options(read_preference=self._read_preference, read_concern=self._read_concern)
logger.info(final_pipeline)
self.logger.info(final_pipeline)
return collection.aggregate(final_pipeline, cursor={}, **kwargs)

def aggregate(self, pipeline, **kwargs): # pylint: disable=arguments-differ,unused-argument
Expand All @@ -174,7 +173,7 @@ def __call__(self, q_obj=None, **query):
q = AtlasQ(**query)
if q_obj is not None:
q &= q_obj
logger.debug(q)
self.logger.debug(q)
qs = super().__call__(q)
return qs

Expand All @@ -184,7 +183,7 @@ def _get_projections(self) -> List[Dict[str, Any]]:
return [{"$project": {"meta": "$$SEARCH_META"}}]
return [{"$count": "count"}]
loaded_fields = self._loaded_fields.as_dict()
logger.debug(loaded_fields)
self.logger.debug(loaded_fields)
if loaded_fields:
return [{"$project": loaded_fields}]
return []
Expand All @@ -197,12 +196,12 @@ def count(self, with_limit_and_skip=False): # pylint: disable=unused-argument
except StopIteration:
self._len = 0 # pylint: disable=attribute-defined-outside-init
else:
logger.debug(count)
self.logger.debug(count)
if self._query_obj:
self._len = count["meta"]["count"]["total"] # pylint: disable=attribute-defined-outside-init
else:
self._len = count["count"] # pylint: disable=attribute-defined-outside-init
logger.debug(self._len)
self.logger.debug(self._len)
return self._len

def limit(self, n):
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ dependencies = {file = ["requirements.txt"]}
test = [
"black==22.3.0",
"isort==5.10.1",
"pylint==2.13.9",
"pylint==2.17.4",
"flake8==4.0.1",
"pre-commit==2.19.0",
"tox==3.25.0",
"tox-gh-actions==2.9.1",
"pre-commit==3.3.2",
"tox==4.5.2",
"tox-gh-actions==3.1.1",
"codecov==2.1.12",
"coverage==6.4",
"mongomock==4.0.0",
"coverage==7.2.6",
"mongomock==4.1.2",
]

[tool.black]
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pre-commit==2.19.0
mongomock==4.0.0
pre-commit==3.3.2
mongomock==4.1.2
7 changes: 5 additions & 2 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from unittest import TestCase

import mongomock
from mongoengine import connect, disconnect


class TestBaseCase(TestCase):

db_name = "mongoenginetest"

@classmethod
def setUpClass(cls) -> None:
cls.db_name = "mongoenginetest"
connect(cls.db_name, host="mongomock://localhost")
connect(db=cls.db_name, mongo_client_class=mongomock.MongoClient)

@classmethod
def tearDownClass(cls) -> None:
Expand Down

0 comments on commit 3818c1d

Please sign in to comment.