Project

General

Profile

Download (2.35 KB) Statistics
| Branch: | Tag: | Revision:

root / tests / test_user_pages.py @ 721bd8e5

1
import os
2
import shutil
3
import time
4

    
5
import pytest
6

    
7
from quixote import cleanup, get_publisher
8
from wcs.qommon import errors, sessions
9
from wcs.qommon.ident.password_accounts import PasswordAccount
10
from wcs.qommon.http_request import HTTPRequest
11
from wcs.categories import Category
12
from wcs.workflows import Workflow
13
from wcs.formdef import FormDef
14
from wcs import fields
15

    
16
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
17

    
18

    
19
def setup_module(module):
20
    cleanup()
21

    
22
    global pub
23

    
24
    pub = create_temporary_pub()
25

    
26
    req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
27
    pub.set_app_dir(req)
28
    pub.cfg['identification'] = {'methods': ['password']}
29
    pub.write_cfg()
30

    
31

    
32
def teardown_module(module):
33
    clean_temporary_pub()
34

    
35

    
36
def create_user():
37
    if pub.user_class.get_users_with_name_identifier('user'):
38
        return pub.user_class.get_users_with_name_identifier('user')[0]
39
    user1 = pub.user_class(name='user')
40
    user1.name_identifiers = ['user']
41
    user1.is_admin = False
42
    user1.store()
43

    
44
    account1 = PasswordAccount(id='user')
45
    account1.set_password('user')
46
    account1.user_id = user1.id
47
    account1.store()
48

    
49
    pub.cfg['identification'] = {'methods': ['password']}
50
    pub.write_cfg()
51

    
52
    return user1
53

    
54

    
55
def create_formdef():
56
    FormDef.wipe()
57
    formdef = FormDef()
58
    formdef.name = 'test'
59
    formdef.fields = []
60
    formdef.store()
61
    return formdef
62

    
63

    
64
def teardown_module(module):
65
    shutil.rmtree(pub.APP_DIR)
66

    
67

    
68
def test_with_user():
69
    user = create_user()
70
    app = login(get_app(pub), username='user', password='user')
71
    resp = app.get('/', status=200)
72

    
73

    
74
def test_form_category_redirection():
75
    Category.wipe()
76
    cat = Category(name='baz')
77
    cat.store()
78

    
79
    FormDef.wipe()
80
    formdef = FormDef()
81
    formdef.name = 'foobar'
82
    formdef.category_id = cat.id
83
    formdef.fields = []
84
    formdef.store()
85

    
86
    # check we get a redirection to /category/formdef/
87
    resp = get_app(pub).get('/foobar/')
88
    assert resp.location.endswith('/baz/foobar/')
89

    
90
    # check missing trailing slashs are ok
91
    resp = get_app(pub).get('/foobar')
92
    assert resp.location.endswith('/foobar/')
93
    resp = resp.follow()
94
    assert resp.location.endswith('/baz/foobar/')
95

    
96
    # check direct category access without trailing slash
97
    resp = get_app(pub).get('/baz')
98
    assert resp.location.endswith('/baz/')
(4-4/5)