Skip to content

Commit

Permalink
Giving up 2.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Dec 1, 2016
1 parent 71382ce commit 0d48dea
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "pypy"
Expand All @@ -16,6 +15,7 @@ script:

matrix:
allow_failures:
- python: "2.7"
- python: pypy
- python: pypy3

Expand Down
38 changes: 30 additions & 8 deletions MyCapytain/resources/texts/api/cts.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,16 @@ def getFirstUrn(self, reference=None):
:return: Children URN
:rtype: URN
"""
if reference:
urn = "{}:{}".format(
str(URN(str(self.urn)).upTo(URN.NO_PASSAGE)),
str(reference)
)
if reference is not None:
if ":" in reference:
urn = reference
else:
urn = "{}:{}".format(
str(URN(str(self.urn)).upTo(URN.NO_PASSAGE)),
str(reference)
)
else:
urn = self.urn

urn = str(self.urn)
_first = __SharedMethod__.firstUrn(
self.retriever.getFirstUrn(
urn
Expand All @@ -224,7 +226,7 @@ def firstId(self):
"""
if self.__first__ is False:
# Request the next urn
self.__first__ = self.getFirstUrn(reference=str(self.urn.reference))
self.__first__ = self.getFirstUrn()
return self.__first__

@property
Expand Down Expand Up @@ -314,6 +316,26 @@ def reffs(self):
reff for reffs in [self.getValidReff(level=i) for i in range(1, len(self.citation) + 1)] for reff in reffs
]

@property
def nextId(self):
raise NotImplementedError

@property
def next(self):
raise NotImplementedError

@property
def prev(self):
raise NotImplementedError

@property
def prevId(self):
raise NotImplementedError

@property
def siblingsId(self):
raise NotImplementedError

def export(self, output=None, exclude=None):
""" Export the collection item in the Mimetype required.
Expand Down
117 changes: 116 additions & 1 deletion tests/resources/texts/api/test_cts.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,121 @@ def test_reffs(self, requests):
params={'urn': 'urn:cts:latinLit:phi1294.phi002.perseus-lat3', 'request': 'GetValidReff', 'level': '3'}
)

def test_siblings_raise(self):
text = Text(
urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2",
retriever=self.endpoint
)
with self.assertRaises(NotImplementedError):
text.prev
with self.assertRaises(NotImplementedError):
text.prevId
with self.assertRaises(NotImplementedError):
text.siblingsId
with self.assertRaises(NotImplementedError):
text.next
with self.assertRaises(NotImplementedError):
text.nextId

def test_get_first(self):
self.endpoint.getPassage = mock.MagicMock(return_value=GET_PASSAGE)
self.endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST)
passage = Text(
urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2",
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")
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=NS)[0])
self.assertIsInstance(first, Passage)

def test_get_first_id(self):
self.endpoint.getPassage = mock.MagicMock(return_value=GET_PASSAGE)
self.endpoint.getPrevNextUrn = mock.MagicMock(return_value=NEXT_PREV)
self.endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST)
self.endpoint.getValidReff = mock.MagicMock(return_value=GET_VALID_REFF_1_1)
passage = Text(
urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2",
retriever=self.endpoint
)

# When next does not exist from the original resource
self.assertEqual(
str(passage.firstId), "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.pr",
"FirstId should resolve"
)

def test_get_last_id(self):
self.endpoint.getPassage = mock.MagicMock(return_value=GET_PASSAGE)
self.endpoint.getPrevNextUrn = mock.MagicMock(return_value=NEXT_PREV)
self.endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST)
self.endpoint.getValidReff = mock.MagicMock(return_value=GET_VALID_REFF_1_1)
passage = Text(
urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2",
retriever=self.endpoint
)

# When next does not exist from the original resource
self.assertEqual(
str(passage.lastId), "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.6",
"FirstId should resolve"
)

def test_child_id(self):
""" Test next property, given that next information already exists or not)
"""
self.endpoint.getPassage = mock.MagicMock(return_value=GET_PASSAGE)
self.endpoint.getPrevNextUrn = mock.MagicMock(return_value=NEXT_PREV)
self.endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST)
self.endpoint.getValidReff = mock.MagicMock(return_value=GET_VALID_REFF_1_1)
passage = Text(
urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1",
retriever=self.endpoint
)

self.assertEqual(
passage.childIds,
[
"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"
)

def test_children(self):
""" Test next property, given that next information already exists or not)
"""

self.endpoint.getPassage = mock.MagicMock(return_value=GET_PASSAGE)
self.endpoint.getPrevNextUrn = mock.MagicMock(return_value=NEXT_PREV)
self.endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST)
self.endpoint.getValidReff = mock.MagicMock(return_value=GET_VALID_REFF_1_1)
passage = Text(
urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1",
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"
],
"Passage should be retrieved and have the correct URN"
)


class TestCTSPassage(unittest.TestCase):
""" Test CTS API implementation of Text
Expand Down Expand Up @@ -520,7 +635,7 @@ def test_child_id(self):
"urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.5",
"urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.6"
],
"FirstId should resolve"
"Passage should be retrieved and have the correct URN"
)

def test_children(self):
Expand Down

0 comments on commit 0d48dea

Please sign in to comment.