Skip to content

Commit 720df5c

Browse files
committed
add and debug tests
1 parent b2a490d commit 720df5c

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed

packages/cubejs-backend-native/js/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ export interface PyConfiguration {
354354
checkAuth?: (req: unknown, authorization: string) => Promise<{ 'security_context'?: unknown }>
355355
queryRewrite?: (query: unknown, ctx: unknown) => Promise<unknown>
356356
contextToApiScopes?: () => Promise<string[]>
357-
scheduledRefreshContexts?: () => Promise<string[]>
358-
scheduledRefreshTimeZones?: () => Promise<string[]>
357+
scheduledRefreshContexts?: (ctx: unknown) => Promise<string[]>
358+
scheduledRefreshTimeZones?: (ctx: unknown) => Promise<string[]>
359359
contextToRoles?: (ctx: unknown) => Promise<string[]>
360360
}
361361

packages/cubejs-backend-native/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"test:server": "CUBEJS_NATIVE_INTERNAL_DEBUG=true CUBESQL_LOG_LEVEL=trace CUBESQL_PG_PORT=5555 node dist/test/server.js",
2222
"test:server:stream": "CUBESQL_STREAM_MODE=true CUBESQL_LOG_LEVEL=error CUBESQL_PG_PORT=5555 node dist/test/server.js",
2323
"test:python": "CUBEJS_NATIVE_INTERNAL_DEBUG=true CUBESQL_LOG_LEVEL=trace CUBESQL_PG_PORT=5555 node dist/test/python.js",
24-
"test:unit": "jest --forceExit",
24+
"unit": "jest --forceExit",
25+
"test:unit": "yarn run unit",
2526
"test:cargo": "cargo test",
2627
"lint": "eslint test/ js/ --ext .ts",
2728
"lint:fix": "eslint --fix test/ js/ --ext .ts"

packages/cubejs-backend-native/python/cube/src/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Configuration:
4444
allow_js_duplicate_props_in_schema: bool
4545
jwt: Dict
4646
scheduled_refresh_timer: Any
47-
scheduled_refresh_timezones: Union[Callable[[RequestContext], list[str]], list[str]]
47+
scheduled_refresh_time_zones: Union[Callable[[RequestContext], list[str]], list[str]]
4848
scheduled_refresh_concurrency: int
4949
scheduled_refresh_batch_size: int
5050
compiler_cache_size: int
@@ -117,7 +117,7 @@ def __init__(self):
117117
self.query_rewrite = None
118118
self.extend_context = None
119119
self.scheduled_refresh_contexts = None
120-
self.scheduled_refresh_timezones = None
120+
self.scheduled_refresh_time_zones = None
121121
self.context_to_api_scopes = None
122122
self.repository_factory = None
123123
self.schema_version = None

packages/cubejs-backend-native/src/python/cube_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl CubeConfigPy {
3333
"scheduled_refresh_batch_size",
3434
"scheduled_refresh_concurrency",
3535
"scheduled_refresh_timer",
36-
"scheduled_refresh_timezones",
36+
"scheduled_refresh_time_zones",
3737
"schema_path",
3838
"sql_cache",
3939
"sql_password",

packages/cubejs-backend-native/test/old-config.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ async def context_to_api_scopes():
3131

3232
settings.context_to_api_scopes = context_to_api_scopes
3333

34+
async def scheduled_refresh_time_zones(ctx):
35+
print("[python] scheduled_refresh_time_zones ctx=", ctx)
36+
return ["Europe/Kyiv", "Antarctica/Troll", "Australia/Sydney"]
37+
38+
settings.scheduled_refresh_time_zones = scheduled_refresh_time_zones
39+
40+
41+
async def scheduled_refresh_contexts(ctx):
42+
print("[python] scheduled_refresh_contexts ctx=", ctx)
43+
return [
44+
{
45+
"securityContext": {
46+
"appid": 'test1', "u": {"prop1": "value1"}
47+
}
48+
},
49+
{
50+
"securityContext": {
51+
"appid": 'test2', "u": {"prop1": "value2"}
52+
}
53+
},
54+
{
55+
"securityContext": {
56+
"appid": 'test3', "u": {"prop1": "value3"}
57+
}
58+
},
59+
]
60+
61+
settings.scheduled_refresh_contexts = scheduled_refresh_contexts
62+
3463
def schema_version(ctx):
3564
print('[python] schema_version', ctx)
3665

packages/cubejs-backend-native/test/python.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ suite('Python Config', () => {
4747
repositoryFactory: expect.any(Function),
4848
schemaVersion: expect.any(Function),
4949
contextToRoles: expect.any(Function),
50+
scheduledRefreshContexts: expect.any(Function),
51+
scheduledRefreshTimeZones: expect.any(Function),
5052
});
5153

5254
if (!config.checkAuth) {
@@ -88,15 +90,15 @@ suite('Python Config', () => {
8890
throw new Error('scheduledRefreshTimeZones was not defined in config.py');
8991
}
9092

91-
expect(await config.scheduledRefreshTimeZones()).toEqual(['Europe/Kyiv', 'Antarctica/Troll', 'Australia/Sydney']);
93+
expect(await config.scheduledRefreshTimeZones({})).toEqual(['Europe/Kyiv', 'Antarctica/Troll', 'Australia/Sydney']);
9294
});
9395

9496
test('scheduled_refresh_contexts', async () => {
9597
if (!config.scheduledRefreshContexts) {
9698
throw new Error('scheduledRefreshContexts was not defined in config.py');
9799
}
98100

99-
expect(await config.scheduledRefreshContexts()).toEqual([
101+
expect(await config.scheduledRefreshContexts({})).toEqual([
100102
{
101103
securityContext: {
102104
appid: 'test1', u: { prop1: 'value1' }
@@ -192,6 +194,9 @@ darwinSuite('Old Python Config', () => {
192194
queryRewrite: expect.any(Function),
193195
repositoryFactory: expect.any(Function),
194196
schemaVersion: expect.any(Function),
197+
contextToRoles: expect.any(Function),
198+
scheduledRefreshContexts: expect.any(Function),
199+
scheduledRefreshTimeZones: expect.any(Function),
195200
});
196201

197202
if (!config.checkAuth) {

0 commit comments

Comments
 (0)