@@ -125,6 +125,54 @@ def test_get_by_tags(self) -> None:
125125 self .assertEqual (self .collection .get_by_tags ([]), [])
126126 self .assertEqual (self .collection .get_by_tags (["this should not be a tag" ]), [])
127127
128+ def test_get_by_tags_with_pagination (self ) -> None :
129+
130+ for i in range (5 ):
131+ dbcre = db .CRE (
132+ description = f"Pagiation CRE { i } " ,
133+ name = f"PaginationCRE{ i } " ,
134+ tags = "pagination-test" ,
135+ external_id = f"500-{ i :03d} " ,
136+ )
137+ self .collection .session .add (dbcre )
138+ self .collection .session .commit ()
139+
140+ total_pages , docs = self .collection .get_by_tags_with_pagination (
141+ ["pagination-test" ], page = 1 , items_per_page = 10
142+ )
143+ self .assertEqual (len (docs ), 5 )
144+ self .assertEqual (total_pages , 1 )
145+
146+ total_pages , docs = self .collection .get_by_tags_with_pagination (
147+ ["pagination-test" ], page = 1 , items_per_page = 2
148+ )
149+ self .assertEqual (len (docs ), 2 )
150+ self .assertEqual (total_pages , 3 )
151+
152+ total_pages , docs = self .collection .get_by_tags_with_pagination (
153+ ["pagination-test" ], page = 2 , items_per_page = 2
154+ )
155+ self .assertEqual (len (docs ), 2 )
156+ self .assertEqual (total_pages , 3 )
157+
158+ total_pages , docs = self .collection .get_by_tags_with_pagination (
159+ ["pagination-test" ], page = 3 , items_per_page = 2
160+ )
161+ self .assertEqual (len (docs ), 1 )
162+ self .assertEqual (total_pages , 3 )
163+
164+ total_pages , docs = self .collection .get_by_tags_with_pagination (
165+ [], page = 1 , items_per_page = 1
166+ )
167+ self .assertEqual (total_pages , 0 )
168+ self .assertEqual (docs , [])
169+
170+ total_pages , docs = self .collection .get_by_tags_with_pagination (
171+ ["non-existent-tag" ], page = 1 , items_per_page = 10
172+ )
173+ self .assertEqual (total_pages , 0 )
174+ self .assertEqual (docs , [])
175+
128176 def test_get_standards_names (self ) -> None :
129177 result = self .collection .get_node_names ()
130178 expected = [("Standard" , "BarStand" ), ("Standard" , "Unlinked" )]
0 commit comments