Skip to content

Commit

Permalink
Add redis failure test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtsuk committed Jun 19, 2023
1 parent 375a8d1 commit f78fa66
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/admin/clickhouse_migrations/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,35 @@ def test_get_iam_roles_cache() -> None:
system_role,
tool_role,
]


@pytest.mark.redis_db
@patch("redis.Redis")
def test_get_iam_roles_cache_fail(mock_redis: Any) -> None:
mock_redis.get.side_effect = Exception("Test exception")
mock_redis.set.side_effect = Exception("Test exception")
system_role = generate_migration_test_role("system", "all")
tool_role = generate_tool_test_role("snql-to-sql")
with patch(
"snuba.admin.auth.DEFAULT_ROLES",
[system_role, tool_role],
):
iam_file = tempfile.NamedTemporaryFile()
iam_file.write(json.dumps({"bindings": []}).encode("utf-8"))
iam_file.flush()

with patch("snuba.admin.auth.settings.ADMIN_IAM_POLICY_FILE", iam_file.name):
user1 = AdminUser(email="test_user1@sentry.io", id="unknown")
_set_roles(user1)

assert user1.roles == [
system_role,
tool_role,
]

_set_roles(user1)

assert user1.roles == [
system_role,
tool_role,
]

0 comments on commit f78fa66

Please sign in to comment.