-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/cohort-pagination
- Loading branch information
Showing
29 changed files
with
724 additions
and
182 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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import django | ||
|
||
from dagster import ( | ||
Config, | ||
MaterializeResult, | ||
asset, | ||
) | ||
|
||
# setup PostHog Django Project | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "posthog.settings") | ||
django.setup() | ||
|
||
from posthog.clickhouse.client import sync_execute # noqa | ||
|
||
|
||
class ClickHouseConfig(Config): | ||
result_path: str = "/tmp/clickhouse_version.txt" | ||
|
||
|
||
@asset | ||
def get_clickhouse_version(config: ClickHouseConfig) -> MaterializeResult: | ||
version = sync_execute("SELECT version()")[0][0] | ||
with open(config.result_path, "w") as f: | ||
f.write(version) | ||
return MaterializeResult(metadata={"version": version}) | ||
|
||
|
||
@asset(deps=[get_clickhouse_version]) | ||
def print_clickhouse_version(config: ClickHouseConfig): | ||
with open(config.result_path) as f: | ||
print(f.read()) # noqa | ||
return MaterializeResult(metadata={"version": config.result_path}) |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from dagster import Definitions, load_assets_from_modules | ||
|
||
from . import assets | ||
|
||
all_assets = load_assets_from_modules([assets]) | ||
|
||
defs = Definitions( | ||
assets=all_assets, | ||
) |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import pytest | ||
from unittest.mock import patch, mock_open | ||
|
||
from dagster import build_op_context | ||
|
||
from dags.assets import ( | ||
get_clickhouse_version, | ||
print_clickhouse_version, | ||
ClickHouseConfig, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def mock_sync_execute(): | ||
with patch("dags.assets.sync_execute") as mock: | ||
mock.return_value = [["23.8.1.2992"]] | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def config(): | ||
return ClickHouseConfig(result_path="/tmp/test_clickhouse_version.txt") | ||
|
||
|
||
def test_get_clickhouse_version(mock_sync_execute, config): | ||
# Create a test context with our config | ||
context = build_op_context(resources={}, config=config) | ||
|
||
# Mock the file write operation | ||
mock_file = mock_open() | ||
with patch("builtins.open", mock_file): | ||
result = get_clickhouse_version(context) | ||
|
||
# Verify the SQL query was executed | ||
mock_sync_execute.assert_called_once_with("SELECT version()") | ||
|
||
# Verify the version was written to file | ||
mock_file().write.assert_called_once_with("23.8.1.2992") | ||
|
||
# Verify the result metadata | ||
assert result.metadata == {"version": "23.8.1.2992"} | ||
|
||
|
||
def test_print_clickhouse_version(config): | ||
# Create a test context with our config | ||
context = build_op_context(resources={}, config=config) | ||
|
||
# Mock the file read operation | ||
mock_file = mock_open(read_data="23.8.1.2992") | ||
with patch("builtins.open", mock_file) as mock_open_: | ||
with patch("builtins.print") as mock_print: | ||
result = print_clickhouse_version(context) | ||
|
||
# Verify the file was read | ||
mock_open_.assert_called_once_with(config.result_path) | ||
|
||
# Verify the version was printed | ||
mock_print.assert_called_once_with("23.8.1.2992") | ||
|
||
# Verify the result metadata | ||
assert result.metadata == {"version": config.result_path} | ||
|
||
|
||
def test_assets_integration(mock_sync_execute, config): | ||
"""Test that both assets work together in sequence""" | ||
context = build_op_context(resources={}, config=config) | ||
|
||
# First run get_clickhouse_version | ||
mock_write = mock_open() | ||
with patch("builtins.open", mock_write): | ||
get_clickhouse_version(context) | ||
mock_write().write.assert_called_once_with("23.8.1.2992") | ||
|
||
# Then run print_clickhouse_version | ||
mock_read = mock_open(read_data="23.8.1.2992") | ||
with patch("builtins.open", mock_read): | ||
with patch("builtins.print") as mock_print: | ||
print_clickhouse_version(context) | ||
mock_print.assert_called_once_with("23.8.1.2992") |
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useActions } from 'kea' | ||
import { Link } from 'lib/lemon-ui/Link' | ||
import notFoundAstrohog from 'public/not-found-astrohog.png' | ||
|
||
import { supportLogic } from '../Support/supportLogic' | ||
|
||
export interface AccessDeniedProps { | ||
object: string | ||
} | ||
|
||
export function AccessDenied({ object }: AccessDeniedProps): JSX.Element { | ||
const { openSupportForm } = useActions(supportLogic) | ||
|
||
return ( | ||
<div className="flex flex-col items-center max-w-2xl p-4 my-24 mx-auto text-center"> | ||
<img src={notFoundAstrohog} className="w-64 h-64 bg-no-repeat bg-center" /> | ||
<h1 className="text-3xl font-bold mt-4 mb-0">Access denied</h1> | ||
<p className="text-sm mt-3 mb-0"> | ||
You do not have access to this {object}. Please contact the creator of this {object} or{' '} | ||
<Link onClick={() => openSupportForm({ kind: 'support' })}>support</Link> if you think this is a | ||
mistake. | ||
</p> | ||
</div> | ||
) | ||
} |
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
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
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
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
Oops, something went wrong.