def test_get_reffs_contextual(self): """ Ensure getReffs works with context """ endpoint = HttpCtsRetriever(self.url) endpoint.getValidReff = mock.MagicMock(return_value=GET_VALID_REFF) text = CtsText("urn:cts:latinLit:phi1294.phi002.perseus-lat2", retriever=endpoint) passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1", resource=GET_PASSAGE, retriever=endpoint) passage.getReffs() endpoint.getValidReff.assert_called_with( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1", level=2)
def test_first_urn_whenreference(self): endpoint = HttpCtsRetriever(self.url) endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST) text = CtsText("urn:cts:latinLit:phi1294.phi002.perseus-lat2", retriever=endpoint) passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1", resource=GET_PASSAGE, retriever=endpoint) first = passage.getFirstUrn("1.1") endpoint.getFirstUrn.assert_called_with( "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") self.assertEqual( first, "1.pr", "Parsing should be done and getFirstUrn should treat correctly full urn" )
def test_get_first_id(self): passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1", resource=GET_PASSAGE, retriever=self.endpoint) # When next does not exist from the original resource self.assertEqual(str(passage.firstId), "1.pr", "FirstId should resolve")
def test_next_id(self): """ Test next property, given that next information already exists or not) """ passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE, retriever=self.endpoint) self.assertEqual(passage.nextId, "1.2", "NextId should resolve")
def test_get_last_id(self): self.endpoint.getValidReff = mock.MagicMock( return_value=GET_VALID_REFF_1_1) passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE, retriever=self.endpoint) # When next does not exist from the original resource self.assertEqual(str(passage.lastId), "1.1.6", "FirstId should resolve")
def test_first_urn(self): text = CtsText("urn:cts:latinLit:phi1294.phi002.perseus-lat2", retriever=self.endpoint) passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1", resource=GET_PASSAGE, retriever=self.endpoint) self.assertEqual(passage.firstId, "1.pr", "Endpoint should be called and URN should be parsed") self.endpoint.getFirstUrn.assert_called_with( "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1")
def test_unicode_text(self): """ Test text properties for pypy """ # Now with a resource containing prevnext passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE, retriever=self.endpoint) self.assertIn("لا یا ایها الساقی ادر کاسا و ناولها ###", passage.text)
def test_get_first(self): passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1", resource=GET_PASSAGE, retriever=self.endpoint ) # When next does not exist from the original resource first = passage.first self.endpoint.getFirstUrn.assert_called_with("urn:cts:latinLit:phi1294.phi002.perseus-lat2:1") self.endpoint.getPassage.assert_called_with(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.pr") self.assertEqual(first.xml, GET_PASSAGE.xpath("//tei:TEI", namespaces=XPATH_NAMESPACES)[0]) self.assertIsInstance(first, CtsPassage)
def test_parentId(self): """ Test next property, given that next information already exists or not) """ passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE, retriever=self.endpoint) self.assertEqual(passage.parentId, "1", "ParentId should resolve") self.assertIsInstance(passage.parent, CtsPassage, "Parent CTSPassage should be a passage") self.endpoint.getPassage.assert_called_with( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1")
def test_child_id(self): """ Test next property, given that next information already exists or not) """ self.endpoint.getValidReff = mock.MagicMock( return_value=GET_VALID_REFF_1_1) passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE, retriever=self.endpoint) self.assertEqual( passage.childIds, ["1.1.1", "1.1.2", "1.1.3", "1.1.4", "1.1.5", "1.1.6"], "CapitainsCtsPassage should be retrieved and have the correct URN")
def test_prev_prev_next_property(self): """ Test reference property As of 0.1.0, .next and prev are URNs """ passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE, retriever=self.endpoint) # When next does not exist from the original resource self.assertEqual(passage.prevId, "1.pr") self.assertEqual(passage.nextId, "1.2") self.assertEqual(passage.siblingsId, ("1.pr", "1.2")) self.endpoint.getPrevNextUrn.assert_called_with( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
def test_prev_getprevnext(self): """ Test next property, given that next information already exists or not) """ passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE, retriever=self.endpoint ) # When next does not exist from the original resource __prev = passage.prev self.endpoint.getPrevNextUrn.assert_called_with(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") self.endpoint.getPassage.assert_called_with(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.pr") self.assertEqual(__prev.xml, GET_PASSAGE.xpath("//tei:TEI", namespaces=XPATH_NAMESPACES)[0]) self.assertIsInstance(__prev, CtsPassage)
def test_first_urn_when_empty(self): endpoint = HttpCtsRetriever(self.url) endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST_EMPTY) text = CtsText("urn:cts:latinLit:phi1294.phi002.perseus-lat2", retriever=endpoint) passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1", resource=GET_PASSAGE, retriever=endpoint) first = passage.firstId endpoint.getFirstUrn.assert_called_with( "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1") self.assertEqual( first, None, "Endpoint should be called and none should be returned if there is none" )
def test_next_resource(self): """ Test next property, given that next information already exists """ # Now with a resource containing prevnext passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE_PLUS, retriever=self.endpoint ) # When next does not exist from the original resource __next = passage.next # print(self.endpoint.getPrevNextUrn.mock_calls) self.endpoint.getPassage.assert_called_with(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.2") self.assertEqual(__next.xml, GET_PASSAGE.xpath("//tei:TEI", namespaces=XPATH_NAMESPACES)[0]) self.assertIsInstance(__next, CtsPassage)
def test_children(self): """ Test next property, given that next information already exists or not) """ self.endpoint.getValidReff = mock.MagicMock( return_value=GET_VALID_REFF_1_1) passage = CtsPassage( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1", resource=GET_PASSAGE, retriever=self.endpoint) self.assertEqual(len(list(passage.children)), 6) self.assertEqual([str(x.urn) for x in passage.children], [ "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.1", "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.2", "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.3", "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.4", "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.5", "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.6" ], "FirstId should resolve")