Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added logging request city and request country using geoip2 #38

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

anatolzak
Copy link
Contributor

#8

Added request city and country logging using Django's wrapper for the python pacakge geoip2

image

@anatolzak
Copy link
Contributor Author

From Django Geolocation with GeoIP2

Instructions on how to enable location logging

In order to perform IP-based geolocation, the GeoIP2 object requires the GeoIP Country and/or City datasets in binary format (the CSV files will not work!). Grab the GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz files and unzip them in a directory corresponding to the GEOIP_PATH setting.

Copy link
Owner

@lingster lingster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to keep the coverage up, could we also some some unit tests to cover the additional 2 new fields.
See the tests/test_models.py and test/test_mixins.py.

rest_framework_tracking/base_mixins.py Show resolved Hide resolved
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 30, 2020

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.22%.

Quality metrics Before After Change
Complexity 1.68 ⭐ 1.86 ⭐ 0.18 👎
Method Length 37.17 ⭐ 37.54 ⭐ 0.37 👎
Working memory 8.19 🙂 8.32 🙂 0.13 👎
Quality 81.41% 81.19% -0.22% 👎
Other metrics Before After Change
Lines 651 694 43
Changed files Quality Before Quality After Quality Change
rest_framework_tracking/admin.py 58.85% 🙂 57.74% 🙂 -1.11% 👎
rest_framework_tracking/base_mixins.py 66.22% 🙂 66.45% 🙂 0.23% 👍
rest_framework_tracking/base_models.py 94.38% ⭐ 94.38% ⭐ 0.00%
tests/test_mixins.py 86.39% ⭐ 86.52% ⭐ 0.13% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
rest_framework_tracking/base_mixins.py BaseLoggingMixin.finalize_response 17 🙂 204 😞 31 ⛔ 26.79% 😞 Try splitting into smaller methods. Extract out complex expressions
rest_framework_tracking/base_mixins.py BaseLoggingMixin._clean_data 17 🙂 119 🙂 11 😞 48.95% 😞 Extract out complex expressions
tests/test_mixins.py TestLoggingMixin.test_put_user 0 ⭐ 54 ⭐ 15 😞 67.97% 🙂 Extract out complex expressions
tests/test_mixins.py TestLoggingMixin.test_post_user 0 ⭐ 50 ⭐ 13 😞 71.29% 🙂 Extract out complex expressions
tests/test_mixins.py TestLoggingMixin.test_log_exact_match_params_cleaned 0 ⭐ 40 ⭐ 13 😞 72.90% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

@anatolzak anatolzak requested a review from lingster November 30, 2020 10:38
@anatolzak
Copy link
Contributor Author

In order to keep the coverage up, could we also some some unit tests to cover the additional 2 new fields.
See the tests/test_models.py and test/test_mixins.py.

I added unit tests to cover the 2 new fields: request_city and request_country. I check that both fields equal to None if the IP address is 127.0.0.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants