forked from benoitc/couchapp
-
Notifications
You must be signed in to change notification settings - Fork 102
/
test_generator.py
73 lines (51 loc) · 1.99 KB
/
test_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
from couchapp.errors import AppError
from couchapp.generator import find_template_dir, init_basic, save_id
from mock import patch
from nose.tools import raises
@patch('couchapp.generator.save_id')
@patch('couchapp.generator.setup_dirs')
@patch('couchapp.generator.setup_dir')
@patch('couchapp.generator.localdoc')
def test_init_basic(localdoc, setup_dir, setup_dirs, save_id):
init_basic('/mock/app')
assert setup_dir.called
assert setup_dirs.called
assert save_id.called
assert localdoc.document.called
@patch('couchapp.generator.open')
def test_save_id(open_):
save_id('/mock/app', 'someid')
open_.assert_called_with('/mock/app/_id', 'wb')
@patch('couchapp.generator.os.path.isdir', return_value=False)
def test_find_template_dir_not_found(isdir):
assert find_template_dir() is None
assert isdir.called
@patch('couchapp.generator.os.path.isdir', return_value=False)
def test_find_template_dir_not_found_raise(isdir):
@raises(AppError)
def f():
find_template_dir(raise_error=True)
f()
assert isdir.called
@patch('couchapp.generator.os.path.isdir', return_value=False)
def test_find_template_dir_template_type_error(isdir):
@raises(AppError)
def f():
find_template_dir(tmpl_type='mock_type')
f()
assert not isdir.called
@patch('couchapp.generator.user_path', return_value=['/mock/.couchapp'])
@patch('couchapp.generator.os.path.isdir', return_value=True)
def test_find_template_dir_user_dir_first(isdir, user_path):
ret = find_template_dir()
assert ret == '/mock/.couchapp/templates/', ret
assert user_path.called
assert isdir.called
@patch('couchapp.generator.user_path', return_value=['/mock/.couchapp'])
@patch('couchapp.generator.os.path.isdir', return_value=True)
def test_find_template_dir_user_dir_first_with_type(isdir, user_path):
ret = find_template_dir(tmpl_type='app')
assert ret == '/mock/.couchapp/templates/app', ret
assert user_path.called
assert isdir.called