villebro commented on code in PR #21570:
URL: https://github.com/apache/superset/pull/21570#discussion_r979990242
##########
tests/unit_tests/db_engine_specs/test_bigquery.py:
##########
@@ -186,9 +186,61 @@ def test_unmask_encrypted_extra() -> None:
}
)
- assert json.loads(BigQueryEngineSpec.unmask_encrypted_extra(old, new)) == {
+ assert json.loads(BigQueryEngineSpec.unmask_encrypted_extra(old, new)) ==
{ # type: ignore
"credentials_info": {
"project_id": "yellow-unicorn-314419",
"private_key": "SECRET",
},
}
+
+
+def test_unmask_encrypted_extra_when_empty() -> None:
+ """
+ Test that a None value works for ``encrypted_extra``.
+ """
+ from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+ old = None
+ new = json.dumps(
+ {
+ "credentials_info": {
+ "project_id": "yellow-unicorn-314419",
+ "private_key": "XXXXXXXXXX",
+ },
+ }
+ )
+
+ assert json.loads(BigQueryEngineSpec.unmask_encrypted_extra(old, new)) ==
{ # type: ignore
+ "credentials_info": {
+ "project_id": "yellow-unicorn-314419",
+ "private_key": "XXXXXXXXXX",
+ },
+ }
+
+
+def test_unmask_encrypted_extra_when_new_is_empty() -> None:
+ """
+ Test that a None value works for ``encrypted_extra``.
+ """
+ from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+ old = json.dumps(
+ {
+ "credentials_info": {
+ "project_id": "black-sanctum-314419",
+ "private_key": "SECRET",
+ },
+ }
+ )
+ new = None
+
+ assert BigQueryEngineSpec.unmask_encrypted_extra(old, new) == None
+
+
+def test_mask_encrypted_extra_when_empty() -> None:
+ """
+ Test that the encrypted extra will return a none value if the field is
empty.
+ """
+ from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+ assert BigQueryEngineSpec.mask_encrypted_extra(None) == None
Review Comment:
nit:
```suggestion
assert BigQueryEngineSpec.mask_encrypted_extra(None) is None
```
##########
superset/db_engine_specs/base.py:
##########
@@ -1614,7 +1614,9 @@ def get_impersonation_key(cls, user: Optional[User]) ->
Any:
return user.username if user else None
@classmethod
- def mask_encrypted_extra(cls, encrypted_extra: str) -> str:
+ def mask_encrypted_extra(
+ cls, encrypted_extra: Union[str, None]
+ ) -> Union[str, None]:
Review Comment:
nit
```suggestion
) -> Optional[str]:
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]