Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def execute(
self.log.info("The Google Analytics property %s was created successfully.", prop.name)
GoogleAnalyticsPropertyLink.persist(
context=context,
property_id=prop.name.lstrip("properties/"),
property_id=prop.name.removeprefix("properties/"),
)

return Property.to_dict(prop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ def test_execute(self, property_to_dict_mock, hook_mock, _):
property_to_dict_mock.assert_called_once_with(property_returned)
assert property_created == property_serialized

@pytest.mark.parametrize(
("property_name", "expected_property_id"),
[
(TEST_PROPERTY_NAME, TEST_PROPERTY_ID),
# Stripping a character set instead of the literal prefix would also eat the leading "s".
("properties/s123", "s123"),
],
)
@mock.patch(f"{ANALYTICS_PATH}.GoogleAnalyticsPropertyLink")
@mock.patch(f"{ANALYTICS_PATH}.GoogleAnalyticsAdminHook")
@mock.patch(f"{ANALYTICS_PATH}.Property.to_dict")
def test_execute_persists_link_with_property_id(
self, _, hook_mock, property_link_mock, property_name, expected_property_id
):
hook_mock.return_value.create_property.return_value.name = property_name

GoogleAnalyticsAdminCreatePropertyOperator(
task_id="test_task",
analytics_property=mock.MagicMock(),
gcp_conn_id=GCP_CONN_ID,
impersonation_chain=IMPERSONATION_CHAIN,
).execute(context=None)

property_link_mock.persist.assert_called_once_with(context=None, property_id=expected_property_id)


class TestGoogleAnalyticsAdminDeletePropertyOperator:
@mock.patch(f"{ANALYTICS_PATH}.GoogleAnalyticsAdminHook")
Expand Down