0001-misc-split-admin-pages-tests-category.patch
tests/admin_pages/test_all.py | ||
---|---|---|
601 | 601 |
assert Role.count() == 0 |
602 | 602 | |
603 | 603 | |
604 |
def test_categories(pub): |
|
605 |
create_superuser(pub) |
|
606 |
app = login(get_app(pub)) |
|
607 |
resp = app.get('/backoffice/forms/categories/') |
|
608 | ||
609 | ||
610 |
def test_categories_legacy_urls(pub): |
|
611 |
create_superuser(pub) |
|
612 |
app = login(get_app(pub)) |
|
613 |
resp = app.get('/backoffice/categories/') |
|
614 |
assert resp.location.endswith('/backoffice/forms/categories/') |
|
615 |
resp = app.get('/backoffice/categories/1') |
|
616 |
assert resp.location.endswith('/backoffice/forms/categories/1') |
|
617 |
resp = app.get('/backoffice/categories/1/') |
|
618 |
assert resp.location.endswith('/backoffice/forms/categories/1/') |
|
619 | ||
620 | ||
621 |
def test_categories_new(pub): |
|
622 |
create_superuser(pub) |
|
623 |
Category.wipe() |
|
624 |
app = login(get_app(pub)) |
|
625 | ||
626 |
# go to the page and cancel |
|
627 |
resp = app.get('/backoffice/forms/categories/') |
|
628 |
resp = resp.click('New Category') |
|
629 |
resp = resp.forms[0].submit('cancel') |
|
630 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
631 | ||
632 |
# go to the page and add a category |
|
633 |
resp = app.get('/backoffice/forms/categories/') |
|
634 |
resp = resp.click('New Category') |
|
635 |
resp.forms[0]['name'] = 'a new category' |
|
636 |
resp.forms[0]['description'] = 'description of the category' |
|
637 |
resp = resp.forms[0].submit('submit') |
|
638 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
639 |
resp = resp.follow() |
|
640 |
assert 'a new category' in resp.text |
|
641 |
resp = resp.click('a new category') |
|
642 |
assert '<h2>a new category' in resp.text |
|
643 | ||
644 |
assert Category.get(1).name == 'a new category' |
|
645 |
assert Category.get(1).description == 'description of the category' |
|
646 | ||
647 | ||
648 |
def test_categories_edit(pub): |
|
649 |
create_superuser(pub) |
|
650 |
Category.wipe() |
|
651 |
category = Category(name='foobar') |
|
652 |
category.store() |
|
653 | ||
654 |
app = login(get_app(pub)) |
|
655 |
resp = app.get('/backoffice/forms/categories/1/') |
|
656 |
assert 'no form associated to this category' in resp.text |
|
657 | ||
658 |
resp = resp.click(href='edit') |
|
659 |
assert resp.forms[0]['name'].value == 'foobar' |
|
660 |
resp.forms[0]['description'] = 'category description' |
|
661 |
resp = resp.forms[0].submit('submit') |
|
662 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
663 |
resp = resp.follow() |
|
664 |
resp = resp.click('foobar') |
|
665 |
assert '<h2>foobar' in resp.text |
|
666 | ||
667 |
assert Category.get(1).description == 'category description' |
|
668 | ||
669 | ||
670 |
def test_categories_edit_duplicate_name(pub): |
|
671 |
Category.wipe() |
|
672 |
category = Category(name='foobar') |
|
673 |
category.store() |
|
674 |
category = Category(name='foobar2') |
|
675 |
category.store() |
|
676 | ||
677 |
app = login(get_app(pub)) |
|
678 |
resp = app.get('/backoffice/forms/categories/1/') |
|
679 | ||
680 |
resp = resp.click(href='edit') |
|
681 |
assert resp.forms[0]['name'].value == 'foobar' |
|
682 |
resp.forms[0]['name'] = 'foobar2' |
|
683 |
resp = resp.forms[0].submit('submit') |
|
684 |
assert 'This name is already used' in resp.text |
|
685 | ||
686 |
resp = resp.forms[0].submit('cancel') |
|
687 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
688 | ||
689 | ||
690 |
def test_categories_with_formdefs(pub): |
|
691 |
Category.wipe() |
|
692 |
category = Category(name='foobar') |
|
693 |
category.store() |
|
694 | ||
695 |
FormDef.wipe() |
|
696 |
app = login(get_app(pub)) |
|
697 |
resp = app.get('/backoffice/forms/categories/1/') |
|
698 |
assert 'form bar' not in resp.text |
|
699 | ||
700 |
formdef = FormDef() |
|
701 |
formdef.name = 'form bar' |
|
702 |
formdef.fields = [] |
|
703 |
formdef.category_id = category.id |
|
704 |
formdef.store() |
|
705 | ||
706 |
resp = app.get('/backoffice/forms/categories/1/') |
|
707 |
assert 'form bar' in resp.text |
|
708 |
assert 'no form associated to this category' not in resp.text |
|
709 | ||
710 | ||
711 |
def test_categories_delete(pub): |
|
712 |
Category.wipe() |
|
713 |
category = Category(name='foobar') |
|
714 |
category.store() |
|
715 | ||
716 |
FormDef.wipe() |
|
717 |
app = login(get_app(pub)) |
|
718 |
resp = app.get('/backoffice/forms/categories/1/') |
|
719 | ||
720 |
resp = resp.click(href='delete') |
|
721 |
resp = resp.forms[0].submit('cancel') |
|
722 |
assert resp.location == 'http://example.net/backoffice/forms/categories/1/' |
|
723 |
assert Category.count() == 1 |
|
724 | ||
725 |
resp = app.get('/backoffice/forms/categories/1/') |
|
726 |
resp = resp.click(href='delete') |
|
727 |
resp = resp.forms[0].submit() |
|
728 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
729 |
resp = resp.follow() |
|
730 |
assert Category.count() == 0 |
|
731 | ||
732 | ||
733 |
def test_categories_edit_description(pub): |
|
734 |
Category.wipe() |
|
735 |
category = Category(name='foobar') |
|
736 |
category.description = 'category description' |
|
737 |
category.store() |
|
738 | ||
739 |
app = login(get_app(pub)) |
|
740 |
# this URL is used for editing from the frontoffice, there's no link |
|
741 |
# pointing to it in the admin. |
|
742 |
resp = app.get('/backoffice/forms/categories/1/description') |
|
743 |
assert resp.forms[0]['description'].value == 'category description' |
|
744 |
resp.forms[0]['description'] = 'updated description' |
|
745 | ||
746 |
# check cancel doesn't save the change |
|
747 |
resp2 = resp.forms[0].submit('cancel') |
|
748 |
assert resp2.location == 'http://example.net/backoffice/forms/categories/1/' |
|
749 |
assert Category.get(1).description == 'category description' |
|
750 | ||
751 |
# check submit does it properly |
|
752 |
resp2 = resp.forms[0].submit('submit') |
|
753 |
assert resp2.location == 'http://example.net/backoffice/forms/categories/1/' |
|
754 |
resp2 = resp2.follow() |
|
755 |
assert Category.get(1).description == 'updated description' |
|
756 | ||
757 | ||
758 |
def test_categories_new_duplicate_name(pub): |
|
759 |
Category.wipe() |
|
760 |
category = Category(name='foobar') |
|
761 |
category.store() |
|
762 | ||
763 |
app = login(get_app(pub)) |
|
764 |
resp = app.get('/backoffice/forms/categories/') |
|
765 |
resp = resp.click('New Category') |
|
766 |
resp.forms[0]['name'] = 'foobar' |
|
767 |
resp = resp.forms[0].submit('submit') |
|
768 |
assert 'This name is already used' in resp.text |
|
769 | ||
770 | ||
771 |
def test_categories_reorder(pub): |
|
772 |
Category.wipe() |
|
773 |
category = Category(name='foo') |
|
774 |
category.store() |
|
775 |
category = Category(name='bar') |
|
776 |
category.store() |
|
777 |
category = Category(name='baz') |
|
778 |
category.store() |
|
779 | ||
780 |
app = login(get_app(pub)) |
|
781 |
resp = app.get('/backoffice/forms/categories/update_order?order=1;2;3;') |
|
782 |
categories = Category.select() |
|
783 |
Category.sort_by_position(categories) |
|
784 |
assert [x.id for x in categories] == ['1', '2', '3'] |
|
785 | ||
786 |
resp = app.get('/backoffice/forms/categories/update_order?order=3;1;2;') |
|
787 |
categories = Category.select() |
|
788 |
Category.sort_by_position(categories) |
|
789 |
assert [x.id for x in categories] == ['3', '1', '2'] |
|
790 | ||
791 | ||
792 | 604 |
def test_settings(pub): |
793 | 605 |
create_superuser(pub) |
794 | 606 |
app = login(get_app(pub)) |
tests/admin_pages/test_category.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 | ||
3 |
import pytest |
|
4 | ||
5 |
from wcs.qommon.http_request import HTTPRequest |
|
6 |
from wcs.categories import Category |
|
7 |
from wcs.formdef import FormDef |
|
8 | ||
9 |
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub |
|
10 |
from .test_all import create_superuser |
|
11 | ||
12 | ||
13 |
def pytest_generate_tests(metafunc): |
|
14 |
if 'pub' in metafunc.fixturenames: |
|
15 |
metafunc.parametrize('pub', ['pickle', 'sql', 'pickle-templates'], indirect=True) |
|
16 | ||
17 | ||
18 |
@pytest.fixture |
|
19 |
def pub(request): |
|
20 |
pub = create_temporary_pub( |
|
21 |
sql_mode=bool('sql' in request.param), |
|
22 |
templates_mode=bool('templates' in request.param) |
|
23 |
) |
|
24 | ||
25 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
|
26 |
pub.set_app_dir(req) |
|
27 |
pub.cfg['identification'] = {'methods': ['password']} |
|
28 |
pub.cfg['language'] = {'language': 'en'} |
|
29 |
pub.write_cfg() |
|
30 | ||
31 |
return pub |
|
32 | ||
33 | ||
34 |
def teardown_module(module): |
|
35 |
clean_temporary_pub() |
|
36 | ||
37 | ||
38 |
def test_categories(pub): |
|
39 |
create_superuser(pub) |
|
40 |
app = login(get_app(pub)) |
|
41 |
app.get('/backoffice/forms/categories/') |
|
42 | ||
43 | ||
44 |
def test_categories_legacy_urls(pub): |
|
45 |
create_superuser(pub) |
|
46 |
app = login(get_app(pub)) |
|
47 |
resp = app.get('/backoffice/categories/') |
|
48 |
assert resp.location.endswith('/backoffice/forms/categories/') |
|
49 |
resp = app.get('/backoffice/categories/1') |
|
50 |
assert resp.location.endswith('/backoffice/forms/categories/1') |
|
51 |
resp = app.get('/backoffice/categories/1/') |
|
52 |
assert resp.location.endswith('/backoffice/forms/categories/1/') |
|
53 | ||
54 | ||
55 |
def test_categories_new(pub): |
|
56 |
create_superuser(pub) |
|
57 |
Category.wipe() |
|
58 |
app = login(get_app(pub)) |
|
59 | ||
60 |
# go to the page and cancel |
|
61 |
resp = app.get('/backoffice/forms/categories/') |
|
62 |
resp = resp.click('New Category') |
|
63 |
resp = resp.forms[0].submit('cancel') |
|
64 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
65 | ||
66 |
# go to the page and add a category |
|
67 |
resp = app.get('/backoffice/forms/categories/') |
|
68 |
resp = resp.click('New Category') |
|
69 |
resp.forms[0]['name'] = 'a new category' |
|
70 |
resp.forms[0]['description'] = 'description of the category' |
|
71 |
resp = resp.forms[0].submit('submit') |
|
72 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
73 |
resp = resp.follow() |
|
74 |
assert 'a new category' in resp.text |
|
75 |
resp = resp.click('a new category') |
|
76 |
assert '<h2>a new category' in resp.text |
|
77 | ||
78 |
assert Category.get(1).name == 'a new category' |
|
79 |
assert Category.get(1).description == 'description of the category' |
|
80 | ||
81 | ||
82 |
def test_categories_edit(pub): |
|
83 |
create_superuser(pub) |
|
84 |
Category.wipe() |
|
85 |
category = Category(name='foobar') |
|
86 |
category.store() |
|
87 | ||
88 |
app = login(get_app(pub)) |
|
89 |
resp = app.get('/backoffice/forms/categories/1/') |
|
90 |
assert 'no form associated to this category' in resp.text |
|
91 | ||
92 |
resp = resp.click(href='edit') |
|
93 |
assert resp.forms[0]['name'].value == 'foobar' |
|
94 |
resp.forms[0]['description'] = 'category description' |
|
95 |
resp = resp.forms[0].submit('submit') |
|
96 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
97 |
resp = resp.follow() |
|
98 |
resp = resp.click('foobar') |
|
99 |
assert '<h2>foobar' in resp.text |
|
100 | ||
101 |
assert Category.get(1).description == 'category description' |
|
102 | ||
103 | ||
104 |
def test_categories_edit_duplicate_name(pub): |
|
105 |
Category.wipe() |
|
106 |
category = Category(name='foobar') |
|
107 |
category.store() |
|
108 |
category = Category(name='foobar2') |
|
109 |
category.store() |
|
110 | ||
111 |
app = login(get_app(pub)) |
|
112 |
resp = app.get('/backoffice/forms/categories/1/') |
|
113 | ||
114 |
resp = resp.click(href='edit') |
|
115 |
assert resp.forms[0]['name'].value == 'foobar' |
|
116 |
resp.forms[0]['name'] = 'foobar2' |
|
117 |
resp = resp.forms[0].submit('submit') |
|
118 |
assert 'This name is already used' in resp.text |
|
119 | ||
120 |
resp = resp.forms[0].submit('cancel') |
|
121 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
122 | ||
123 | ||
124 |
def test_categories_with_formdefs(pub): |
|
125 |
Category.wipe() |
|
126 |
category = Category(name='foobar') |
|
127 |
category.store() |
|
128 | ||
129 |
FormDef.wipe() |
|
130 |
app = login(get_app(pub)) |
|
131 |
resp = app.get('/backoffice/forms/categories/1/') |
|
132 |
assert 'form bar' not in resp.text |
|
133 | ||
134 |
formdef = FormDef() |
|
135 |
formdef.name = 'form bar' |
|
136 |
formdef.fields = [] |
|
137 |
formdef.category_id = category.id |
|
138 |
formdef.store() |
|
139 | ||
140 |
resp = app.get('/backoffice/forms/categories/1/') |
|
141 |
assert 'form bar' in resp.text |
|
142 |
assert 'no form associated to this category' not in resp.text |
|
143 | ||
144 | ||
145 |
def test_categories_delete(pub): |
|
146 |
Category.wipe() |
|
147 |
category = Category(name='foobar') |
|
148 |
category.store() |
|
149 | ||
150 |
FormDef.wipe() |
|
151 |
app = login(get_app(pub)) |
|
152 |
resp = app.get('/backoffice/forms/categories/1/') |
|
153 | ||
154 |
resp = resp.click(href='delete') |
|
155 |
resp = resp.forms[0].submit('cancel') |
|
156 |
assert resp.location == 'http://example.net/backoffice/forms/categories/1/' |
|
157 |
assert Category.count() == 1 |
|
158 | ||
159 |
resp = app.get('/backoffice/forms/categories/1/') |
|
160 |
resp = resp.click(href='delete') |
|
161 |
resp = resp.forms[0].submit() |
|
162 |
assert resp.location == 'http://example.net/backoffice/forms/categories/' |
|
163 |
resp = resp.follow() |
|
164 |
assert Category.count() == 0 |
|
165 | ||
166 | ||
167 |
def test_categories_edit_description(pub): |
|
168 |
Category.wipe() |
|
169 |
category = Category(name='foobar') |
|
170 |
category.description = 'category description' |
|
171 |
category.store() |
|
172 | ||
173 |
app = login(get_app(pub)) |
|
174 |
# this URL is used for editing from the frontoffice, there's no link |
|
175 |
# pointing to it in the admin. |
|
176 |
resp = app.get('/backoffice/forms/categories/1/description') |
|
177 |
assert resp.forms[0]['description'].value == 'category description' |
|
178 |
resp.forms[0]['description'] = 'updated description' |
|
179 | ||
180 |
# check cancel doesn't save the change |
|
181 |
resp2 = resp.forms[0].submit('cancel') |
|
182 |
assert resp2.location == 'http://example.net/backoffice/forms/categories/1/' |
|
183 |
assert Category.get(1).description == 'category description' |
|
184 | ||
185 |
# check submit does it properly |
|
186 |
resp2 = resp.forms[0].submit('submit') |
|
187 |
assert resp2.location == 'http://example.net/backoffice/forms/categories/1/' |
|
188 |
resp2 = resp2.follow() |
|
189 |
assert Category.get(1).description == 'updated description' |
|
190 | ||
191 | ||
192 |
def test_categories_new_duplicate_name(pub): |
|
193 |
Category.wipe() |
|
194 |
category = Category(name='foobar') |
|
195 |
category.store() |
|
196 | ||
197 |
app = login(get_app(pub)) |
|
198 |
resp = app.get('/backoffice/forms/categories/') |
|
199 |
resp = resp.click('New Category') |
|
200 |
resp.forms[0]['name'] = 'foobar' |
|
201 |
resp = resp.forms[0].submit('submit') |
|
202 |
assert 'This name is already used' in resp.text |
|
203 | ||
204 | ||
205 |
def test_categories_reorder(pub): |
|
206 |
Category.wipe() |
|
207 |
category = Category(name='foo') |
|
208 |
category.store() |
|
209 |
category = Category(name='bar') |
|
210 |
category.store() |
|
211 |
category = Category(name='baz') |
|
212 |
category.store() |
|
213 | ||
214 |
app = login(get_app(pub)) |
|
215 |
app.get('/backoffice/forms/categories/update_order?order=1;2;3;') |
|
216 |
categories = Category.select() |
|
217 |
Category.sort_by_position(categories) |
|
218 |
assert [x.id for x in categories] == ['1', '2', '3'] |
|
219 | ||
220 |
app.get('/backoffice/forms/categories/update_order?order=3;1;2;') |
|
221 |
categories = Category.select() |
|
222 |
Category.sort_by_position(categories) |
|
223 |
assert [x.id for x in categories] == ['3', '1', '2'] |
|
0 |
- |