-
Notifications
You must be signed in to change notification settings - Fork 23
/
test_views.py
82 lines (70 loc) · 3.82 KB
/
test_views.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
from fulfillment_api.constants import api_settings, permissions
from testing.decorators import login_as, permission_required_test
from testing.shotput_tests import BaseShotputTestCaseWithData
from testing.test_data import require_data
class GetBestFitTest(BaseShotputTestCaseWithData):
@require_data(users='rect')
@login_as('rect')
@permission_required_test('rect', 'rectangles', 'shotput',
permissions.box_packing_read,
setup=False, success_status=400,
test_api_keys='api_key',
api_type=api_settings.BOX_PACKING)
def test_get_best_fit_forbidden(self, token, api_key):
token = token if api_key is None else None
api_key = '' if api_key is None else '?key={}'.format(api_key.get_key())
return self.post_json('/box_packing_api/basic{}'.format(api_key), token)
class GetSpaceAfterPackingTest(BaseShotputTestCaseWithData):
@require_data(users='rect')
@login_as('rect')
@permission_required_test('rect', 'rectangles', 'shotput',
permissions.box_packing_read,
setup=False, success_status=400,
test_api_keys='api_key',
api_type=api_settings.BOX_PACKING)
def test_get_space_after_packing_forbidden(self, token, api_key):
token = token if api_key is None else None
api_key = '' if api_key is None else '?key={}'.format(api_key.get_key())
return self.post_json('/box_packing_api/remaining_volume{}'
.format(api_key), token)
class HowManyFitTest(BaseShotputTestCaseWithData):
@require_data(users='rect')
@login_as('rect')
@permission_required_test('rect', 'rectangles', 'shotput',
permissions.box_packing_read,
setup=False, success_status=400,
test_api_keys='api_key',
api_type=api_settings.BOX_PACKING)
def test_how_many_fit_forbidden(self, token, api_key):
token = token if api_key is None else None
api_key = '' if api_key is None else '?key={}'.format(api_key.get_key())
return self.post_json(
'/box_packing_api/capacity{}'.format(api_key), token)
class BoxPackingApiTest(BaseShotputTestCaseWithData):
@require_data(users='rect')
@login_as('rect')
@permission_required_test('rect', 'rectangles', 'shotput',
permissions.box_packing_read,
setup=False, success_status=400,
test_api_keys='api_key',
api_type=api_settings.BOX_PACKING)
def test_box_packing_api_forbidden(self, token, api_key):
token = token if api_key is None else None
api_key = '' if api_key is None else '?key={}'.format(api_key.get_key())
return self.post_json('/box_packing_api/full{}'.format(api_key), token)
class ComparePackTest(BaseShotputTestCaseWithData):
def setUp(self):
super(ComparePackTest, self).setUp()
self.data.users['admin'].groups = []
self.session.commit()
@require_data(users='admin')
@login_as('admin')
@permission_required_test('admin', 'shotput', 'shotput',
permissions.global_god_mode,
setup=False, test_api_keys='api_key',
api_type=api_settings.BOX_PACKING)
def test_compare_pack_forbidden(self, token, api_key):
token = token if api_key is None else None
api_key = '' if api_key is None else '?key={}'.format(api_key.get_key())
return self.get_json('/box_packing_api/compare_packing_efficiency{}'
.format(api_key), token, args={'trials': 1})