-
Notifications
You must be signed in to change notification settings - Fork 41
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
Espoo Importer #718
Espoo Importer #718
Conversation
647b21d
to
4ea1d33
Compare
Codecov Report
@@ Coverage Diff @@
## main #718 +/- ##
==========================================
+ Coverage 80.26% 82.03% +1.77%
==========================================
Files 274 275 +1
Lines 21056 21090 +34
==========================================
+ Hits 16901 17302 +401
+ Misses 4155 3788 -367
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
925881e
to
b4279bf
Compare
b1e046d
to
cbfac1a
Compare
OK, I believe I've addressed all the comments. Requesting re-review and the new changes are in separate commits for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the earlier comments were not addressed.
events/importer/espoo.py
Outdated
places = Place.objects.filter(**filter_params).order_by( | ||
"-data_source", "-n_events" | ||
audiences_data = _get_origin_objs( | ||
f"{settings.ESPOO_API_URL}v1/keyword/", missing_audience_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now three places where a URL is built from settings.ESPOO_API_URL
, and this particular one is actually implemented a bit differently than the other two (f-string vs urljoin). From DRY viewpoint it would be better to have something like get_espoo_api_url(resource)
. Also, it would safer for the future, if the setting ESPOO_API_URL
would work with and without a trailing /
.
events/importer/espoo.py
Outdated
instances = [] | ||
instance_data_map = {} | ||
for obj_data in origin_objs: | ||
obj_data = dict(obj_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is here just to get a copy, I'm guessing it would be more robust to use deepcopy?
linkedevents/settings.py
Outdated
@@ -60,6 +60,15 @@ def get_git_revision_hash() -> str: | |||
), | |||
ENABLE_EXTERNAL_USER_EVENTS=(bool, True), | |||
ENABLE_REGISTRATION_ENDPOINTS=(bool, False), | |||
ESPOO_API_URL=(str, "https://api.espoo.fi/events/"), | |||
ESPOO_API_QUERY_PARAMS=( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As these are only used with event resource queries, I would rather name this ESPOO_API_EVENT_QUERY_PARAMS
(I actually first thought these were used in every query when I saw the setting 🙂)
Could not identify where it was needed anymore.
d0ff51b
to
30795b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions for the tests, otherwise LGTM 👍
events/tests/importers/test_espoo.py
Outdated
assert [d["id"] for d in origin_data[:1]] == [i.id for i in common_objs] | ||
assert origin_data[1:] == origin_objs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we asserting here? The first line especially is very cryptic 😅
@pytest.fixture | ||
def sleep(monkeypatch): | ||
class Sleep: | ||
call_count = 0 | ||
|
||
def sleep(self, t): | ||
self.call_count += 1 | ||
|
||
sleep_instance = Sleep() | ||
|
||
monkeypatch.setattr("time.sleep", sleep_instance.sleep) | ||
return sleep_instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use Mock
instead:
@pytest.fixture | |
def sleep(monkeypatch): | |
class Sleep: | |
call_count = 0 | |
def sleep(self, t): | |
self.call_count += 1 | |
sleep_instance = Sleep() | |
monkeypatch.setattr("time.sleep", sleep_instance.sleep) | |
return sleep_instance | |
@pytest.fixture | |
def sleep(monkeypatch): | |
mock_sleep = Mock() # or a MagicMock | |
monkeypatch.setattr("time.sleep", mock_sleep) | |
return mock_sleep |
Or if you don't like mixing & matching:
@pytest.fixture | |
def sleep(monkeypatch): | |
class Sleep: | |
call_count = 0 | |
def sleep(self, t): | |
self.call_count += 1 | |
sleep_instance = Sleep() | |
monkeypatch.setattr("time.sleep", sleep_instance.sleep) | |
return sleep_instance | |
@pytest.fixture | |
def sleep(): | |
with patch("time.sleep") as mock: # not completely sure on the target; maybe "events.importer.sleep" if this one doesn't work? | |
yield mock |
|
||
|
||
@pytest.fixture | ||
def sleep(monkeypatch): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the name mock_sleep
, but up to you.
def sleep(monkeypatch): | |
def mock_sleep(monkeypatch): |
A generic LE importer that handles relations and imports Organizations, Places, Keywords and Events under a DataSource. Unreferenced relations are removed using ModelSyncher. Co-authored-by: Tuomas Haapala <[email protected]> Co-authored-by: Daniel Prange <[email protected]>
30795b1
to
66648f1
Compare
Kudos, SonarCloud Quality Gate passed! |
Espoo importer is a rather generic LE importer. Handles various relations between objects etc. although in hindsight nobody has specified if this is necessary. Actually, at this point I still don't know what are the parameters that should be used for importing, so that's configurable via an environment variable..
https://helsinkisolutionoffice.atlassian.net/browse/LINK-1375