-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3bf1a1
commit ec049a9
Showing
2 changed files
with
60 additions
and
1 deletion.
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
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,59 @@ | ||
import pytest | ||
|
||
from dbt.tracking import ( | ||
disable_tracking, | ||
initialize_from_flags, | ||
track_behavior_deprecation_warn, | ||
) | ||
from dbt_common.behavior_flags import Behavior | ||
from dbt_common.events.event_manager_client import ( | ||
add_callback_to_manager, | ||
cleanup_event_logger, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def snowplow_tracker(mocker): | ||
# initialize `active_user` without writing the cookie to disk | ||
initialize_from_flags(True, "") | ||
mocker.patch("dbt.tracking.User.set_cookie").return_value = {"id": 42} | ||
|
||
# add the relevant callback to the event manager | ||
add_callback_to_manager(track_behavior_deprecation_warn) | ||
|
||
# don't make a call, catch the request | ||
snowplow_tracker = mocker.patch("dbt.tracking.tracker.track_struct_event") | ||
|
||
yield snowplow_tracker | ||
|
||
# teardown | ||
cleanup_event_logger() | ||
disable_tracking() | ||
|
||
|
||
def test_false_evaluation_triggers_snowplow_tracking(snowplow_tracker): | ||
behavior = Behavior([{"name": "my_flag", "default": False}], {}) | ||
if behavior.my_flag: | ||
# trigger a False evaluation | ||
assert False, "This flag should evaluate to false and skip this line" | ||
assert snowplow_tracker.called | ||
|
||
|
||
def test_true_evaluation_does_not_trigger_snowplow_tracking(snowplow_tracker): | ||
behavior = Behavior([{"name": "my_flag", "default": True}], {}) | ||
if behavior.my_flag: | ||
pass | ||
else: | ||
# trigger a True evaluation | ||
assert False, "This flag should evaluate to false and skip this line" | ||
assert not snowplow_tracker.called | ||
|
||
|
||
def test_false_evaluation_does_not_trigger_snowplow_tracking_when_disabled(snowplow_tracker): | ||
disable_tracking() | ||
|
||
behavior = Behavior([{"name": "my_flag", "default": False}], {}) | ||
if behavior.my_flag: | ||
# trigger a False evaluation | ||
assert False, "This flag should evaluate to false and skip this line" | ||
assert not snowplow_tracker.called |