|
1 | 1 | from flask import Flask, url_for
|
2 | 2 | from .view_classes import DecoratedView
|
| 3 | +from .view_classes import DecoratedBoldListView |
| 4 | +from .view_classes import DecoratedBoldItalicsListView |
| 5 | +from .view_classes import DecoratedListMemberView |
| 6 | +from .view_classes import DecoratedListFunctionAttributesView |
| 7 | +from .view_classes import DecoratedListMemberFunctionAttributesView |
3 | 8 | from nose.tools import *
|
4 | 9 |
|
5 | 10 | app = Flask("decorated")
|
6 | 11 | DecoratedView.register(app)
|
| 12 | +DecoratedBoldListView.register(app) |
| 13 | +DecoratedBoldItalicsListView.register(app) |
| 14 | +DecoratedListMemberView.register(app) |
| 15 | +DecoratedListFunctionAttributesView.register(app) |
| 16 | +DecoratedListMemberFunctionAttributesView.register(app) |
7 | 17 | client = app.test_client()
|
8 | 18 |
|
9 | 19 |
|
@@ -51,9 +61,80 @@ def test_params_decorator():
|
51 | 61 | resp = client.get('/decorated/params_decorator_method/')
|
52 | 62 | eq_(b"Params Decorator", resp.data)
|
53 | 63 |
|
| 64 | + |
54 | 65 | def test_params_decorator_delete():
|
55 | 66 | resp = client.delete('/decorated/1234')
|
56 | 67 | eq_(b"Params Decorator Delete 1234", resp.data)
|
57 | 68 |
|
58 | 69 |
|
| 70 | +def test_decorator_bold_list_get(): |
| 71 | + resp = client.get('/decorated_bold_list_view/1234') |
| 72 | + ok_(b'<b>' in resp.data) |
| 73 | + ok_(b'</b>' in resp.data) |
| 74 | + |
| 75 | + |
| 76 | +def test_decorator_bold_list_index(): |
| 77 | + resp = client.get('/decorated_bold_list_view/') |
| 78 | + ok_(b'<b>' in resp.data) |
| 79 | + ok_(b'</b>' in resp.data) |
| 80 | + |
| 81 | + |
| 82 | +def test_decorator_bold_italics_list_get(): |
| 83 | + resp = client.get('/decorated_bold_italics_list_view/1234') |
| 84 | + ok_(b'<i>' in resp.data) |
| 85 | + ok_(b'</i>' in resp.data) |
| 86 | + ok_(b'<b>' in resp.data) |
| 87 | + ok_(b'</b>' in resp.data) |
| 88 | + |
| 89 | + |
| 90 | +def test_decorator_bold_italics_list_index(): |
| 91 | + resp = client.get('/decorated_bold_italics_list_view/') |
| 92 | + ok_(b'<i>' in resp.data) |
| 93 | + ok_(b'</i>' in resp.data) |
| 94 | + ok_(b'<b>' in resp.data) |
| 95 | + ok_(b'</b>' in resp.data) |
| 96 | + |
| 97 | + |
| 98 | +def test_decorator_list_member_index(): |
| 99 | + resp = client.get('/decorated_list_member_view/') |
| 100 | + ok_(b'<i>' in resp.data) |
| 101 | + ok_(b'</i>' in resp.data) |
| 102 | + ok_(b'<b>' in resp.data) |
| 103 | + ok_(b'</b>' in resp.data) |
| 104 | + ok_(b'<p>' not in resp.data) |
| 105 | + ok_(b'</p>' not in resp.data) |
| 106 | + |
| 107 | + |
| 108 | +def test_decorator_list_member_get(): |
| 109 | + resp = client.get('/decorated_list_member_view/1234') |
| 110 | + |
| 111 | + # The order should match how functions are decorated |
| 112 | + eq_(b'<b>', resp.data[:3]) |
| 113 | + eq_(b'<i>', resp.data[3:6]) |
| 114 | + eq_(b'<p>', resp.data[6:9]) |
| 115 | + eq_(b'</p>', resp.data[-12:-8]) |
| 116 | + eq_(b'</i>', resp.data[-8:-4]) |
| 117 | + eq_(b'</b>', resp.data[-4:]) |
| 118 | + |
| 119 | + |
| 120 | +# Verify list of decorators with attributes modify all functions in FlaskView |
| 121 | +def test_decorator_list_function_attributes_get(): |
| 122 | + ok_(hasattr(app.view_functions['DecoratedListFunctionAttributesView:get'], '_eggs')) |
| 123 | + eq_('scrambled', app.view_functions['DecoratedListFunctionAttributesView:get']._eggs) |
| 124 | + |
| 125 | + |
| 126 | +# Verify list of decorators with attributes modify all functions in FlaskView |
| 127 | +def test_decorator_list_function_attributes_index(): |
| 128 | + ok_(hasattr(app.view_functions['DecoratedListFunctionAttributesView:index'], '_eggs')) |
| 129 | + eq_('scrambled', app.view_functions['DecoratedListFunctionAttributesView:index']._eggs) |
| 130 | + |
| 131 | + |
| 132 | +# Verify decorator with attributes does not modify other members |
| 133 | +def test_decorator_list_member_function_attributes_get(): |
| 134 | + eq_(hasattr(app.view_functions['DecoratedListMemberFunctionAttributesView:get'], '_eggs'), False) |
| 135 | + |
59 | 136 |
|
| 137 | +# Verify decorator with attributes modify decorated memeber functions |
| 138 | +def test_decorator_list_member_function_attributes_index(): |
| 139 | + eq_(hasattr(app.view_functions['DecoratedListMemberFunctionAttributesView:index'], '_eggs'), True) |
| 140 | + eq_('scrambled', app.view_functions['DecoratedListMemberFunctionAttributesView:index']._eggs) |
0 commit comments