-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.py
148 lines (134 loc) · 5.63 KB
/
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import datetime
import unittest
from xml.etree import ElementTree
import phpreport
from phpreport import Customer, PHPReportObject, Project, Task, User
class TestUser(unittest.TestCase):
def setUp(self):
PHPReportObject.instances.clear()
def test_empty(self):
user = User()
self.assertIs(user, User.find(-1))
self.assertIsInstance(user, User)
self.assertEqual(user.phpreport_id, -1)
self.assertEqual(user.login, "<unknown>")
def test_simple_parse(self):
element = ElementTree.fromstring("""
<user>
<id>22</id>
<login>testuser</login>
<userGroups/>
</user>""")
user = User.from_element(element)
self.assertIs(user, User.find(22))
self.assertIsInstance(user, User)
self.assertEqual(user.phpreport_id, 22)
self.assertEqual(user.login, "testuser")
class TestCustomer(unittest.TestCase):
def test_empty(self):
Customer()
customer = Customer.find(-1)
self.assertIsInstance(customer, Customer)
self.assertEqual(customer.phpreport_id, -1)
self.assertEqual(customer.name, "<unknown>")
def test_simple_parse(self):
element = ElementTree.fromstring("""
<customer>
<id>99</id>
<sectorId>1</sectorId>
<name>Custom Er</name>
<type>large</type>
<url>http://customer.com</url>
</customer>""")
customer = Customer.from_element(element)
self.assertIs(customer, Customer.find(99))
self.assertEqual(customer.phpreport_id, 99)
self.assertEqual(customer.name, "Custom Er")
class TestProject(unittest.TestCase):
def test_empty(self):
project = Project()
self.assertIs(project, Project.find(-1))
self.assertIsInstance(project, Project)
self.assertEqual(project.phpreport_id, -1)
self.assertEqual(project.description, "<description>")
self.assertEqual(project.customer_id, -1)
self.assertIs(project.customer, Customer.find(-1))
self.assertEqual(project.init_date, phpreport.DEFAULT_DATE.date())
self.assertEqual(project.end_date, phpreport.DEFAULT_DATE.date())
def test_simple_parse(self):
element = ElementTree.fromstring("""
<project>
<id>230</id>
<areaId>3</areaId>
<customerId>-1</customerId>
<activation/>
<invoice>203</invoice>
<description>Very cool</description>
<customerName><unknown></customerName>
<fullDescription>Very very cool</fullDescription>
<init format="Y-m-d">2016-09-29</init>
<end format="Y-m-d">2018-02-13</end>
<estHours>24</estHours>
<type>per_goals</type>
<movedHours/>
<schedType/>
</project>""")
project = Project.from_element(element)
self.assertIs(project, Project.find(230))
self.assertIsInstance(project, Project)
self.assertEqual(project.phpreport_id, 230)
self.assertEqual(project.description, "Very cool")
self.assertEqual(project.customer_id, -1)
self.assertIs(project.customer, Customer.find(-1))
self.assertEqual(project.init_date, datetime.date(2016, 9, 29))
self.assertEqual(project.end_date, datetime.date(2018, 2, 13))
class TestTask(unittest.TestCase):
def test_empty(self):
task = Task()
self.assertIs(task, Task.find(-1))
self.assertEqual(task.phpreport_id, -1)
self.assertEqual(task.user_id, -1)
self.assertIs(task.user, User.find(-1))
self.assertEqual(task.project_id, -1)
self.assertEqual(task.project, Project.find(-1))
self.assertEqual(task.text, "")
self.assertEqual(task.story, "")
self.assertEqual(task.ttype, "")
self.assertEqual(task.date, phpreport.DEFAULT_DATE.date())
self.assertEqual(task.init_time, phpreport.DEFAULT_DATE)
self.assertEqual(task.end_time, phpreport.DEFAULT_DATE + datetime.timedelta(days=1))
self.assertFalse(task.onsite)
self.assertFalse(task.telework)
def test_simple_parse(self):
element = ElementTree.fromstring("""
<task>
<id>200291</id>
<date format="Y-m-d">2023-02-17</date>
<initTime>03:30</initTime>
<endTime>08:22</endTime>
<story>likely</story>
<telework>true</telework>
<onsite>true</onsite>
<ttype>implementation</ttype>
<text>Adding a test for parsing of tasks.</text>
<phase>fase</phase>
<userId>-1</userId>
<projectId>-1</projectId>
</task>""")
task = Task.from_element(element)
self.assertIs(task, Task.find(200291))
self.assertEqual(task.phpreport_id, 200291)
self.assertEqual(task.user_id, -1)
self.assertIs(task.user, User.find(-1))
self.assertEqual(task.project_id, -1)
self.assertEqual(task.project, Project.find(-1))
self.assertEqual(task.text, "Adding a test for parsing of tasks.")
self.assertEqual(task.story, "likely")
self.assertEqual(task.ttype, "implementation")
self.assertEqual(task.date, datetime.date(2023, 2, 17))
self.assertEqual(task.init_time, datetime.datetime(2023, 2, 17, 3, 30))
self.assertEqual(task.end_time, datetime.datetime(2023, 2, 17, 8, 22))
self.assertTrue(task.onsite)
self.assertTrue(task.telework)
if __name__ == '__main__':
unittest.main()