~edwinvandeven/openstudio/2017.0

« back to all changes in this revision

Viewing changes to tests/controllers/test_14_tasks_controller.py

  • Committer: Edwin van de Ven
  • Date: 2017-10-10 11:43:48 UTC
  • Revision ID: edwinvandeven@home.nl-20171010114348-kjon60md9vz6n4uf
Added test for profile cancel orders

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
'''
4
 
    py.test test cases to test OpenStudio.
5
 
    These tests run based on webclient and need web2py server running.
6
 
'''
7
 
 
8
 
from gluon.contrib.populate import populate
9
 
 
10
 
from populate_os_tables import populate_tasks
11
 
 
12
 
 
13
 
def test_task_list(client, web2py):
14
 
    '''
15
 
        Test if the task list is working
16
 
    '''
17
 
    # get url so admin user is created
18
 
    url = '/tasks/index'
19
 
    client.get(url)
20
 
    assert client.status == 200
21
 
 
22
 
    populate_tasks(web2py)
23
 
 
24
 
    # get the page again now everything's been populated
25
 
    client.get(url)
26
 
    assert client.status == 200
27
 
 
28
 
    assert 'grapes' in client.text
29
 
 
30
 
    # check colors for tasks today & yesterday
31
 
    assert 'red' in client.text
32
 
    assert 'green' in client.text
33
 
 
34
 
 
35
 
def test_task_list_finished(client, web2py):
36
 
    '''
37
 
        Test if the task list is working for finished tasks
38
 
    '''
39
 
    # get url so admin user is created
40
 
    url = '/tasks/index'
41
 
    client.get(url)
42
 
    assert client.status == 200
43
 
 
44
 
    populate_tasks(web2py)
45
 
 
46
 
    # get the page again now everything's been populated
47
 
    url = '/tasks/index?filter=finished'
48
 
    client.get(url)
49
 
    assert client.status == 200
50
 
 
51
 
    assert 'bananas' in client.text
52
 
    assert 'line-through' in client.text # class for finished tasks in table row
53
 
 
54
 
 
55
 
def test_task_list_all(client, web2py):
56
 
    '''
57
 
        Test if the task list is working for finished tasks
58
 
    '''
59
 
    # get url so admin user is created
60
 
    url = '/tasks/index'
61
 
    client.get(url)
62
 
    assert client.status == 200
63
 
 
64
 
    populate_tasks(web2py)
65
 
 
66
 
    # get the page again now everything's been populated
67
 
    url = '/tasks/index?filter=all'
68
 
    client.get(url)
69
 
    assert client.status == 200
70
 
 
71
 
    assert 'bananas' in client.text
72
 
    assert 'grapes' in client.text
73
 
 
74
 
 
75
 
def test_task_pinboard(client, web2py):
76
 
    '''
77
 
        Test if open tasks for today are listed on the pin board
78
 
    '''
79
 
    # get url so admin user is created
80
 
    url = '/pinboard/index'
81
 
    client.get(url)
82
 
    assert client.status == 200
83
 
 
84
 
    populate_tasks(web2py)
85
 
 
86
 
    # get the page again now everything's been populated
87
 
    client.get(url)
88
 
    assert client.status == 200
89
 
 
90
 
    # make sure the item for today is in the list on the pin board
91
 
    assert 'grapes' in client.text
92
 
 
93
 
 
94
 
def test_task_add(client, web2py):
95
 
    '''
96
 
        Can we add a new task?
97
 
    '''
98
 
    # get url so admin user is created
99
 
    url = '/tasks/add'
100
 
    client.get(url)
101
 
    assert client.status == 200
102
 
 
103
 
    populate_tasks(web2py)
104
 
 
105
 
    # post the data
106
 
    data = { 'Task'         : 'Hello world!',
107
 
             'Description'  : 'Adding some items to the list',
108
 
             'Duedate'      : '2014-01-01',
109
 
             'Priority'     : 1,
110
 
             'auth_user_id' : 1 }
