Skip to content

Commit

Permalink
Fixes #39 - Https scheme and missing trailing slashes in uselicense
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Fonseca committed Apr 7, 2015
1 parent 08cda26 commit 18bd9a3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Dev

* Fixes a bug that report *page-count* as invalid when fpage or lpage values
are non-digit.
* Fixes a bug that mark as invalid XMLs containing use-licenses with
https scheme or missing trailing slashes.


0.7 (2015-03-13)
Expand Down
5 changes: 1 addition & 4 deletions packtools/catalogs/scielo-style-1.1.sch
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,7 @@
<assert test="@license-type = 'open-access'">
Element 'license', attribute license-type: Invalid value '<value-of select="@license-type"/>'.
</assert>
<assert test="@xlink:href = 'http://creativecommons.org/licenses/by-nc/4.0/' or
@xlink:href = 'http://creativecommons.org/licenses/by-nc/3.0/' or
@xlink:href = 'http://creativecommons.org/licenses/by/4.0/' or
@xlink:href = 'http://creativecommons.org/licenses/by/3.0/'">
<assert test="regexp:test(@xlink:href, 'https?://creativecommons\.org/licenses/(by-nc|by)/(3|4)\.0/?')">
Element 'license', attribute xlink:href: Invalid value '<value-of select="@xlink:href"/>'.
</assert>
</rule>
Expand Down
2 changes: 1 addition & 1 deletion packtools/catalogs/scielo-style-1.2.sch
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@
<assert test="@license-type = 'open-access'">
Element 'license', attribute license-type: Invalid value '<value-of select="@license-type"/>'.
</assert>
<assert test="regexp:test(@xlink:href, 'https?://creativecommons\.org/licenses/(by-nc|by|by-nc-nd)/(3|4)\.0/')">
<assert test="regexp:test(@xlink:href, 'https?://creativecommons\.org/licenses/(by-nc|by|by-nc-nd)/(3|4)\.0/?')">
Element 'license', attribute xlink:href: Invalid value '<value-of select="@xlink:href"/>'.
</assert>
</rule>
Expand Down
52 changes: 52 additions & 0 deletions tests/test_schematron_1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2999,6 +2999,34 @@ def test_allowed_license_href(self):

self.assertTrue(self._run_validation(sample))

def test_allowed_license_href_https_scheme(self):
allowed_licenses = [
'https://creativecommons.org/licenses/by-nc/4.0/',
'https://creativecommons.org/licenses/by-nc/3.0/',
'https://creativecommons.org/licenses/by/4.0/',
'https://creativecommons.org/licenses/by/3.0/',
]

for license in allowed_licenses:
sample = u"""<article xmlns:xlink="http://www.w3.org/1999/xlink">
<front>
<article-meta>
<permissions>
<license license-type="open-access"
xlink:href="%s">
<license-p>
This is an open-access article distributed under the terms...
</license-p>
</license>
</permissions>
</article-meta>
</front>
</article>
""" % license
sample = io.BytesIO(sample.encode('utf-8'))

self.assertTrue(self._run_validation(sample))

def test_disallowed_license_href(self):
sample = u"""<article xmlns:xlink="http://www.w3.org/1999/xlink">
<front>
Expand All @@ -3019,6 +3047,30 @@ def test_disallowed_license_href(self):

self.assertFalse(self._run_validation(sample))

def test_missing_trailing_slash(self):
allowed_licenses = [
'https://creativecommons.org/licenses/by-nc/4.0',
]

for license in allowed_licenses:
sample = u"""<article xmlns:xlink="http://www.w3.org/1999/xlink">
<front>
<article-meta>
<permissions>
<license license-type="open-access"
xlink:href="%s">
<license-p>
This is an open-access article distributed under the terms...
</license-p>
</license>
</permissions>
</article-meta>
</front>
</article>
""" % license
sample = io.BytesIO(sample.encode('utf-8'))

self.assertTrue(self._run_validation(sample))

class AckTests(PhaseBasedTestCase):
"""Tests for article/back/ack element.
Expand Down
25 changes: 25 additions & 0 deletions tests/test_schematron_1_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2640,6 +2640,31 @@ def test_disallowed_license_href(self):

self.assertFalse(self._run_validation(sample))

def test_missing_trailing_slash(self):
allowed_licenses = [
'https://creativecommons.org/licenses/by-nc/4.0',
]

for license in allowed_licenses:
sample = u"""<article xmlns:xlink="http://www.w3.org/1999/xlink">
<front>
<article-meta>
<permissions>
<license license-type="open-access"
xlink:href="%s">
<license-p>
This is an open-access article distributed under the terms...
</license-p>
</license>
</permissions>
</article-meta>
</front>
</article>
""" % license
sample = io.BytesIO(sample.encode('utf-8'))

self.assertTrue(self._run_validation(sample))


class AckTests(PhaseBasedTestCase):
"""Tests for article/back/ack element.
Expand Down

0 comments on commit 18bd9a3

Please sign in to comment.