-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
92 lines (77 loc) · 3.02 KB
/
tests.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
# * File Name : tests.py
#
# * Copyright (C) 2012 Gaston TJEBBES <[email protected]>
# * Company : Majerti ( http://www.majerti.fr )
#
# This software is distributed under GPLV3
# License: http://www.gnu.org/licenses/gpl-3.0.txt
#
# * Creation Date : 31-07-2013
# * Last Modified : 29-10-2013
#
# * Project :
#
import datetime
from utils import (
read_locale_date,
write_locale_date,
get_base_url,
get_action_path_and_method,
filter_expenses,
cmp_attribute,
)
def test_read_locale_date():
assert read_locale_date('25-07-2013') == datetime.date(2013, 07, 25)
def test_write_locale_date():
assert write_locale_date(datetime.date(2013, 07, 25)) == '25-07-2013'
def test_get_base_url():
assert get_base_url('http://test.com/testpath') == 'http://test.com/'
assert get_base_url('http://test.com/?testpath') == 'http://test.com/'
def test_get_action_path_and_method():
edict = {'id': 1}
for action, method, path in (
('add', 'POST', 'expenses'),
('update', 'PUT', 'expenses/1'),
('delete', 'DELETE', 'expenses/1'),):
edict['todo'] = action
assert get_action_path_and_method(edict) == (path, method)
def test_cmp_attribute():
assert cmp_attribute('test', {}, {})
assert cmp_attribute('test', {'test': 0}, {'test': 0})
assert cmp_attribute('test', {}, {'test': 0})
assert not cmp_attribute('test', {'test': 0}, {'test': 1})
assert not cmp_attribute('test', {'test': 0}, {})
assert not cmp_attribute('test', {'test': 'ham'}, {'test': 'spam'})
def test_filter_expenses():
expenses = [
{
'category': u'2', 'todo': 'add',
'description': 'repas rdv', 'type_id': u'5', 'tva': '2',
'ht': '10', 'local_id': 2435, 'date': '2013-10-29',
'type': u'Restauration'
},
{
'category': u'3', 'todo': 'add',
'description': 'repas rdv', 'type_id': u'6', 'tva': '2',
'ht': '10', 'local_id': 2435, 'date': '2013-10-29',
'type': u'Restauration'
},
{
'category': u'2', 'todo': 'add',
'description': 'repas rdv', 'type_id': u'6', 'tva': '2',
'ht': '10', 'local_id': 2435, 'date': '2013-10-29',
'type': u'Restauration'
},
]
assert list(filter_expenses({'category': '2'}, expenses, ('category', )))
assert list(filter_expenses({'category': '4'}, expenses, ('type_id', )))
assert list(filter_expenses({'ht': '10'}, expenses, ('category', )))
assert list(filter_expenses({'ht': '10', 'category': '3'},
expenses, ('category', 'type')))
assert len(list(filter_expenses({'ht': '10', 'category': '2'},
expenses, ('category', 'type')))) == 2
assert len(list(filter_expenses({'type_id': '6', 'category': '2'},
expenses, ('category', 'type_id')))) == 1
assert not list(filter_expenses(
{'category': '4'}, expenses, ('category', )))