111
 
 
112
 
    url = '/tasks/add'
113
 
    client.post(url, data=data)
114
 
    assert client.status == 200
115
 
 
116
 
    assert 'world!' in client.text
117
 
 
118
 
 
119
 
def test_task_customer_add(client, web2py):
120
 
    '''
121
 
        Can we add a new task linked to a customer?
122
 
    '''
123
 
    # get url so admin user is created
124
 
    url = '/tasks/add'
125
 
    client.get(url)
126
 
    assert client.status == 200
127
 
 
128
 
    populate_tasks(web2py)
129
 
 
130
 
    # post the data
131
 
    data = { 'Task'            : 'Hello world!',
132
 
             'Description'     : 'Adding some items to the list',
133
 
             'Duedate'         : '2014-01-01',
134
 
             'Priority'        : 1,
135
 
             'auth_user_id'    : 2 }
136
 
 
137
 
    url = '/tasks/add?cuID=1001'
138
 
    client.post(url, data=data)
139
 
    assert client.status == 200
140
 
 
141
 
    assert 'world!' in client.text
142
 
 
143
 
    # check database
144
 
    query = (web2py.db.tasks.auth_customer_id == 1001)
145
 
    count = web2py.db(query).count()
146
 
 
147
 
    assert count == 1
148
 
 
149
 
 
150
 
def test_task_workshop_add(client, web2py):
151
 
    '''
152
 
        Can we add a new task linked to a workshop?
153
 
    '''
154
 
    # get url so admin user is created
155
 
    url = '/tasks/add'
156
 
    client.get(url)
157
 
    assert client.status == 200
158
 
 
159
 
    populate_tasks(web2py)
160
 
 
161
 
    # post the data
162
 
    data = { 'Task'         : 'Hello world!',
163
 
             'Description'  : 'Adding some items to the list',
164
 
             'Duedate'      : '2014-01-01',
165
 
             'Priority'     : 1,
166
 
             'auth_user_id' : 1 }
167
 
 
168
 
    url = '/tasks/add?wsID=1'
169
 
    client.post(url, data=data)
170
 
    assert client.status == 200
171
 
 
172
 
    assert 'world!' in client.text
173
 
 
174
 
    # check database
175
 
    query = (web2py.db.tasks.workshops_id == 1)
176
 
    count = web2py.db(query).count()
177
 
 
178
 
    assert count == 1
179
 
 
180
 
 
181
 
def test_task_edit(client, web2py):
182
 
    '''
183
 
        Can we edit a task?
184
 
    '''
185
 
    # get url so admin user is created
186
 
    url = '/tasks/index'
187
 
    client.get(url)
188
 
    assert client.status == 200
189
 
 
190
 
    populate_tasks(web2py)
191
 
    web2py.db.auth_user.insert(
192
 
        first_name = 'tasks',
193
 
        last_name  = 'user',
194
 
        email      = 'tasks@openstudioproject.com',
195
 
        password   = '')
196
 
 
197
 
    web2py.db.commit()
198
 
 
199
 
    # post the data
200
 
    url = '/tasks/edit?tID=1'
201
 
    client.get(url)
202
 
    assert client.status == 200
203
 
 
204
 
    data = { 'id'           : 1,
205
 
             'Task'         : 'Hello world!',
206
 
             'Description'  : 'Adding some items to the list',
207
 
             'Duedate'      : '2014-01-01',
208
 
             'Priority'     : 1,
209
 
             'auth_user_id' : 2,
210
 
             'wsID'         : '',
211
 
             'cuID'         : '' }
212
 
 
213
 
    url = '/tasks/edit?tID=1'
214
 
    client.post(url, data=data)
215
 
    assert client.status == 200
216
 
 
217
 
    assert 'Tasks' in client.text # verify redirection
218
 
 
219
 
    assert 'world!' in client.text