Skip to content

Commit 4dcc5d5

Browse files
committed
update existing, add new test_link_terms
1 parent 645c0ba commit 4dcc5d5

File tree

2 files changed

+100
-18
lines changed

2 files changed

+100
-18
lines changed

indigo_api/tests/fixtures.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,41 @@
3333
</akomaNtoso>
3434
"""
3535

36+
PORTION_FIXTURE = """<akomaNtoso xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0">
37+
<portion name="portion">
38+
<meta>
39+
<identification source="">
40+
<FRBRWork>
41+
<FRBRthis value="/akn/za/act/1900/1/!main"/>
42+
<FRBRuri value="/akn/za/act/1900/1"/>
43+
<FRBRalias value="Untitled"/>
44+
<FRBRdate date="1900-01-01" name="Generation"/>
45+
<FRBRauthor href="#council" as="#author"/>
46+
<FRBRcountry value="za"/>
47+
</FRBRWork>
48+
<FRBRExpression>
49+
<FRBRthis value="/akn/za/act/1900/1/eng@/!main"/>
50+
<FRBRuri value="/akn/za/act/1900/1/eng@"/>
51+
<FRBRdate date="1900-01-01" name="Generation"/>
52+
<FRBRauthor href="#council" as="#author"/>
53+
<FRBRlanguage language="eng"/>
54+
</FRBRExpression>
55+
<FRBRManifestation>
56+
<FRBRthis value="/akn/za/act/1900/1/eng@/!main"/>
57+
<FRBRuri value="/akn/za/act/1900/1/eng@"/>
58+
<FRBRdate date="1900-01-01" name="Generation"/>
59+
<FRBRauthor href="#council" as="#author"/>
60+
</FRBRManifestation>
61+
</identification>
62+
<publication date="2005-07-24" name="Province of Western Cape: σπαθιοῦ Gazette" number="6277" showAs="Province of Western Cape: 😀 Provincial Gazette"/>
63+
</meta>
64+
<portionBody>
65+
%s
66+
</portionBody>
67+
</portion>
68+
</akomaNtoso>
69+
"""
70+
3671
BODY_FIXTURE = """
3772
<body>
3873
<section eId="sec_1">
@@ -130,6 +165,13 @@ def document_fixture(text=None, xml=None):
130165
return DOCUMENT_FIXTURE % xml
131166

132167

168+
def portion_fixture(text=None, xml=None):
169+
if text:
170+
xml = """<section eId="sec_1"><content><p>%s</p></content></section>""" % text
171+
172+
return PORTION_FIXTURE % xml
173+
174+
133175
def component_fixture(text=None, xml=None):
134176
if text:
135177
xml = """<section eId="sec_1"><content><p>%s</p></content></section>""" % text

indigo_api/tests/test_analysis_api.py

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from nose.tools import * # noqa
42
from rest_framework.test import APITestCase
53

@@ -19,17 +17,12 @@ def setUp(self):
1917

2018
def test_link_terms_no_input(self):
2119
response = self.client.post('/api/documents/1/analysis/link-terms', {
22-
'document': {},
2320
})
2421
assert_equal(response.status_code, 400)
2522

2623
def test_link_terms(self):
2724
response = self.client.post('/api/documents/1/analysis/link-terms', {
28-
'document': {
29-
'frbr_uri': '/za/act/1992/1',
30-
'expression_date': '2001-01-01',
31-
'language': 'eng',
32-
'content': document_fixture(xml="""
25+
'xml': document_fixture(xml="""
3326
<section id="section-1">
3427
<num>1.</num>
3528
<heading>Definitions and interpretation</heading>
@@ -64,37 +57,84 @@ def test_link_terms(self):
6457
</content>
6558
</subsection>
6659
</section>
67-
""")
68-
}
60+
"""),
61+
'language': 'eng',
62+
'is_portion': False
6963
})
7064
assert_equal(response.status_code, 200)
7165

72-
content = response.data['document']['content']
66+
content = response.data['xml']
7367

7468
assert_true(content.startswith('<akomaNtoso'))
7569
assert_in('<def ', content)
7670
assert_in('<TLCTerm ', content)
7771

72+
def test_link_terms_portion(self):
73+
response = self.client.post('/api/documents/1/analysis/link-terms', {
74+
'xml': portion_fixture(xml="""
75+
<section id="section-1">
76+
<num>1.</num>
77+
<heading>Definitions and interpretation</heading>
78+
<subsection id="section-1.subsection-0">
79+
<content>
80+
<p>In these By-laws, any word or expression that has been defined in the National Road Traffic Act, 1996 (Act No. 93 of 1996) has that meaning and, unless the context otherwise indicates –</p>
81+
</content>
82+
</subsection>
83+
<subsection id="section-1.subsection-1">
84+
<content>
85+
<blockList id="section-1.subsection-1.list1">
86+
<listIntroduction>"authorised official" means –</listIntroduction>
87+
<item id="section-1.subsection-1.list1.a">
88+
<num>(a)</num>
89+
<p>a member of the Johannesburg Metropolitan Police established in terms of section 64A of the South African Police Service Act, 1995 (Act No. 68 of 1995); or</p>
90+
</item>
91+
<item id="section-1.subsection-1.list1.b">
92+
<num>(b)</num>
93+
<p>any person or official authorised as such, in writing, by the Council;</p>
94+
</item>
95+
</blockList>
96+
</content>
97+
</subsection>
98+
<subsection id="section-1.subsection-2">
99+
<content>
100+
<p>"backfill" means to replace the structural layers, including the base, sub-base, sudgrade and subgrade but excluding the surfacing, in a trench dug in, or other excavation of, a road reserve, and “backfilling” is construed accordingly;</p>
101+
</content>
102+
</subsection>
103+
<subsection id="section-1.subsection-3">
104+
<content>
105+
<p>"these By-Laws" includes the schedules;</p>
106+
</content>
107+
</subsection>
108+
</section>
109+
"""),
110+
'language': 'eng',
111+
'is_portion': True
112+
})
113+
assert_equal(response.status_code, 200)
114+
115+
content = response.data['xml']
116+
117+
assert_true(content.startswith('<portion '))
118+
assert_in('<def ', content)
119+
assert_in('<TLCTerm ', content)
120+
78121
def test_link_terms_no_perms(self):
79122
self.client.logout()
80123
self.assertTrue(self.client.login(username='no-perms@example.com', password='password'))
81124
user = User.objects.get(username='no-perms@example.com')
82125

83126
data = {
84-
'document': {
85-
'frbr_uri': '/za/act/1992/1',
86-
'expression_date': '2001-01-01',
87-
'language': 'eng',
88-
'content': document_fixture(xml="""
127+
'xml': document_fixture(xml="""
89128
<section id="section-1">
90129
<num>1.</num>
91130
<heading>Definitions and interpretation</heading>
92131
<content>
93132
<p>test</p>
94133
</content>
95134
</section>
96-
""")
97-
}
135+
"""),
136+
'language': 'eng',
137+
'is_portion': False
98138
}
99139

100140
# user doesn't have perms

0 commit comments

Comments
 (0)