Skip to content

Commit 8a1484d

Browse files
Tests: add testcase to check isUserBanned
1 parent 498431a commit 8a1484d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

tests/test_twitter_bot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def tearDown(self): ## destroy(destructor of object)
2929
def test_relevant(self):
3030

3131
search_list = ['#netsec', '#DNS', '#DANE', '#DNSSEC', '#QUIC', '#TCP/UDP', '#BGP', '#Routing', '#IP', '#IPv4', '#IPv6'
32-
, '#SNI', '#HTTP/0.9', '#HTTP0.9', '#HTTP2', '#HTTP/2', '#HTTP3', '#HTTP/3', '#TLS', '#TCP', '#UDP']
32+
, '#SNI', '#HTTP/0.9', '#HTTP0.9', '#HTTP2', '#HTTP/2', '#HTTP3', '#HTTP/3', '#TLS', '#TCP', '#UDP']
3333

3434
tweet_text1 = "iPhone SE delivery times suggest supply has caught up with demand https://t.co/yXoEdrLx5X TLS News"
3535
self.assertEqual(self.tw1.nawab_check_relevant(search_list,tweet_text1),1)
@@ -45,8 +45,8 @@ def test_check_id(self):
4545
def test_isUserBanned(self):
4646

4747
""" Check for Banned user"""
48-
self.assertEqual(self.tw1.isUserBanned("Ananthan2k","Ananthan2k"),True)
49-
self.assertEqual(self.tw1.isUserBanned("Pornhub","Ananthan2k"),False)
48+
self.assertEqual(self.tw1.isUserBanned("Ananthan2k","Ananthan2k"),False)
49+
self.assertEqual(self.tw1.isUserBanned("freeman","jumbo_lane"),True)
5050

5151
def test_isSafeword(self):
5252

twitter_bot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ def __isUserwhitelisted(self, userName):
9090
return True
9191
return False
9292

93-
def __isUserBanned(self, userName, admin_user):
93+
def isUserBanned(self, userName, admin_user):
9494
"""
9595
Search if the Blacklisted user is in file,and blacklist the bot's account
9696
"""
9797
if not any((str(acc["Blacklist"]).lower() == userName.lower()) or (admin_user.lower() == userName.lower()) for index, acc in self.data.iterrows()):
9898
return True
9999
return False
100100

101-
def __isSafeKeyword(self, tweetText):
101+
def isSafeKeyword(self, tweetText):
102102
"""
103103
Search if tweettext is safe
104104
"""
@@ -129,7 +129,7 @@ def nawab_find_prev_date(self):
129129
break
130130
return previous_date
131131

132-
def __nawab_check_relevant(self, query, text):
132+
def nawab_check_relevant(self, query, text):
133133
"""
134134
check for count of keywords in text
135135
"""
@@ -140,7 +140,7 @@ def __nawab_check_relevant(self, query, text):
140140
cnt += text.count(key)
141141
return cnt
142142

143-
def __nawab_check_tweet(self, tweet_id):
143+
def nawab_check_tweet(self, tweet_id):
144144
"""
145145
Check if current tweet id is in tid_store or not
146146
"""
@@ -179,13 +179,13 @@ def nawab_search(self, api, query):
179179
## minimum no of keywords required
180180
min_freq = 2
181181

182-
if (self.__nawab_check_tweet(id)) and ('RT @' in text):
182+
if (self.nawab_check_tweet(id)) and ('RT @' in text):
183183
self.nawab_log(str(id) + ' already exists in the database or it is a retweet', 'error', 'Twitter_Bot ')
184184
else:
185-
if (self.__isUserwhitelisted(user) or (self.__isUserBanned(user, admin_user) and self.__isSafeKeyword(text))):
186-
if not (self.__nawab_check_tweet(id)):
185+
if (self.__isUserwhitelisted(user) or (self.isUserBanned(user, admin_user) and self.isSafeKeyword(text))):
186+
if not (self.nawab_check_tweet(id)):
187187
##check if it is a relevant tweet
188-
if self.__nawab_check_relevant(query, text) >= min_freq:
188+
if self.nawab_check_relevant(query, text) >= min_freq:
189189
self.nawab_log('Id: ' + str(id) + 'is a relevant tweet and is stored to the db from this iteration', 'info', 'Twitter_Bot ')
190190
self.nawab_store_id(id, True)
191191
else:

0 commit comments

Comments
 (0)