@@ -62,12 +62,13 @@ def test_push_event_queues_to_db(self):
6262 body = filter_by_fields ('13.14.15.16' , ['ip_dest' ])
6363 )['hits' ]['hits' ]
6464
65- self .assertEqual (len (honeypot_records ), 1 )
66- self .assertEqual (len (network_records ), 1 )
6765 # Find the records in the DB
6866 honeypot_record = honeypot_records [0 ]['_source' ]
6967 network_record = network_records [0 ]['_source' ]
7068
69+ self .assertGreater (len (honeypot_records ), 0 )
70+ self .assertGreater (len (network_records ), 0 )
71+
7172 # Compare the record found in the DB with the one pushed
7273 self .assertEqual (honeypot_record ["ip_src" ], honeypot_event .ip_src )
7374 self .assertEqual (honeypot_record ["ip_dest" ], honeypot_event .ip_dest )
@@ -76,13 +77,13 @@ def test_push_event_queues_to_db(self):
7677 self .assertEqual (network_record ["ip_dest" ], network_event .ip_dest )
7778
7879 # Delete test events from the database
79- connector .elasticsearch_events .delete_by_query (
80+ connector .elasticsearch_events .delete (
8081 index = 'honeypot_events' ,
81- body = filter_by_fields ( '11.22.33.44' , [ 'ip_dest' ])
82+ id = honeypot_records [ 0 ][ "_id" ]
8283 )
83- connector .elasticsearch_events .delete_by_query (
84+ connector .elasticsearch_events .delete (
8485 index = 'network_events' ,
85- body = filter_by_fields ( '13.14.15.16' , [ 'ip_dest' ])
86+ id = network_records [ 0 ][ "_id" ]
8687 )
8788
8889 def test_insert_to_credential_events (self ):
@@ -106,9 +107,10 @@ def test_insert_to_credential_events(self):
106107 index = 'credential_events' ,
107108 body = filter_by_fields ('88.99.11.22' , ['ip_src' ])
108109 )['hits' ]['hits' ]
109- self .assertEqual (len (credential_events ), 1 )
110110 credential_record = credential_events [0 ]['_source' ]
111111
112+ self .assertGreater (len (credential_events ), 0 )
113+
112114 # Compare the record found in the DB with the one pushed
113115 self .assertEqual (
114116 credential_record ["ip_src" ],
@@ -126,9 +128,9 @@ def test_insert_to_credential_events(self):
126128 )
127129
128130 # Delete test events from the database
129- connector .elasticsearch_events .delete_by_query (
131+ connector .elasticsearch_events .delete (
130132 index = 'credential_events' ,
131- body = filter_by_fields ( '88.99.11.22' , [ 'ip_src' ])
133+ id = credential_events [ 0 ][ "_id" ]
132134 )
133135
134136 def test_insert_events_data (self ):
@@ -146,23 +148,24 @@ def test_insert_events_data(self):
146148 # wait for insert
147149 time .sleep (1 )
148150
149- records = connector .elasticsearch_events .search (
151+ # Find the records in the DB
152+ event_records = connector .elasticsearch_events .search (
150153 index = 'data_events' ,
151154 body = filter_by_fields ('55.66.77.88' , ['ip_src' ])
152155 )['hits' ]['hits' ]
153- # Compare number of records present
154- self .assertEqual (len (records ), 1 )
155- # Find the record in the DB
156- event_record_data = records [0 ]['_source' ]
156+
157+ self .assertGreater (len (event_records ), 0 )
158+
159+ event_record_data = event_records [0 ]['_source' ]
157160 # Compare the record found in the DB with the one pushed
158161 self .assertEqual (event_record_data ["ip_src" ], event_data .ip_src )
159162 self .assertEqual (
160163 event_record_data ["data" ],
161164 event_data .data
162165 )
163- connector .elasticsearch_events .delete_by_query (
166+ connector .elasticsearch_events .delete (
164167 index = 'data_events' ,
165- body = filter_by_fields ( '55.66.77.88' , [ 'ip_src' ])
168+ id = event_records [ 0 ][ "_id" ]
166169 )
167170
168171
0 commit comments