#25407: Remove network dependency in GeoIP tests
--------------------------------------+------------------------------------
Reporter: MarkusH | Owner: bak1an
Type: Cleanup/optimization | Status: assigned
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by bak1an):
Hi all!
Had to wait until a weekend to move forward on this. Here is what I've got
for now:
- Mocking works fine for {{{geoip2}}} since domains are resolved within
python code -
https://github.com/django/django/blob/master/django/contrib/gis/geoip2/base.py#L162
([https://github.com/django/django/compare/master...bak1an:ticket_25407_gis_tests
initial branch is there])
- With {{{geoip}}} it is not that simple. Domain resolution is done within
maxmind C library - https://github.com/maxmind/geoip-
api-c/blob/733b36e88138a6d603e411976c0a18972f8e2045/libGeoIP/GeoIP.c#L1681
and django just uses it as is via ctypes -
https://github.com/django/django/blob/master/django/contrib/gis/geoip/prototypes.py#L122
- Other tests seem to work fine without network (had 146 skips though).
Unfortunately Berker's hint on catching network errors during the test
(using context manager for example) is not going to work in this case
because the actual network error is being consumed inside the C library
and all we have is just {{{None}}} as a result of a geoip query.
I can see the following options here:
- Introduce some sort of a skip decorator or just a routine inside a
testsuite for checking if there is a proper network connection (and
possibly skipping tests that require internet). This seems a bit tricky to
me. How do we check connectivity? Which resources should we query?
Besides, for this particular case we don't need a full internet connection
at all, just DNS (local caching server will do fine).
- Add hacks to {{{geoip}}} tests (3 tests require such 'fixing') so they
will try to do {{{socket.gethostbyname}}} for domains under test in the
beginning or {{{setUp}}}. In case gethostbyname fails - tests will proceed
with IP checks only, skipping fqdn checks (probably issuing a warning, so
it's easy to catch if the issue persists).
- Leave it as is. {{{geoip}}} is deprecated after all.
@timgraham, @berkerpeksag - could you advise a proper way to go here?
Meanwhile, I'm going to get some sleep. Perhaps there are other solutions
hidden out there which I can't see now.
--
Ticket URL: <https://code.djangoproject.com/ticket/25407#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.e538883af229d25c388d92d5dfc347b1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.