Esempio n. 1
0
    def test_to_db_model_default(self):
        sorting_fields = []
        expected_result = self.TestModel.Config.sorting_default

        result = SortBuilder(sorting_fields=sorting_fields).to_db(
            model=self.TestModel, append_sorting_default=False)

        self.assertEqual(expected_result, result)
Esempio n. 2
0
    def test_to_db_model_no_sorting_default(self):
        sorting_fields = []
        expected_result = [("_id", pymongo.DESCENDING)]

        result = SortBuilder(sorting_fields=sorting_fields).to_db(
            model=self.TestModelNoSortingDefault)

        self.assertEqual(expected_result, result)
Esempio n. 3
0
    def test_to_db_pipeline_model_default(self):
        sorting_fields = []
        expected_result = {"a": pymongo.DESCENDING}

        result = SortBuilder(sorting_fields=sorting_fields).to_db(
            model=self.TestModel,
            to_pipeline_stage=True,
            append_sorting_default=False)

        self.assertEqual(expected_result, result)
Esempio n. 4
0
    def test__init__(self):
        sorting_fields = [
            ("a", pymongo.ASCENDING),
            ("b", pymongo.DESCENDING),
            ("c", pymongo.ASCENDING),
        ]

        builder = SortBuilder(sorting_fields=sorting_fields)

        self.assertEqual([("_id", pymongo.DESCENDING)],
                         builder.sorting_default)
        self.assertEqual(sorting_fields, builder.sorting_fields)
Esempio n. 5
0
    def test_to_db_pipeline(self):
        sorting_fields = [
            ("a", pymongo.ASCENDING),
            ("b", pymongo.DESCENDING),
            ("c", pymongo.ASCENDING),
        ]
        expected_result = {
            "a": pymongo.ASCENDING,
            "b": pymongo.DESCENDING,
            "_id": pymongo.DESCENDING,
        }

        result = SortBuilder(sorting_fields=sorting_fields).to_db(
            model=self.TestModel, to_pipeline_stage=True)

        self.assertEqual(expected_result, result)
Esempio n. 6
0
    def test_to_db(self):
        sorting_fields = [
            ("a", pymongo.ASCENDING),
            ("b", pymongo.DESCENDING),
            ("c", pymongo.ASCENDING),
        ]
        expected_result = [
            ("a", pymongo.ASCENDING),
            ("b", pymongo.DESCENDING),
            ("_id", pymongo.DESCENDING),
        ]

        result = SortBuilder(sorting_fields=sorting_fields).to_db(
            model=self.TestModel)

        self.assertEqual(expected_result, result)
Esempio n. 7
0
 async def users_list(
     self,
     request: fastapi.Request,
     query: dict,
     sort_by: SortBuilder,
     paginator: Paginator,
     projector: BaseProjector,
 ):
     return await self.user_repository.find(
         query=query,
         sort=sort_by.to_db(model=UserModel),
         skip=paginator.skip,
         limit=paginator.limit,
         session=request.state.db_session,
         projection=projector.to_db(),
         repository_config=BaseRepositoryConfig(convert=False),
     )
Esempio n. 8
0
    def test_to_db_model_no_sorting_fields(self):
        sorting_fields = []

        with self.assertRaises(NotImplementedError):
            SortBuilder(sorting_fields=sorting_fields).to_db(
                model=self.TestModelNoSortingFields)