Skip to content

Commit 827569c

Browse files
committed
refactor: consolidate grants tests
1 parent 543aba5 commit 827569c

1 file changed

Lines changed: 39 additions & 33 deletions

File tree

tests/core/test_model.py

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11737,6 +11737,45 @@ def test_use_original_sql():
1173711737
assert model.post_statements_[0].sql == "CREATE TABLE post (b INT)"
1173811738

1173911739

11740+
def test_grants():
11741+
expressions = d.parse("""
11742+
MODEL (
11743+
name test.table,
11744+
kind FULL,
11745+
grants (
11746+
'select' = ['user1', 123, admin_role, 'user2'],
11747+
'insert' = 'admin',
11748+
'roles/bigquery.dataViewer' = ["group:data_eng@company.com", 'user:someone@company.com'],
11749+
'update' = 'admin'
11750+
)
11751+
);
11752+
SELECT 1 as id
11753+
""")
11754+
model = load_sql_based_model(expressions)
11755+
assert model.grants == {
11756+
"select": ["user1", "123", "admin_role", "user2"],
11757+
"insert": ["admin"],
11758+
"roles/bigquery.dataViewer": ["group:data_eng@company.com", "user:someone@company.com"],
11759+
"update": ["admin"],
11760+
}
11761+
11762+
model = create_sql_model(
11763+
"db.table",
11764+
parse_one("SELECT 1 AS id"),
11765+
kind="FULL",
11766+
grants={
11767+
"select": ["user1", "user2"],
11768+
"insert": ["admin"],
11769+
"roles/bigquery.dataViewer": "user:data_eng@company.com",
11770+
},
11771+
)
11772+
assert model.grants == {
11773+
"select": ["user1", "user2"],
11774+
"insert": ["admin"],
11775+
"roles/bigquery.dataViewer": ["user:data_eng@company.com"],
11776+
}
11777+
11778+
1174011779
@pytest.mark.parametrize(
1174111780
"kind",
1174211781
[
@@ -11914,21 +11953,6 @@ def test_grants_unresolved_macro_errors():
1191411953
load_sql_based_model(expressions3)
1191511954

1191611955

11917-
def test_grants_mixed_types_conversion():
11918-
expressions = d.parse("""
11919-
MODEL (
11920-
name test.mixed_types,
11921-
kind FULL,
11922-
grants (
11923-
'select' = ['user1', 123, admin_role, 'user2']
11924-
)
11925-
);
11926-
SELECT 1 as id
11927-
""")
11928-
model = load_sql_based_model(expressions)
11929-
assert model.grants == {"select": ["user1", "123", "admin_role", "user2"]}
11930-
11931-
1193211956
def test_grants_empty_values():
1193311957
model1 = create_sql_model(
1193411958
"db.table", parse_one("SELECT 1 AS id"), kind="FULL", grants={"select": []}
@@ -11939,24 +11963,6 @@ def test_grants_empty_values():
1193911963
assert model2.grants is None
1194011964

1194111965

11942-
def test_grants_backward_compatibility():
11943-
model = create_sql_model(
11944-
"db.table",
11945-
parse_one("SELECT 1 AS id"),
11946-
kind="FULL",
11947-
grants={
11948-
"select": ["user1", "user2"],
11949-
"insert": ["admin"],
11950-
"roles/bigquery.dataViewer": ["user:data_eng@company.com"],
11951-
},
11952-
)
11953-
assert model.grants == {
11954-
"select": ["user1", "user2"],
11955-
"insert": ["admin"],
11956-
"roles/bigquery.dataViewer": ["user:data_eng@company.com"],
11957-
}
11958-
11959-
1196011966
@pytest.mark.parametrize(
1196111967
"kind, expected",
1196211968
[

0 commit comments

Comments
 (0)