-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils_data.py
More file actions
54 lines (45 loc) · 2.33 KB
/
test_utils_data.py
File metadata and controls
54 lines (45 loc) · 2.33 KB
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
import unittest
import lister.utils.data as du
import random
import string
class TestStringMethods(unittest.TestCase):
def generate_random_string(self, string_size=10):
return ''.join(random.choice(string.ascii_uppercase + string.digits)
for _ in range(string_size))
def test_get_single_random(self):
test_data = [self.generate_random_string() for i in xrange(0, 10)]
random_song = du.get_single_random(test_data)[0]
self.assertTrue(random_song in test_data,
'Chosen song is in the provided list')
def test_get_shuffled_list(self):
test_data = [self.generate_random_string() for i in xrange(0, 10)]
shuffled_list = du.get_shuffled_list(test_data)
self.assertTrue(len(test_data) == len(shuffled_list),
'The same amount of entries is returned')
for song in test_data:
self.assertTrue(song in shuffled_list,
'Song from shuffled list is in the provided list')
different = False
for index in xrange(len(test_data)):
if (shuffled_list[index] != test_data[index]):
different = True
self.assertTrue(different)
def test_get_search_filter(self):
test_data = [self.generate_random_string() for i in xrange(0, 10)]
cases = [{'label': 'Single string does not return a 1-element array ',
'input': test_data[0],
'expected': [test_data[0]]},
{'label': 'Two strings do not return two separate strings',
'input': ' '.join((test_data[0], test_data[1])),
'expected': [test_data[0], test_data[1]]},
{'label': 'Single filter does not return correct count',
'input': ':'.join((test_data[0], test_data[1])),
'expected': [test_data[0], test_data[1]]},
{'label': 'Multiple filter does not return correct count',
'input': ':'.join((test_data[0], test_data[1], test_data[2])),
'expected': [test_data[0], test_data[1], test_data[2]]}]
for case in cases:
result = du.get_search_filter(case['input'])
self.assertEqual(result, case['expected'], case['label'] + ' ' + str(result))
if __name__ == '__main__':
unittest.main()