Skip to content

Commit 6aa6259

Browse files
committed
adding more unit tests
1 parent 0e13e2c commit 6aa6259

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spotify_bot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def search(query, query_type, auth_token):
8585
def is_empty_query(query):
8686
return True if query == '' else False
8787

88+
def check_no_results(results):
89+
return True if len(results) == 0 else False
90+
8891
# main function to handle all inline queries
8992
def inlinequery(bot, update):
9093

@@ -108,7 +111,7 @@ def inlinequery(bot, update):
108111
input_message_content=InputTextMessageContent(response)))
109112

110113
# if there are no results, tell user
111-
if len(results) == 0:
114+
if check_no_results(results):
112115
results.append(InlineQueryResultArticle(id=uuid4(),
113116
title="No results found",
114117
input_message_content=InputTextMessageContent("No results found")))

tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ class TestInlineQueryHandling(unittest.TestCase):
44
def setUp(self):
55
self.emptyQuery = ''
66
self.nonEmptyQuery = 'Coldplay'
7+
self.emptyResults = []
8+
self.nonEmptyResults = [{"artist": "Coldplay"}]
79

810
def test_empty_query(self):
911
self.assertTrue(spotify_bot.is_empty_query(self.emptyQuery))
1012

1113
def test_nonempty_query(self):
1214
self.assertFalse(spotify_bot.is_empty_query(self.nonEmptyQuery))
1315

16+
def test_empty_results(self):
17+
self.assertTrue(spotify_bot.check_no_results(self.emptyResults))
18+
19+
def test_nonempty_results(self):
20+
self.assertFalse(spotify_bot.check_no_results(self.nonEmptyResults))
21+
1422
if __name__ == '__main__':
1523
unittest.main()

0 commit comments

Comments
 (0)