Ejemplo n.º 1
0
 def test_disconnect(self):
     store = ObjectDatastore(self.config)
     connection = MagicMock()
     store.connection = connection
     store.disconnect()
     connection.close.assert_called_once()
     self.assertIsNone(store.connection)
     store.disconnect()
Ejemplo n.º 2
0
def _get_cbs_features(path: str) -> dict[str, dict[str, str]]:
    """
    Gets the CBS codes from the Objectstore and returns a list of dicts with the naam,
    code (wijk or buurt).

    :param path: the path to source file
    :return: a list of dicts with CBS Code and CBS naam, mapped on the local code.
    """
    datastore = ObjectDatastore(
        connection_config=get_datastore_config("Basisinformatie"),
        read_config={
            "file_filter": path,
            "file_type": "XLS"
        })

    datastore.connect()
    result = list(datastore.query(''))
    datastore.disconnect()

    if not result:
        raise GOBException(f"No CBS features found for path '{path}'")

    return {row[0]: {"code": row[1], "naam": row[2]} for row in result}