lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.11-30-gdb89d38

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.11-30-gdb89d38



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  db89d38f73725ad6dc1245228991f5abc1f8da5a (commit)
       via  e75b1bf4afde612e151e02aa79edfc85894e5eb0 (commit)
      from  fb725502333dc822675f770af0784f4474cc0f3e (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=db89d38f73725ad6dc1245228991f5abc1f8da5a

commit db89d38f73725ad6dc1245228991f5abc1f8da5a
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jul 21 23:24:28 2019 +0200

    Fix the Handelsregisternummer number matching
    
    This ensures that numbers of 1 digit are also accepted and that trailing
    characters are not silently discardede in the validation.
    
    This also adds a few test cases for this and makes "Paderborn früher
    Höxter" an alias for "Paderborn".
    
    Closes https://github.com/arthurdejong/python-stdnum/issues/143

diff --git a/stdnum/de/handelsregisternummer.py 
b/stdnum/de/handelsregisternummer.py
index 603d9a3..5bda74c 100644
--- a/stdnum/de/handelsregisternummer.py
+++ b/stdnum/de/handelsregisternummer.py
@@ -239,6 +239,7 @@ _courts.update(
         ('St. Wendel', 'St. Wendel (St Wendel)'),
         ('Weiden in der Oberpfalz', 'Weiden i. d. OPf.'),
         ('Weiden', 'Weiden i. d. OPf.'),
+        ('Paderborn früher Höxter', 'Paderborn'),
     ))
 
 
