1
|
import os
|
2
|
import shutil
|
3
|
import StringIO
|
4
|
import time
|
5
|
|
6
|
import pytest
|
7
|
|
8
|
from quixote import cleanup, get_publisher
|
9
|
from wcs.qommon import errors, sessions
|
10
|
from qommon.ident.password_accounts import PasswordAccount
|
11
|
from wcs.qommon.http_request import HTTPRequest
|
12
|
from wcs.qommon.template import get_current_theme
|
13
|
from wcs.categories import Category
|
14
|
from wcs.roles import Role
|
15
|
from wcs.workflows import Workflow
|
16
|
from wcs.formdef import FormDef
|
17
|
from wcs import fields
|
18
|
|
19
|
from utilities import get_app, login, create_temporary_pub
|
20
|
|
21
|
def setup_module(module):
|
22
|
cleanup()
|
23
|
|
24
|
global pub
|
25
|
|
26
|
pub = create_temporary_pub()
|
27
|
|
28
|
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
|
29
|
pub.set_app_dir(req)
|
30
|
pub.cfg['identification'] = {'methods': ['password']}
|
31
|
pub.write_cfg()
|
32
|
|
33
|
def create_user():
|
34
|
if pub.user_class.has_key('user'):
|
35
|
return
|
36
|
user1 = pub.user_class(name='user')
|
37
|
user1.id = 'admin'
|
38
|
user1.is_admin = False
|
39
|
user1.store()
|
40
|
|
41
|
account1 = PasswordAccount(id='user')
|
42
|
account1.set_password('user')
|
43
|
account1.user_id = user1.id
|
44
|
account1.store()
|
45
|
|
46
|
pub.cfg['identification'] = {'methods': ['password']}
|
47
|
pub.write_cfg()
|
48
|
|
49
|
return user1
|
50
|
|
51
|
def create_formdef():
|
52
|
FormDef.wipe()
|
53
|
formdef = FormDef()
|
54
|
formdef.name = 'test'
|
55
|
formdef.fields = []
|
56
|
formdef.store()
|
57
|
return formdef
|
58
|
|
59
|
def teardown_module(module):
|
60
|
shutil.rmtree(pub.APP_DIR)
|
61
|
|
62
|
def test_with_user():
|
63
|
user = create_user()
|
64
|
app = login(get_app(pub), username='user', password='user')
|
65
|
resp = app.get('/', status=200)
|
66
|
resp = app.get('/myspace/', status=200)
|
67
|
|
68
|
def test_myspace_with_user_forms():
|
69
|
user = create_user()
|
70
|
formdef = create_formdef()
|
71
|
|
72
|
cat = Category(name='cat')
|
73
|
cat.store()
|
74
|
formdef.category_id = cat.id
|
75
|
formdef.enable_tracking_codes = True
|
76
|
|
77
|
wf = Workflow(name='status')
|
78
|
st1 = wf.add_status('Status1', 'st1')
|
79
|
wf.store()
|
80
|
formdef.workflow_id = wf.id
|
81
|
formdef.store()
|
82
|
|
83
|
formdef.data_class().wipe()
|
84
|
formdata = formdef.data_class()()
|
85
|
formdata.user_id = user.id
|
86
|
formdata.status = 'wf-st1'
|
87
|
formdata.data = {}
|
88
|
formdata.store()
|
89
|
draft = formdef.data_class()()
|
90
|
draft.user_id = user.id
|
91
|
draft.status = 'draft'
|
92
|
draft.data = {}
|
93
|
draft.store()
|
94
|
|
95
|
app = login(get_app(pub), username='user', password='user')
|
96
|
resp = app.get('/myspace/')
|
97
|
assert 'Status1' in resp
|
98
|
assert '<a href="/cat/test/%s/"' % formdata.id in resp
|
99
|
assert 'Draft' in resp
|
100
|
assert '<a href="/cat/test/%s"' % draft.id in resp
|
101
|
resp = app.get('/cat/test/%s' % formdata.id)
|
102
|
resp.status_int = 200
|
103
|
resp = app.get('/cat/test/%s' % draft.id, status=302)
|
104
|
resp = resp.follow(status=302)
|
105
|
resp.location.startswith('http://example.net/cat/test/?mt=')
|
106
|
resp = resp.follow(status=200)
|
107
|
|
108
|
# disable formdef: formdatas are still visible and accessible, drafts are not
|
109
|
formdef.disabled = True
|
110
|
formdef.store()
|
111
|
resp = app.get('/myspace/')
|
112
|
assert 'Status1' in resp
|
113
|
assert '<a href="/cat/test/%s/"' % formdata.id in resp
|
114
|
assert not 'Draft' in resp
|
115
|
assert not '<a href="/cat/test/%s"' % draft.id in resp
|
116
|
resp = app.get('/cat/test/%s' % formdata.id)
|
117
|
resp.status_int = 200
|
118
|
resp = app.get('/cat/test/%s' % draft.id, status=302)
|
119
|
resp = resp.follow(status=302)
|
120
|
resp.location.startswith('http://example.net/cat/test/?mt=')
|
121
|
resp = resp.follow(status=403)
|
122
|
|
123
|
def test_announces():
|
124
|
from modules.announces import Announce, AnnounceSubscription
|
125
|
|
126
|
if not 'misc' in pub.cfg:
|
127
|
pub.cfg['misc'] = {}
|
128
|
pub.cfg['misc']['announce_themes'] = ['Foo', 'Bar']
|
129
|
pub.write_cfg()
|
130
|
|
131
|
announce = Announce()
|
132
|
announce.title = 'Hello World'
|
133
|
announce.text = 'Lorem ipsum...'
|
134
|
announce.publication_time = time.gmtime(time.time()-100000)
|
135
|
announce.store()
|
136
|
|
137
|
user = create_user()
|
138
|
app = login(get_app(pub), username='user', password='user')
|
139
|
resp = app.get('/announces/', status=200)
|
140
|
resp = resp.click('Receiving those Announces')
|
141
|
resp = resp.click('Email')
|
142
|
assert 'You are logged in but there is no email address in your profile.' in resp.body
|
143
|
assert 'email' in resp.form.fields
|
144
|
user.email = 'foo@localhost'
|
145
|
user.store()
|
146
|
resp = app.get('/announces/email', status=200)
|
147
|
assert 'foo@localhost' in resp.body
|
148
|
assert not 'email' in resp.form.fields
|
149
|
resp = resp.form.submit()
|
150
|
assert AnnounceSubscription.count() == 1
|
151
|
|
152
|
resp = app.get('/myspace/', status=200)
|
153
|
resp = resp.click('Edit my Subscription to Announces')
|
154
|
assert resp.form['themes$elementFoo'].checked
|
155
|
assert resp.form['themes$elementBar'].checked
|
156
|
resp.form['themes$elementFoo'].checked = False
|
157
|
resp = resp.form.submit('submit')
|
158
|
assert AnnounceSubscription.count() == 1
|
159
|
|
160
|
resp = app.get('/myspace/announces', status=200)
|
161
|
assert not resp.form['themes$elementFoo'].checked
|
162
|
assert resp.form['themes$elementBar'].checked
|
163
|
|
164
|
def test_agenda():
|
165
|
from modules.events import Event, RemoteCalendar
|
166
|
|
167
|
remote_calendar = RemoteCalendar()
|
168
|
remote_calendar.label = 'Remote'
|
169
|
remote_calendar.store()
|
170
|
|
171
|
event = Event()
|
172
|
event.title = 'Hello World'
|
173
|
event.description = 'Lorem ipsum...'
|
174
|
event.date_start = time.strptime('2016-09-10', '%Y-%m-%d')
|
175
|
event.date_end = time.strptime('2016-09-12', '%Y-%m-%d')
|
176
|
event.store()
|
177
|
|
178
|
app = get_app(pub)
|
179
|
resp = app.get('/agenda/', status=200)
|
180
|
resp = app.get('/agenda/filter')
|
181
|
assert 'tags$element0' in resp.form.fields
|
182
|
assert 'calendars$element0' in resp.form.fields
|