@@ -50,6 +50,117 @@ def test_delete(session, signal):
50
50
assert not get (db_session = session , signal_id = signal .id )
51
51
52
52
53
+ def test_filter_actions_deduplicate_different_entities (session , signal , project ):
54
+ from dispatch .signal .models import (
55
+ SignalFilter ,
56
+ SignalInstance ,
57
+ SignalFilterAction ,
58
+ )
59
+ from dispatch .signal .service import filter_signal
60
+ from dispatch .entity_type .models import EntityType
61
+ from dispatch .entity .models import Entity
62
+
63
+ entity_type_0 = EntityType (
64
+ name = "dedupe2-0" ,
65
+ field = "id" ,
66
+ regular_expression = None ,
67
+ project = project ,
68
+ )
69
+ session .add (entity_type_0 )
70
+
71
+ entity_0 = Entity (name = "dedupe2" , description = "test" , value = "foo" , entity_type = entity_type_0 )
72
+ session .add (entity_0 )
73
+
74
+ entity_1 = Entity (name = "dedupe2-1" , description = "test" , value = "foo" , entity_type = entity_type_0 )
75
+ session .add (entity_1 )
76
+
77
+ signal_instance_0 = SignalInstance (
78
+ raw = json .dumps ({"id" : "foo" }), project = project , signal = signal , entities = [entity_0 ]
79
+ )
80
+ session .add (signal_instance_0 )
81
+
82
+ signal_instance_1 = SignalInstance (
83
+ raw = json .dumps ({"id" : "foo" }), project = project , signal = signal , entities = [entity_1 ]
84
+ )
85
+ session .add (signal_instance_1 )
86
+ session .commit ()
87
+
88
+ # create deduplicate signal filter
89
+ signal_filter = SignalFilter (
90
+ name = "test" ,
91
+ description = "dedupe2" ,
92
+ expression = [
93
+ {"or" : [{"model" : "EntityType" , "field" : "id" , "op" : "==" , "value" : entity_type_0 .id }]}
94
+ ],
95
+ action = SignalFilterAction .deduplicate ,
96
+ window = 5 ,
97
+ project = project ,
98
+ )
99
+ signal .filters .append (signal_filter )
100
+
101
+ session .commit ()
102
+ assert not filter_signal (db_session = session , signal_instance = signal_instance_1 )
103
+ assert signal_instance_1 .filter_action == SignalFilterAction .none
104
+
105
+
106
+ def test_filter_actions_deduplicate_different_entities_types (session , signal , project ):
107
+ from dispatch .signal .models import (
108
+ SignalFilter ,
109
+ SignalInstance ,
110
+ SignalFilterAction ,
111
+ )
112
+ from dispatch .signal .service import filter_signal
113
+ from dispatch .entity_type .models import EntityType
114
+ from dispatch .entity .models import Entity
115
+
116
+ entity_type_0 = EntityType (
117
+ name = "dedupe0-0" ,
118
+ field = "id" ,
119
+ regular_expression = None ,
120
+ project = project ,
121
+ )
122
+ session .add (entity_type_0 )
123
+ entity_0 = Entity (name = "dedupe0" , description = "test" , value = "foo" , entity_type = entity_type_0 )
124
+ session .add (entity_0 )
125
+ signal_instance_0 = SignalInstance (
126
+ raw = json .dumps ({"id" : "foo" }), project = project , signal = signal , entities = [entity_0 ]
127
+ )
128
+ session .add (signal_instance_0 )
129
+
130
+ entity_type_1 = EntityType (
131
+ name = "dedupe0-1" ,
132
+ field = "id" ,
133
+ regular_expression = None ,
134
+ project = project ,
135
+ )
136
+ session .add (entity_type_1 )
137
+ entity_1 = Entity (name = "dedupe0-1" , description = "test" , value = "foo" , entity_type = entity_type_1 )
138
+ session .add (entity_1 )
139
+
140
+ signal_instance_1 = SignalInstance (
141
+ raw = json .dumps ({"id" : "foo" }), project = project , signal = signal , entities = [entity_1 ]
142
+ )
143
+ session .add (signal_instance_1 )
144
+ session .commit ()
145
+
146
+ # create deduplicate signal filter
147
+ signal_filter = SignalFilter (
148
+ name = "test" ,
149
+ description = "dedupe0" ,
150
+ expression = [
151
+ {"or" : [{"model" : "EntityType" , "field" : "id" , "op" : "==" , "value" : entity_type_1 .id }]}
152
+ ],
153
+ action = SignalFilterAction .deduplicate ,
154
+ window = 5 ,
155
+ project = project ,
156
+ )
157
+ signal .filters .append (signal_filter )
158
+
159
+ session .commit ()
160
+ assert not filter_signal (db_session = session , signal_instance = signal_instance_1 )
161
+ assert signal_instance_1 .filter_action == SignalFilterAction .none
162
+
163
+
53
164
def test_filter_actions_deduplicate (session , signal , project ):
54
165
from dispatch .signal .models import (
55
166
SignalFilter ,
@@ -61,14 +172,14 @@ def test_filter_actions_deduplicate(session, signal, project):
61
172
from dispatch .entity .models import Entity
62
173
63
174
entity_type = EntityType (
64
- name = "test " ,
175
+ name = "dedupe1 " ,
65
176
field = "id" ,
66
177
regular_expression = None ,
67
178
project = project ,
68
179
)
69
180
session .add (entity_type )
70
181
71
- entity = Entity (name = "test " , description = "test" , value = "foo" , entity_type = entity_type )
182
+ entity = Entity (name = "dedupe1 " , description = "test" , value = "foo" , entity_type = entity_type )
72
183
session .add (entity )
73
184
74
185
# create instance
@@ -81,13 +192,10 @@ def test_filter_actions_deduplicate(session, signal, project):
81
192
raw = json .dumps ({"id" : "foo" }), project = project , signal = signal , entities = [entity ]
82
193
)
83
194
session .add (signal_instance_2 )
84
- signal .entity_types .append (entity_type )
85
-
86
195
session .commit ()
87
-
88
196
# create deduplicate signal filter
89
197
signal_filter = SignalFilter (
90
- name = "test " ,
198
+ name = "dedupe1 " ,
91
199
description = "test" ,
92
200
expression = [
93
201
{"or" : [{"model" : "EntityType" , "field" : "id" , "op" : "==" , "value" : entity_type .id }]}
0 commit comments