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
Import: Support import of huddles. #9547
Conversation
@rheaparekh how have you tested this? This is complicated enough that automated tests seem pretty high-value here. |
@timabbott I have tested this manually several times, by checking if all of the Huddle features are present in the exported and then imported realm with the original realm. For writing automated tests, I would have to start from scratch and write tests for the entire |
Have you seen |
@timabbott |
7cd3b5b
to
1ea43ed
Compare
I'll be updating this with the tests after #9659 has been merged |
This is still pending on #9659? |
1ea43ed
to
377dab2
Compare
55b7878
to
ec17d83
Compare
I have updated this with tests. |
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'm not overly familiar with this, but here's a review based on some more general aspects.
zerver/tests/test_import_export.py
Outdated
user_id_list = [ | ||
[UserProfile.objects.get(realm=realm, short_name=name).id | ||
for name in short_names] for realm in realms] | ||
huddle_hash = [ |
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 would call this huddle_hashes
, and probably use user_id_lists
above, so that the highest level list comprehension loops are clearer.
zerver/tests/test_import_export.py
Outdated
for name in short_names] for realm in realms] | ||
huddle_hash = [ | ||
get_huddle_hash(id_list) | ||
for id_list in user_id_list] |
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.
For example, this looks like id_list
is not just one of many, but a different data type, if that makes sense?
Whereas for user_id_list in user_id_lists
seems clearer, at least to me - what do you think?
zerver/tests/test_import_export.py
Outdated
get_huddle_hash(id_list) | ||
for id_list in user_id_list] | ||
|
||
self.assertNotEqual(huddle_hash[0], huddle_hash[1]) |
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 know these are "just" tests, but after these and any other tests are complete, I would enjoy a refactor to avoid using 0
and 1
, as we discussed previously. Not a priority, but it makes it clearer :)
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'll do a refactor in another PR. As you suggested, I think using a helper function would be good.
zerver/tests/test_import_export.py
Outdated
|
||
huddle_ids = [ | ||
Huddle.objects.get(huddle_hash=huddle_hash).id | ||
for huddle_hash in huddle_hash] |
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.
These are the same variable name, in the loop. The plurals might help.
zerver/lib/import_realm.py
Outdated
Extract the IDs of the user_profiles involved in a huddle from the subscription object | ||
This helps to generate a unique huddle hash from the updated user_profile ids | ||
""" | ||
id_map_to_list['huddle_to_user_list'] = dict( |
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.
This could be a dict comprehension:
{value: [] for value in id_maps['recipient_to_huddle_map'].values()}
zerver/lib/import_realm.py
Outdated
(value, []) for value in id_maps['recipient_to_huddle_map'].values()) | ||
|
||
for subscription in data[table]: | ||
if subscription['recipient'] in id_maps['recipient_to_huddle_map'].keys(): |
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.
You can skip .keys()
here.
d5029e9
to
f3a2567
Compare
I have updated this! This is ready for a final review. |
f3a2567
to
9b4a571
Compare
Heads up @rheaparekh, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
@rheaparekh can you do a rebase on this? |
9b4a571
to
75696d9
Compare
@timabbott I have rebased and updated this. |
For importing huddles we have to have unique huddle hashes. Huddle hashes are extracted from the list of users participating in a huddle. So to extract these user ids, we first use huddle id to getting the matching recipient, and then we use subscription to get the user ids from the recipient id. Added tests for the same.
I gave this a careful read, and the logic looks great. I made a small change to some variable names in the tests for clarity (pluralization), and added a TODO comment for migrating this new test to use |
Oh I forget to rebase it after the refactor got merged yesterday. I'll add another PR for changing the tests to |
For importing huddles we have to have unique huddle hashes. Huddle hashes are extracted from the list of users participating in a huddle. So to extract this user ids, we first use huddle id to getting the matching
recipient
, and then we usesubscription
to get the user ids from the recipient id.