3751 |
3751 |
def test_categories(pub):
|
3752 |
3752 |
create_superuser(pub)
|
3753 |
3753 |
app = login(get_app(pub))
|
3754 |
|
app.get('/backoffice/categories/')
|
|
3754 |
resp = app.get('/backoffice/forms/categories/')
|
|
3755 |
|
|
3756 |
def test_categories_legacy_urls(pub):
|
|
3757 |
create_superuser(pub)
|
|
3758 |
app = login(get_app(pub))
|
|
3759 |
resp = app.get('/backoffice/categories/')
|
|
3760 |
assert resp.location.endswith('/backoffice/forms/categories/')
|
|
3761 |
resp = app.get('/backoffice/categories/1')
|
|
3762 |
assert resp.location.endswith('/backoffice/forms/categories/1')
|
|
3763 |
resp = app.get('/backoffice/categories/1/')
|
|
3764 |
assert resp.location.endswith('/backoffice/forms/categories/1/')
|
3755 |
3765 |
|
3756 |
3766 |
def test_categories_new(pub):
|
3757 |
3767 |
create_superuser(pub)
|
... | ... | |
3759 |
3769 |
app = login(get_app(pub))
|
3760 |
3770 |
|
3761 |
3771 |
# go to the page and cancel
|
3762 |
|
resp = app.get('/backoffice/categories/')
|
|
3772 |
resp = app.get('/backoffice/forms/categories/')
|
3763 |
3773 |
resp = resp.click('New Category')
|
3764 |
3774 |
resp = resp.forms[0].submit('cancel')
|
3765 |
|
assert resp.location == 'http://example.net/backoffice/categories/'
|
|
3775 |
assert resp.location == 'http://example.net/backoffice/forms/categories/'
|
3766 |
3776 |
|
3767 |
3777 |
# go to the page and add a category
|
3768 |
|
resp = app.get('/backoffice/categories/')
|
|
3778 |
resp = app.get('/backoffice/forms/categories/')
|
3769 |
3779 |
resp = resp.click('New Category')
|
3770 |
3780 |
resp.forms[0]['name'] = 'a new category'
|
3771 |
3781 |
resp.forms[0]['description'] = 'description of the category'
|
3772 |
3782 |
resp = resp.forms[0].submit('submit')
|
3773 |
|
assert resp.location == 'http://example.net/backoffice/categories/'
|
|
3783 |
assert resp.location == 'http://example.net/backoffice/forms/categories/'
|
3774 |
3784 |
resp = resp.follow()
|
3775 |
3785 |
assert 'a new category' in resp.body
|
3776 |
3786 |
resp = resp.click('a new category')
|
... | ... | |
3786 |
3796 |
category.store()
|
3787 |
3797 |
|
3788 |
3798 |
app = login(get_app(pub))
|
3789 |
|
resp = app.get('/backoffice/categories/1/')
|
|
3799 |
resp = app.get('/backoffice/forms/categories/1/')
|
3790 |
3800 |
assert 'no form associated to this category' in resp.body
|
3791 |
3801 |
|
3792 |
3802 |
resp = resp.click(href='edit')
|
3793 |
3803 |
assert resp.forms[0]['name'].value == 'foobar'
|
3794 |
3804 |
resp.forms[0]['description'] = 'category description'
|
3795 |
3805 |
resp = resp.forms[0].submit('submit')
|
3796 |
|
assert resp.location == 'http://example.net/backoffice/categories/'
|
|
3806 |
assert resp.location == 'http://example.net/backoffice/forms/categories/'
|
3797 |
3807 |
resp = resp.follow()
|
3798 |
3808 |
resp = resp.click('foobar')
|
3799 |
3809 |
assert '<h2>foobar' in resp.body
|
... | ... | |
3808 |
3818 |
category.store()
|
3809 |
3819 |
|
3810 |
3820 |
app = login(get_app(pub))
|
3811 |
|
resp = app.get('/backoffice/categories/1/')
|
|
3821 |
resp = app.get('/backoffice/forms/categories/1/')
|
3812 |
3822 |
|
3813 |
3823 |
resp = resp.click(href='edit')
|
3814 |
3824 |
assert resp.forms[0]['name'].value == 'foobar'
|
... | ... | |
3817 |
3827 |
assert 'This name is already used' in resp.body
|
3818 |
3828 |
|
3819 |
3829 |
resp = resp.forms[0].submit('cancel')
|
3820 |
|
assert resp.location == 'http://example.net/backoffice/categories/'
|
|
3830 |
assert resp.location == 'http://example.net/backoffice/forms/categories/'
|
3821 |
3831 |
|
3822 |
3832 |
def test_categories_with_formdefs(pub):
|
3823 |
3833 |
Category.wipe()
|
... | ... | |
3826 |
3836 |
|
3827 |
3837 |
FormDef.wipe()
|
3828 |
3838 |
app = login(get_app(pub))
|
3829 |
|
resp = app.get('/backoffice/categories/1/')
|
|
3839 |
resp = app.get('/backoffice/forms/categories/1/')
|
3830 |
3840 |
assert 'form bar' not in resp.body
|
3831 |
3841 |
|
3832 |
3842 |
formdef = FormDef()
|
... | ... | |
3835 |
3845 |
formdef.category_id = category.id
|
3836 |
3846 |
formdef.store()
|
3837 |
3847 |
|
3838 |
|
resp = app.get('/backoffice/categories/1/')
|
|
3848 |
resp = app.get('/backoffice/forms/categories/1/')
|
3839 |
3849 |
assert 'form bar' in resp.body
|
3840 |
3850 |
assert 'no form associated to this category' not in resp.body
|
3841 |
3851 |
|
... | ... | |
3846 |
3856 |
|
3847 |
3857 |
FormDef.wipe()
|
3848 |
3858 |
app = login(get_app(pub))
|
3849 |
|
resp = app.get('/backoffice/categories/1/')
|
|
3859 |
resp = app.get('/backoffice/forms/categories/1/')
|
3850 |
3860 |
|
3851 |
3861 |
resp = resp.click(href='delete')
|
3852 |
3862 |
resp = resp.forms[0].submit('cancel')
|
3853 |
|
assert resp.location == 'http://example.net/backoffice/categories/1/'
|
|
3863 |
assert resp.location == 'http://example.net/backoffice/forms/categories/1/'
|
3854 |
3864 |
assert Category.count() == 1
|
3855 |
3865 |
|
3856 |
|
resp = app.get('/backoffice/categories/1/')
|
|
3866 |
resp = app.get('/backoffice/forms/categories/1/')
|
3857 |
3867 |
resp = resp.click(href='delete')
|
3858 |
3868 |
resp = resp.forms[0].submit()
|
3859 |
|
assert resp.location == 'http://example.net/backoffice/categories/'
|
|
3869 |
assert resp.location == 'http://example.net/backoffice/forms/categories/'
|
3860 |
3870 |
resp = resp.follow()
|
3861 |
3871 |
assert Category.count() == 0
|
3862 |
3872 |
|
... | ... | |
3870 |
3880 |
app = login(get_app(pub))
|
3871 |
3881 |
# this URL is used for editing from the frontoffice, there's no link
|
3872 |
3882 |
# pointing to it in the admin.
|
3873 |
|
resp = app.get('/backoffice/categories/1/description')
|
|
3883 |
resp = app.get('/backoffice/forms/categories/1/description')
|
3874 |
3884 |
assert resp.forms[0]['description'].value == 'category description'
|
3875 |
3885 |
resp.forms[0]['description'] = 'updated description'
|
3876 |
3886 |
|
3877 |
3887 |
# check cancel doesn't save the change
|
3878 |
3888 |
resp2 = resp.forms[0].submit('cancel')
|
3879 |
|
assert resp2.location == 'http://example.net/backoffice/categories/1/'
|
|
3889 |
assert resp2.location == 'http://example.net/backoffice/forms/categories/1/'
|
3880 |
3890 |
assert Category.get(1).description == 'category description'
|
3881 |
3891 |
|
3882 |
3892 |
# check submit does it properly
|
3883 |
3893 |
resp2 = resp.forms[0].submit('submit')
|
3884 |
|
assert resp2.location == 'http://example.net/backoffice/categories/1/'
|
|
3894 |
assert resp2.location == 'http://example.net/backoffice/forms/categories/1/'
|
3885 |
3895 |
resp2 = resp2.follow()
|
3886 |
3896 |
assert Category.get(1).description == 'updated description'
|
3887 |
3897 |
|
... | ... | |
3891 |
3901 |
category.store()
|
3892 |
3902 |
|
3893 |
3903 |
app = login(get_app(pub))
|
3894 |
|
resp = app.get('/backoffice/categories/')
|
|
3904 |
resp = app.get('/backoffice/forms/categories/')
|
3895 |
3905 |
resp = resp.click('New Category')
|
3896 |
3906 |
resp.forms[0]['name'] = 'foobar'
|
3897 |
3907 |
resp = resp.forms[0].submit('submit')
|
... | ... | |
3907 |
3917 |
category.store()
|
3908 |
3918 |
|
3909 |
3919 |
app = login(get_app(pub))
|
3910 |
|
resp = app.get('/backoffice/categories/update_order?order=1;2;3;')
|
|
3920 |
resp = app.get('/backoffice/forms/categories/update_order?order=1;2;3;')
|
3911 |
3921 |
categories = Category.select()
|
3912 |
3922 |
Category.sort_by_position(categories)
|
3913 |
3923 |
assert [x.id for x in categories] == ['1', '2', '3']
|
3914 |
3924 |
|
3915 |
|
resp = app.get('/backoffice/categories/update_order?order=3;1;2;')
|
|
3925 |
resp = app.get('/backoffice/forms/categories/update_order?order=3;1;2;')
|
3916 |
3926 |
categories = Category.select()
|
3917 |
3927 |
Category.sort_by_position(categories)
|
3918 |
3928 |
assert [x.id for x in categories] == ['3', '1', '2']
|