python-stdnum branch master updated. 1.8.1-9-g75138a4
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.8.1-9-g75138a4
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.8.1-9-g75138a4
- Date: Mon, 19 Feb 2018 23:53:04 +0100 (CET)
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".
The branch, master has been updated
via 75138a4cce3a987e37fbd8833ba68a91568f2543 (commit)
from 92d751cd03ff165f942ee9034399bb942262ad7f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=75138a4cce3a987e37fbd8833ba68a91568f2543
commit 75138a4cce3a987e37fbd8833ba68a91568f2543
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Mon Feb 19 23:48:36 2018 +0100
Add check_dgii() to stdnum.do.cedula module
This exposes the stdnum.do.rnc.check_dgii() in the stdnum.do.cedula
module with but rename the rnc result entry to cedula.
Closes https://github.com/arthurdejong/python-stdnum/issues/63
diff --git a/stdnum/do/cedula.py b/stdnum/do/cedula.py
index db9a1de..fce2f09 100644
--- a/stdnum/do/cedula.py
+++ b/stdnum/do/cedula.py
@@ -1,6 +1,7 @@
# cedula.py - functions for handling Dominican Republic national identifier
+# coding: utf-8
#
-# Copyright (C) 2015-2017 Arthur de Jong
+# Copyright (C) 2015-2018 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -37,6 +38,7 @@ InvalidFormat: ...
"""
from stdnum import luhn
+from stdnum.do import rnc
from stdnum.exceptions import *
from stdnum.util import clean
@@ -173,3 +175,31 @@ def format(number):
"""Reformat the number to the standard presentation format."""
number = compact(number)
return '-'.join((number[:3], number[3:-1], number[-1]))
+
+
+def check_dgii(number, timeout=30): # pragma: no cover
+ """Lookup the number using the DGII online web service.
+
+ This uses the validation service run by the the Dirección General de
+ Impuestos Internos, the Dominican Republic tax department to lookup
+ registration information for the number. The timeout is in seconds.
+
+ Returns a dict with the following structure::
+
+ {
+ 'cedula': '12345678901', # The requested number
+ 'name': 'The registered name',
+ 'commercial_name': 'An additional commercial name',
+ 'status': '2', # 1: inactive, 2: active
+ 'category': '0', # always 0?
+ 'payment_regime': '2', # 1: N/D, 2: NORMAL, 3: PST
+ }
+
+ Will return None if the number is invalid or unknown."""
+ # this function isn't automatically tested because it would require
+ # network access for the tests and unnecessarily load the online service
+ # we use the RNC implementation and change the rnc result to cedula
+ result = rnc.check_dgii(number)
+ if result and 'rnc' in result:
+ result['cedula'] = result.pop('rnc')
+ return result
diff --git a/tests/test_do_cedula.py b/tests/test_do_cedula.py
new file mode 100644
index 0000000..a5a3bb8
--- /dev/null
+++ b/tests/test_do_cedula.py
@@ -0,0 +1,55 @@
+# test_do_cedula.py - functions for testing the online Cedula validation
+# coding: utf-8
+#
+# Copyright (C) 2018 Arthur de Jong
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+# This is a separate test file because it should not be run regularly
+# because it could negatively impact the online service.
+
+"""Extra tests for the stdnum.do.cedula module."""
+
+import os
+import unittest
+
+from stdnum.do import cedula
+
+
+@unittest.skipIf(
+ not os.environ.get('ONLINE_TESTS'),
+ 'Do not overload online services')
+class TestDGII(unittest.TestCase):
+ """Test the web services provided by the the Dirección General de
+ Impuestos Internos (DGII), the Dominican Republic tax department."""
+
+ def test_check_dgii(self):
+ """Test stdnum.do.cedula.check_dgii()"""
+ # Test a normal valid number
+ result = cedula.check_dgii('05500023407')
+ self.assertTrue(all(
+ key in result.keys()
+ for key in ['cedula', 'name', 'commercial_name', 'category',
'status']))
+ self.assertEqual(result['cedula'], '05500023407')
+ # Test an invalid length number
+ self.assertIsNone(cedula.check_dgii('123'))
+ # Test a number with an invalid checksum
+ self.assertIsNone(cedula.check_dgii('00113918204'))
+ # Valid number but unknown
+ self.assertIsNone(cedula.check_dgii('12345678903'))
+ # Test a number on the whitelist
+ result = cedula.check_dgii('0710208838')
+ self.assertEqual(result['cedula'], '0710208838')
-----------------------------------------------------------------------
Summary of changes:
stdnum/do/cedula.py | 32 ++++++++++++++++++++++++++-
tests/{test_do_ncf.py => test_do_cedula.py} | 34 ++++++++++++++---------------
2 files changed, 48 insertions(+), 18 deletions(-)
copy tests/{test_do_ncf.py => test_do_cedula.py} (56%)
hooks/post-receive
--
python-stdnum
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum branch master updated. 1.8.1-9-g75138a4,
Commits of the python-stdnum project