18
18
19
19
import pytest
20
20
from django .db import connection
21
- from django .test import override_settings
22
21
23
22
from aap_eda .analytics .collector import AnalyticsCollector , gather
24
23
@@ -42,12 +41,11 @@ def collector():
42
41
return collector
43
42
44
43
45
- @patch ("aap_eda.analytics.collector.flag_enabled" )
44
+ @patch ("aap_eda.analytics.collector.features.ANALYTICS" , True )
46
45
@patch ("aap_eda.analytics.collector.AnalyticsCollector" )
47
- def test_gather_when_enabled (mock_collector_cls , mock_flag_enabled ):
46
+ def test_gather_when_enabled (mock_collector_cls ):
48
47
"""Test gather function when FEATURE_EDA_ANALYTICS_ENABLED
49
48
is set to True"""
50
- mock_flag_enabled .return_value = True
51
49
mock_collector_cls .return_value = MagicMock ()
52
50
mock_logger = MagicMock ()
53
51
@@ -58,7 +56,6 @@ def test_gather_when_enabled(mock_collector_cls, mock_flag_enabled):
58
56
logger = mock_logger ,
59
57
)
60
58
61
- mock_flag_enabled .assert_called_once_with ("FEATURE_EDA_ANALYTICS_ENABLED" )
62
59
mock_collector_cls .assert_called_once_with (
63
60
collector_module = ANY ,
64
61
collection_type = "manual" ,
@@ -67,27 +64,19 @@ def test_gather_when_enabled(mock_collector_cls, mock_flag_enabled):
67
64
assert result is not None
68
65
69
66
70
- @patch ("aap_eda.analytics.collector.flag_enabled" )
71
- def test_gather_when_disabled (mock_flag_enabled ):
67
+ @patch ("aap_eda.analytics.collector.features.ANALYTICS" , False )
68
+ def test_gather_when_disabled ():
72
69
"""Test gather function when FEATURE_EDA_ANALYTICS_ENABLED
73
70
is set to False"""
74
- mock_flag_enabled .return_value = False
75
71
mock_logger = MagicMock ()
76
-
77
72
result = gather (logger = mock_logger )
78
-
79
- mock_logger .info .assert_called_once_with (
80
- "FEATURE_EDA_ANALYTICS_ENABLED is set to False."
81
- )
82
73
assert result is None
83
74
84
75
85
76
@pytest .mark .django_db
86
- @patch ("aap_eda.analytics.collector.flag_enabled" )
77
+ @patch ("aap_eda.analytics.collector.features.ANALYTICS" , True )
87
78
@patch ("aap_eda.analytics.collector.AnalyticsCollector" )
88
- def test_gather_uses_default_logger (mock_collector_cls , mock_flag_enabled ):
89
- mock_flag_enabled .return_value = True
90
-
79
+ def test_gather_uses_default_logger (mock_collector_cls ):
91
80
with patch (
92
81
"aap_eda.analytics.collector.logging.getLogger"
93
82
) as mock_get_logger :
@@ -119,20 +108,15 @@ def test_shipping_disabled_logs_warning(
119
108
with patch (
120
109
"aap_eda.analytics.utils.get_insights_tracking_state" ,
121
110
return_value = insights_tracking_state ,
111
+ ), patch (
112
+ "aap_eda.analytics.collector.features.ANALYTICS" , feature_flag_state
122
113
):
123
- with override_settings (
124
- FLAGS = {
125
- "FEATURE_EDA_ANALYTICS_ENABLED" : [
126
- ("boolean" , feature_flag_state )
127
- ]
128
- }
129
- ):
130
- assert collector ._is_shipping_configured () is expected
131
-
132
- if not expected :
133
- collector .logger .warning .assert_called_once_with (
134
- "Insights for Event Driven Ansible is not enabled."
135
- )
114
+ assert collector ._is_shipping_configured () is expected
115
+
116
+ if not expected :
117
+ collector .logger .warning .assert_called_once_with (
118
+ "Insights for Event Driven Ansible is not enabled."
119
+ )
136
120
137
121
138
122
@pytest .mark .django_db
0 commit comments