@@ -271,10 +272,10 @@ COMPANY_FORM_REGISTRY_TYPES = {
 # possible formats the number can be specified in
 _court_re = r'(?P<court>.*)'
 _registry_re = r'(?P<registry>%s)' % '|'.join(REGISTRY_TYPES)
-_number_re = r'(?P<nr>[0-9]{3,6})(\s*(?P<x>[A-Z]{1,3}))?'
+_number_re = r'(?P<nr>[1-9][0-9]{0,5})(\s*(?P<x>[A-ZÖ]{1,3}))?'
 _formats = [
-    _registry_re + r'\s+' + _number_re + r',?\s+' + _court_re,
-    _court_re + r',?\s+' + _registry_re + r'\s+' + _number_re,
+    _registry_re + r'\s+' + _number_re + r',?\s+' + _court_re + '$',
+    _court_re + r',?\s+' + _registry_re + r'\s+' + _number_re + '$',
 ]
 
 
diff --git a/tests/test_de_handelsregisternummer.doctest 
b/tests/test_de_handelsregisternummer.doctest
index b75a1db..f204b4f 100644
--- a/tests/test_de_handelsregisternummer.doctest
+++ b/tests/test_de_handelsregisternummer.doctest
@@ -46,6 +46,14 @@ Some basic tests for valid numbers.
 'Berlin (Charlottenburg) HRB 11223 B'
 
 
+Tests for some corner cases.
+
+>>> handelsregisternummer.validate('Berlin (Charlottenburg) HRA 11223 BBBB')
+Traceback (most recent call last):
+  ...
+InvalidFormat: ...
+
+
 The court name can also be shortened and various encodings are accepted but
 we only return either Unicode or UTF-8 (Python 2 only). The tests are a bit
 funky so they work both in Python 2 and Python 3.
@@ -87,6 +95,7 @@ These have been found online and should all be valid numbers.
 ... Aachen   HRB   11214
 ... Aachen   HRB   5360
 ... Aachen   HRB   987
+... Augsburg HRA 1
 ... Bad Oeynhausen   HRA   5980
 ... Bad Oeynhausen   HRB   14572
 ... Bad Oeynhausen   HRB   5087
@@ -95,6 +104,7 @@ These have been found online and should all be valid numbers.
 ... Berlin HRB 87447 B
 ... Bochum   HRA   5582
 ... Bochum   HRA   5828
+... Bochum HRB 1
 ... Braunschweig   HRB   8057
 ... Chemnitz   HRB   14011
 ... Coesfeld   HRA   7092
@@ -172,6 +182,7 @@ These have been found online and should all be valid 
numbers.
 ... Mönchengladbach   HRB   5867
 ... Mönchengladbach   HRB   6639
 ... Mönchengladbach   HRB   7785
+... München HRB 1
 ... München HRB 178881
 ... Münster   HRA   8289
 ... Neubrandenburg   HRB   4956
@@ -190,7 +201,9 @@ These have been found online and should all be valid 
numbers.
 ... Paderborn   HRB   3659
 ... Paderborn   HRB   653
 ... Paderborn   HRB   6774
+... Paderborn früher Höxter HRB 9
 ... Pinneberg   HRB   12700  PI
+... Pinneberg GNR 1 IZ
 ... Recklinghausen   HRB   4702
 ... Rostock   HRA   887
 ... Saarbrücken   HRB   102069
@@ -198,8 +211,10 @@ These have been found online and should all be valid 
numbers.
 ... Siegen   HRB   10955
 ... Siegen   HRB   5398
 ... Siegen   HRB   7426
+... Straubing PR 8
 ... Stuttgart   HRB   460675
 ... Tostedt   HRB   100870
+... Traunstein GnR 1
 ... Walsrode   HRB   202134
 ... Wiesbaden   HRB   11946
 ... Wittlich   HRB   42489

https://arthurdejong.org/git/python-stdnum/commit/?id=e75b1bf4afde612e151e02aa79edfc85894e5eb0

commit e75b1bf4afde612e151e02aa79edfc85894e5eb0
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jul 21 20:21:33 2019 +0200

    Lookup German Handelsregisternummer in OffeneRegister.de
    
    This supports looking up the German Handelsregisternummer using the
    online OffeneRegister.de web service.

diff --git a/stdnum/de/handelsregisternummer.py 
b/stdnum/de/handelsregisternummer.py
index 5d7de4e..603d9a3 100644
--- a/stdnum/de/handelsregisternummer.py
+++ b/stdnum/de/handelsregisternummer.py
@@ -34,6 +34,7 @@ More information:
 
 * https://www.handelsregister.de/
 * https://en.wikipedia.org/wiki/German_Trade_Register
+* https://offeneregister.de/
 
 >>> validate('Aachen HRA 11223')
 'Aachen HRA 11223'
@@ -284,7 +285,7 @@ def _split(number):
     for fmt in _formats:
         m = re.match(fmt, number, flags=re.I | re.U)
         if m:
-            return m.group('court'), m.group('registry'), m.group('nr'), 
m.group('x')
+            return m.group('court').strip(), m.group('registry'), 
m.group('nr'), m.group('x')
     raise InvalidFormat()
 
 
@@ -316,3 +317,62 @@ def is_valid(number):
         return bool(validate(number))
     except ValidationError:
         return False
+
+
+# The base URL for performing lookups
+_offeneregister_url = 'https://db.offeneregister.de/openregister-ef9e802.json'
+
+
+def check_offeneregister(number, timeout=30):  # pragma: no cover (not part of 
normal test suite)
+    """Retrieve registration information from the OffeneRegister.de web site.
+
+    This basically returns the JSON response from the web service as a dict.
+    It will contain something like the following::
+
+        {
+            'retrieved_at': '2018-06-24T12:34:53Z',
+            'native_company_number': 'The number requested',
+            'company_number': 'Compact company number',
+            'registrar': 'Registar',
+            'federal_state': 'State name',
+            'registered_office': 'Office',
+            'register_art': 'Register type',
+            'register_nummer': 'Number'
+            'name': 'The name of the organisation',
+            'current_status': 'currently registered',
+        }
+
+    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 web service
+    import requests
+    court, registry, number, qualifier = _split(number)
+    # First lookup the registrar code
+    # (we could look up the number by registrar (court), registry and number
+    # but it seems those queries are too slow)
+    response = requests.get(
+        _offeneregister_url,
+        params={
+            'sql': 'select company_number from company where registrar = :p0 
limit 1',
+            'p0': court},
+        timeout=timeout)
+    response.raise_for_status()
+    try:
+        registrar = response.json()['rows'][0][0].split('_')[0]
+    except (KeyError, IndexError) as e:  # noqa: F841
+        raise InvalidComponent()  # unknown registrar code
+    # Lookup the number
+    number = '%s_%s%s' % (registrar, registry, number)
+    response = requests.get(
+        _offeneregister_url,
+        params={
+            'sql': 'select * from company where company_number = :p0 limit 1',
+            'p0': number},
+        timeout=timeout)
+    response.raise_for_status()
+    try:
+        json = response.json()
+        return dict(zip(json['columns'], json['rows'][0]))
+    except (KeyError, IndexError) as e:  # noqa: F841
+        return  # number not found
diff --git a/tests/test_de_handelsregisternummer.py 
b/tests/test_de_handelsregisternummer.py
new file mode 100644
index 0000000..496c356
--- /dev/null
+++ b/tests/test_de_handelsregisternummer.py
@@ -0,0 +1,47 @@
+# test_de_handelsregisternummer.py - online validation tests
+# coding: utf-8
+#
+# Copyright (C) 2019 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.de.handelsregisternummer module."""
+
+import os
+import unittest
+
+from stdnum.de import handelsregisternummer
+
+
+@unittest.skipIf(
+    not os.environ.get('ONLINE_TESTS'),
+    'Do not overload online services')
+class TestOffeneRegister(unittest.TestCase):
+    """Test the web services provided by the OffeneRegister.de web site."""
+
+    def test_check_offeneregister(self):
+        """Test stdnum.de.handelsregisternummer.check_offeneregister()"""
+        # Test a normal valid number
+        result = handelsregisternummer.check_offeneregister('Chemnitz HRB 
14011')
+        self.assertTrue(all(
+            key in result.keys()
+            for key in ['company_number', 'current_status', 'federal_state', 
'registrar', 'native_company_number']))
+        # Test invalid number
+        result = handelsregisternummer.check_offeneregister('Chemnitz HRA 
14012')
+        self.assertIsNone(result)

-----------------------------------------------------------------------

Summary of changes:
 stdnum/de/handelsregisternummer.py                 | 69 ++++++++++++++++++++--
 tests/test_de_handelsregisternummer.doctest        | 15 +++++
 ..._cedula.py => test_de_handelsregisternummer.py} | 34 ++++-------
 3 files changed, 93 insertions(+), 25 deletions(-)
 copy tests/{test_do_cedula.py => test_de_handelsregisternummer.py} (50%)


hooks/post-receive
-- 
python-stdnum