Skip to content

Commit

Permalink
refactor: Consolidate on var CLOUD_DEPLOYMENT instead of REGION (#…
Browse files Browse the repository at this point in the history
…20274)

* refactor: Consolidate on var `CLOUD_DEPLOYMENT` instead of `REGION`

* Update `is_cloud`

* Update `get_instance_region`

* Update query snapshots

* Update query snapshots

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Twixes and github-actions[bot] authored Feb 12, 2024
1 parent df72e97 commit 5bb9cf9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 11 deletions.
11 changes: 11 additions & 0 deletions posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -8350,6 +8350,17 @@
LIMIT 1 /*controller='project_dashboards-detail',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/dashboards/%28%3FP%3Cpk%3E%5B%5E/.%5D%2B%29/%3F%24'*/
'''
# ---
# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.315
'''
SELECT "posthog_instancesetting"."id",
"posthog_instancesetting"."key",
"posthog_instancesetting"."raw_value"
FROM "posthog_instancesetting"
WHERE "posthog_instancesetting"."key" = 'constance:posthog:PERSON_ON_EVENTS_ENABLED'
ORDER BY "posthog_instancesetting"."id" ASC
LIMIT 1 /*controller='project_dashboards-detail',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/dashboards/%28%3FP%3Cpk%3E%5B%5E/.%5D%2B%29/%3F%24'*/
'''
# ---
# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.32
'''
SELECT "posthog_team"."id",
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/test/test_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ def test_can_create_org_with_multi_org(self):

@pytest.mark.ee
def test_cloud_preflight_based_on_region(self):
with self.settings(REGION="US"):
with self.settings(CLOUD_DEPLOYMENT="US"):
response = self.client.get("/_preflight/")
assert response.status_code == status.HTTP_200_OK
assert response.json()["realm"] == "cloud"
assert response.json()["cloud"] is True
with self.settings(REGION=None):
with self.settings(CLOUD_DEPLOYMENT=None):
response = self.client.get("/_preflight/")
assert response.status_code == status.HTTP_200_OK
assert response.json()["realm"] == "hosted-clickhouse"
Expand Down
2 changes: 1 addition & 1 deletion posthog/cloud_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def is_cloud() -> bool:
return bool(settings.REGION)
return bool(settings.CLOUD_DEPLOYMENT)


def get_cached_instance_license() -> Optional["License"]:
Expand Down
4 changes: 1 addition & 3 deletions posthog/settings/base_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
DEBUG = get_from_env("DEBUG", False, type_cast=str_to_bool)
TEST = "test" in sys.argv or sys.argv[0].endswith("pytest") or get_from_env("TEST", False, type_cast=str_to_bool) # type: bool
DEMO = get_from_env("DEMO", False, type_cast=str_to_bool) # Whether this is a managed demo environment
REGION = get_from_env( # Whether this is the "US" or "EU" Cloud region (REGION's only set on Cloud)
"REGION", optional=True
)
CLOUD_DEPLOYMENT = get_from_env("CLOUD_DEPLOYMENT", optional=True) # "US", "EU", or "DEV" - unset on self-hosted
SELF_CAPTURE = get_from_env("SELF_CAPTURE", DEBUG and not DEMO, type_cast=str_to_bool)
E2E_TESTING = get_from_env(
"E2E_TESTING", False, type_cast=str_to_bool
Expand Down
2 changes: 1 addition & 1 deletion posthog/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def validate_basic_html(self, html_message, site_url, preheader=None):

@contextmanager
def is_cloud(self, value: bool):
with self.settings(REGION="US" if value else None):
with self.settings(CLOUD_DEPLOYMENT="US" if value else None):
yield value

@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion posthog/test/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def test_project_unchanged_when_accessing_missing_project_by_id(self):
assert response_users_api.json().get("team", {}).get("id") == self.team.id


@override_settings(REGION="US") # As PostHog Cloud
@override_settings(CLOUD_DEPLOYMENT="US") # As PostHog Cloud
class TestPostHogTokenCookieMiddleware(APIBaseTest):
CONFIG_AUTO_LOGIN = False

Expand Down
2 changes: 1 addition & 1 deletion posthog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ def get_instance_region() -> Optional[str]:
"""
Returns the region for the current Cloud instance. `US` or 'EU'.
"""
return settings.REGION
return settings.CLOUD_DEPLOYMENT


def get_can_create_org(user: Union["AbstractBaseUser", "AnonymousUser"]) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions posthog/warehouse/api/test/test_external_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_database_schema(self):
def test_internal_postgres(self, patch_get_postgres_schemas):
patch_get_postgres_schemas.return_value = ["table_1"]

with override_settings(REGION="US"):
with override_settings(CLOUD_DEPLOYMENT="US"):
team_2, _ = Team.objects.get_or_create(id=2, organization=self.team.organization)
response = self.client.get(
f"/api/projects/{team_2.id}/external_data_sources/database_schema/",
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_internal_postgres(self, patch_get_postgres_schemas):
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {"message": "Cannot use internal Postgres database"})

with override_settings(REGION="EU"):
with override_settings(CLOUD_DEPLOYMENT="EU"):
team_1, _ = Team.objects.get_or_create(id=1, organization=self.team.organization)
response = self.client.get(
f"/api/projects/{team_1.id}/external_data_sources/database_schema/",
Expand Down

0 comments on commit 5bb9cf9

Please sign in to comment.