-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backup): Handle UserRole name collisions (#56479)
Issue: getsentry/team-ospo#184
- Loading branch information
1 parent
b72ff94
commit 69cc8ff
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -741,6 +741,30 @@ def test_colliding_query_subscription(self): | |
== 1 | ||
) | ||
|
||
def test_colliding_user_role(self): | ||
self.create_exhaustive_user("owner", is_admin=True) | ||
|
||
# Take note of the `UserRole` - this is the one we'll be importing. | ||
colliding = UserRole.objects.all().first() | ||
|
||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
tmp_path = self.export_to_tmp_file_and_clear_database(tmp_dir) | ||
|
||
# After exporting and clearing the database, insert a copy of the same `UserRole` as the | ||
# one found in the import. | ||
colliding.save() | ||
|
||
assert UserRole.objects.count() == 1 | ||
assert UserRole.objects.filter(name="test-admin-role").count() == 1 | ||
|
||
with open(tmp_path) as tmp_file: | ||
import_in_global_scope(tmp_file, printer=NOOP_PRINTER) | ||
|
||
assert UserRole.objects.count() == 2 | ||
assert UserRole.objects.filter(name__contains="test-admin-role").count() == 2 | ||
assert UserRole.objects.filter(name__exact="test-admin-role").count() == 1 | ||
assert UserRole.objects.filter(name__contains="test-admin-role-").count() == 1 | ||
|
||
def test_colliding_user_with_merging_enabled_in_user_scope(self): | ||
self.create_exhaustive_user(username="owner", email="[email protected]") | ||
|
||
|