-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewardstest.py
91 lines (67 loc) · 2.95 KB
/
rewardstest.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''Unit test for rewards.py'''
import rewards
import unittest
import pandas as pd
from datetime import date
from urllib import request
import settings
import os.path
class KnownValues(unittest.TestCase):
known_values = (
(2, 'Jméno a příjmení', 'Mikuláš Ferjenčík'),
(4, 'Doba', 4) ,
(7, 'Funkce', 'psavkyně mediálního odboru')
)
def test_known_payrol(self):
'''reading the payroll should give the expected values'''
known_payroll = rewards.read_payroll()
for row, col, val in self.known_values:
read_value = known_payroll[col][row]
self.assertEqual(read_value,val)
reference_business_days = (
(date(2016,1,1), date(2016,1,31), 20),
(date(2016,1,1), date(2016,12,31), 252),
(date(2016,7,1), date(2016,7,24), 14),
(date(2015,12,20), date(2016,1,7), 11)
)
def test_business_days(self):
'''The bussiness days should be like those on the web
http://kalendar.beda.cz/pracovni-kalkulacka '''
for startDate, endDate, number in self.reference_business_days:
self.assertEqual(number, rewards.business_days(startDate,endDate))
reference_month_last_day = (
('2016-02',29),
('2015-01',31),
('2017-02',28),
('2016-12',31),
('2016-11',30)
)
def test_last_month(self):
'''Check the number of the last day in month.'''
for month, day in self.reference_month_last_day:
self.assertEqual(month+'-'+str(day), str(rewards.last_day(month)))
startDate='2016-06-01'
endDate='2016-06-30'
user_ids=['3','4','16','17']
reference_link='https://redmine.pirati.cz/time_entries.csv?c[]=project&c[]=user&c[]=activity&c[]=issue&c[]=hours&c[]=cf_16&c[]=spent_on&f[]=spent_on&f[]=user_id&f[]=&op[spent_on]=><&op[user_id]==&utf8=%E2%9C%93&v[spent_on][]=2016-06-01&v[spent_on][]=2016-06-30&v[user_id][]=3&v[user_id][]=4&v[user_id][]=16&v[user_id][]=17'
def test_download_link(self):
'''Test the download link for '''
tested_link = rewards.create_link(self.startDate,self.endDate,self.user_ids)
self.assertEqual(tested_link, self.reference_link)
reference_project_pairs = (
('34', 'parlamentní tým'),
('15', 'zastupitelstvo hl. m. Prahy')
)
def test_project_lookup(self):
'''Test the project number lookup'''
for number, name in self.reference_project_pairs:
self.assertEqual(str(number), str(rewards.find_project_by_name(name)))
def test_file_download(self):
'''Test whether the utility downloads everyting all right. I had problems
downloading issues list in correct format.'''
rewards.safe_download('https://redmine.pirati.cz/projects.json','test_projects.json')
self.assertEqual(os.path.isfile('test_projects.json'), True)
if __name__ == '__main__':
unittest.main()