Closed mutantsan closed 2 years ago
Fix #271. Any idea why the tests fail?
I had a problem with testing ckanext-spatial, it doesn't work for me. I'm going to try again, but I see there are a lot of recent commits with dumb comments, and it's hard to understand why do we need all of them.
@mutantsan what do you mean with "recent commits with dumb comments"? is this on this repo, if so in what branch? There's only one failure here and it looks like it could be related to the changes (probably the test needs to be adapted)
@amercader I think it refers to all the "WIP: debug print" and similar commits that are on master.
Ok, I think I found it.
tk.ValidationError
does not return an HTTP error code. This is a CKAN bug in my opinion. There is a difference on the error triggered: asShape
fails using ValueError
providing a meaningful message, while shape
fails using AttributeError
, which is caught by a generic Exception
handler.
ckanext-spatial
does not look at the HTTP code, as CKAN does not seem to handle that correctly, so it relies on the output, which is different if a generic Exception
is triggered. The test is not generic enough.
This is the output: Spatial: Error creating geometry: Context does not provide geo interface
This is what CKAN tests look for:
https://github.com/ckan/ckanext-spatial/blob/992b2753fc24d0abb12ced5cf5aaa3a853ca9ea4/ckanext/spatial/tests/functional/test_package.py#L186
There is a test already for checking if Error
is included in the reply. Dropping the last assertion seems reasonable to me.
Error handling:
Example:
>>> asShape({"Type":"Bad_GeoJSON","a":2})
Traceback (most recent call last):
File "/usr/lib/ckan/venv/lib/python3.8/site-packages/shapely/geometry/geo.py", line 175, in asShape
geom_type = ob.get("type").lower()
AttributeError: 'NoneType' object has no attribute 'lower'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/ckan/venv/lib/python3.8/site-packages/shapely/geometry/geo.py", line 177, in asShape
raise ValueError("Context does not provide geo interface")
ValueError: Context does not provide geo interface
>>> shape({"Type":"Bad_GeoJSON","a":2})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/ckan/venv/lib/python3.8/site-packages/shapely/geometry/geo.py", line 102, in shape
geom_type = ob.get("type").lower()
AttributeError: 'NoneType' object has no attribute 'lower'
@amercader This PR can be closed, as PR #273 has been merged.
There are some shapely deprecations that related to ckanext-spatial:
asShape
is deprecated in favor ofshape