示例#1
0
 def test_container_calculates_page_numbers_correctly(self):
     container = AnnotationContainer(self.base_url,
                                     self.annotations,
                                     page_size=1)
     view = container.view()
     last_url = container.update_url(self.base_url, {"iris": 1, "page": 1})
     self.assertEqual(view["last"], last_url)
     container = AnnotationContainer(self.base_url,
                                     self.annotations,
                                     page_size=2)
     view = container.view()
     last_url = container.update_url(self.base_url, {"iris": 1, "page": 0})
     self.assertEqual(view["last"], last_url)
示例#2
0
 def test_container_view_can_show_first_page_as_iris(self):
     anno_ids = [anno.id for anno in self.annotations]
     container = AnnotationContainer(self.base_url,
                                     self.annotations,
                                     view="PreferContainedIRIs",
                                     page_size=1)
     view = container.view()
     self.assertEqual(view["first"]["id"],
                      container.update_url(container.base_url, {"page": 0}))
     self.assertEqual(view["first"]["next"],
                      container.update_url(container.base_url, {"page": 1}))
     self.assertEqual(len(view["first"]["items"]), 1)
     self.assertTrue(view["first"]["items"][0] in anno_ids)
示例#3
0
 def test_container_can_be_initialized(self):
     container = AnnotationContainer(self.base_url, [],
                                     view="PreferMinimalContainer")
     self.assertEqual(container.page_size, 100)
     self.assertEqual(container.num_pages, 0)
     self.assertEqual(container.metadata['id'],
                      container.update_url(self.base_url, {"iris": 1}))
示例#4
0
 def test_container_can_generate_pages(self):
     container = AnnotationContainer(self.base_url,
                                     self.annotations,
                                     page_size=1)
     view = container.view_page(page=0)
     self.assertEqual(view["@context"], "http://www.w3.org/ns/anno.jsonld")
     self.assertEqual(
         view["id"],
         container.update_url(self.base_url, {
             "iris": 1,
             "page": 0
         }))
     self.assertEqual(view["type"], "AnnotationPage")
     self.assertEqual(view["partOf"]["id"], container.base_url)
     self.assertEqual(view["startIndex"], 0)
     self.assertEqual(
         view["next"],
         container.update_url(self.base_url, {
             "iris": 1,
             "page": 1
         }))
     self.assertEqual(len(view["items"]), 1)