-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_test.py
100 lines (85 loc) · 3.42 KB
/
unit_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import unittest
from unittest.mock import Mock, patch
from spotify import search_artist, get_data
from genius import get_lyrics
from app import saved_artists, getDB, randomArtist
KEY_INPUT = "input"
KEY_EXPECTED = "expected"
class testCaseNoMocking(unittest.TestCase):
def setUp(self):
self.testValidArtist = [
{
KEY_INPUT: [
"BTOB",
"YOASOBI",
"ヨルシカ",
],
KEY_EXPECTED: [
"2hcsKca6hCfFMwwdbFvenJ",
"64tJ2EAv1R6UaZqc4iOCyj",
"4UK2Lzi6fBfUi9rpDt6cik"
],
},
]
self.testLyricsLink = [
{
KEY_INPUT: [
"Missing You",
"怪物",
"ただ君に晴れ"
],
KEY_EXPECTED: [
"https://genius.com/Diddy-ill-be-missing-you-lyrics",
"https://genius.com/Genius-romanizations-yoasobi-monster-kaibutsu-romanized-lyrics",
"https://genius.com/Yorushika-just-a-sunny-day-for-you-lyrics"
],
},
]
def testValidArtist(self):
for test in self.testValidArtist:
actual_result0 = search_artist(test[KEY_INPUT][0])
actual_result1 = search_artist(test[KEY_INPUT][1])
actual_result2 = search_artist(test[KEY_INPUT][2])
expected_result = test[KEY_EXPECTED]
self.assertEqual(actual_result0["artistID"], expected_result[0])
self.assertEqual(actual_result1["artistID"], expected_result[1])
self.assertEqual(actual_result2["artistID"], expected_result[2])
def testLyricsLink(self):
for test in self.testLyricsLink:
actual_result = get_lyrics(test[KEY_INPUT])
expected_result = test[KEY_EXPECTED]
self.assertEqual(actual_result["lyrics"], expected_result[0])
class testCaseMocking(unittest.TestCase):
def setUp(self):
# self.initial_db_mock = [
# saved_artists(username = "User", artist_ID = ""),
# saved_artists(username = "User", artist_ID = ""),
# saved_artists(username = "User", artist_ID = "")
# ]
self.testWrongLyrics = [
{
KEY_INPUT: [
"2hcsKca6hCfFMwwdbFvenJ",
"64tJ2EAv1R6UaZqc4iOCyj",
"4UK2Lzi6fBfUi9rpDt6cik"
],
KEY_EXPECTED: "2hcsKca6hCfFMwwdbFvenJ"
},
]
def test_get_artist_url(self):
def not_random_choice(l):
return l[0]
for test in self.testWrongLyrics:
with patch("app.random.choice", not_random_choice):
actual_result1 = randomArtist(test[KEY_INPUT][1])
actual_result2 = randomArtist(test[KEY_INPUT][2])
expected_result = test[KEY_EXPECTED]
self.assertEqual(actual_result1, expected_result)
self.assertEqual(actual_result2, expected_result)
# def testUser(self):
# with patch("app.saved_artists.query") as mock_query:
# mock_query.all.return_value = self.initial_db_mock
# datas = getDB("All")
# self.assertEqual(datas, (["User"], []))
if __name__ == '__main__':
unittest.main()