aa-bulletin-board 1.10.1__py3-none-any.whl → 1.11.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aa_bulletin_board/__init__.py +1 -1
- aa_bulletin_board/auth_hooks.py +15 -6
- aa_bulletin_board/forms.py +6 -4
- aa_bulletin_board/helpers.py +15 -6
- aa_bulletin_board/locale/de/LC_MESSAGES/django.mo +0 -0
- aa_bulletin_board/locale/de/LC_MESSAGES/django.po +25 -30
- aa_bulletin_board/locale/django.pot +21 -24
- aa_bulletin_board/locale/es/LC_MESSAGES/django.po +21 -24
- aa_bulletin_board/locale/fr_FR/LC_MESSAGES/django.po +21 -24
- aa_bulletin_board/locale/it_IT/LC_MESSAGES/django.po +21 -24
- aa_bulletin_board/locale/ja/LC_MESSAGES/django.po +21 -24
- aa_bulletin_board/locale/ko_KR/LC_MESSAGES/django.po +21 -24
- aa_bulletin_board/locale/ru/LC_MESSAGES/django.mo +0 -0
- aa_bulletin_board/locale/ru/LC_MESSAGES/django.po +28 -33
- aa_bulletin_board/locale/uk/LC_MESSAGES/django.po +21 -24
- aa_bulletin_board/locale/zh_Hans/LC_MESSAGES/django.po +21 -24
- aa_bulletin_board/managers.py +7 -2
- aa_bulletin_board/models.py +17 -3
- aa_bulletin_board/static/aa_bulletin_board/css/aa-bootstrap-fix.css +5 -5
- aa_bulletin_board/static/aa_bulletin_board/css/aa-bootstrap-fix.min.css +1 -1
- aa_bulletin_board/templates/aa_bulletin_board/base.html +1 -1
- aa_bulletin_board/templates/aa_bulletin_board/partials/footer/app-translation-footer.html +11 -0
- aa_bulletin_board/templatetags/aa_bulletin_board_versioned_static.py +2 -1
- aa_bulletin_board/tests/test_access.py +61 -37
- aa_bulletin_board/tests/test_auth_hooks.py +18 -9
- aa_bulletin_board/tests/test_bulletins.py +80 -47
- aa_bulletin_board/tests/test_templatetags.py +9 -6
- aa_bulletin_board/tests/test_user_interface.py +85 -43
- aa_bulletin_board/tests/utils.py +24 -3
- aa_bulletin_board/urls.py +7 -5
- aa_bulletin_board/views.py +86 -33
- {aa_bulletin_board-1.10.1.dist-info → aa_bulletin_board-1.11.0.dist-info}/METADATA +1 -1
- {aa_bulletin_board-1.10.1.dist-info → aa_bulletin_board-1.11.0.dist-info}/RECORD +35 -35
- aa_bulletin_board/templates/aa_bulletin_board/partials/app-translation-footer.html +0 -11
- {aa_bulletin_board-1.10.1.dist-info → aa_bulletin_board-1.11.0.dist-info}/WHEEL +0 -0
- {aa_bulletin_board-1.10.1.dist-info → aa_bulletin_board-1.11.0.dist-info}/licenses/LICENSE +0 -0
@@ -25,22 +25,26 @@ class TestGetSentinelUser(TestCase):
|
|
25
25
|
Tests for the sentinel user
|
26
26
|
"""
|
27
27
|
|
28
|
-
def test_should_create_user_when_it_does_not_exist(self):
|
28
|
+
def test_should_create_user_when_it_does_not_exist(self) -> None:
|
29
29
|
"""
|
30
30
|
Test should create a sentinel user when it doesn't exist
|
31
|
+
|
31
32
|
:return:
|
33
|
+
:rtype:
|
32
34
|
"""
|
33
35
|
|
34
36
|
# when
|
35
37
|
user = get_sentinel_user()
|
36
38
|
|
37
39
|
# then
|
38
|
-
self.assertEqual(user.username, "deleted")
|
40
|
+
self.assertEqual(first=user.username, second="deleted")
|
39
41
|
|
40
|
-
def test_should_return_user_when_it_does(self):
|
42
|
+
def test_should_return_user_when_it_does(self) -> None:
|
41
43
|
"""
|
42
44
|
Test should return sentinel user when it exists
|
45
|
+
|
43
46
|
:return:
|
47
|
+
:rtype:
|
44
48
|
"""
|
45
49
|
|
46
50
|
# given
|
@@ -50,7 +54,7 @@ class TestGetSentinelUser(TestCase):
|
|
50
54
|
user = get_sentinel_user()
|
51
55
|
|
52
56
|
# then
|
53
|
-
self.assertEqual(user.username, "deleted")
|
57
|
+
self.assertEqual(first=user.username, second="deleted")
|
54
58
|
|
55
59
|
|
56
60
|
class TestBulletins(TestCase):
|
@@ -62,32 +66,40 @@ class TestBulletins(TestCase):
|
|
62
66
|
def setUpClass(cls) -> None:
|
63
67
|
"""
|
64
68
|
Set up groups and users
|
69
|
+
|
70
|
+
:return:
|
71
|
+
:rtype:
|
65
72
|
"""
|
66
73
|
|
67
74
|
super().setUpClass()
|
68
75
|
cls.group = Group.objects.create(name="Superhero")
|
69
76
|
|
70
77
|
# User cannot access bulletins
|
71
|
-
cls.user_1001 = create_fake_user(
|
78
|
+
cls.user_1001 = create_fake_user(
|
79
|
+
character_id=1001, character_name="Peter Parker"
|
80
|
+
)
|
72
81
|
|
73
82
|
# User can access bulletins
|
74
83
|
cls.user_1002 = create_fake_user(
|
75
|
-
1002,
|
84
|
+
character_id=1002,
|
85
|
+
character_name="Bruce Wayne",
|
86
|
+
permissions=["aa_bulletin_board.basic_access"],
|
76
87
|
)
|
77
88
|
|
78
89
|
# User can manage bulletins
|
79
90
|
cls.user_1003 = create_fake_user(
|
80
|
-
1003,
|
81
|
-
"Clark Kent",
|
91
|
+
character_id=1003,
|
92
|
+
character_name="Clark Kent",
|
82
93
|
permissions=[
|
83
94
|
"aa_bulletin_board.basic_access",
|
84
95
|
"aa_bulletin_board.manage_bulletins",
|
85
96
|
],
|
86
97
|
)
|
87
98
|
|
88
|
-
def test_should_remove_bulletin(self):
|
99
|
+
def test_should_remove_bulletin(self) -> None:
|
89
100
|
"""
|
90
101
|
Test if a bulletin should be removed
|
102
|
+
|
91
103
|
:return:
|
92
104
|
:rtype:
|
93
105
|
"""
|
@@ -100,22 +112,29 @@ class TestBulletins(TestCase):
|
|
100
112
|
created_by=self.user_1001,
|
101
113
|
)
|
102
114
|
|
103
|
-
self.client.force_login(self.user_1003)
|
115
|
+
self.client.force_login(user=self.user_1003)
|
104
116
|
|
105
117
|
# when
|
106
118
|
response = self.client.get(
|
107
|
-
reverse(
|
119
|
+
path=reverse(
|
120
|
+
viewname="aa_bulletin_board:remove_bulletin", args=[bulletin.slug]
|
121
|
+
)
|
108
122
|
)
|
109
|
-
messages = list(get_messages(response.wsgi_request))
|
123
|
+
messages = list(get_messages(request=response.wsgi_request))
|
110
124
|
|
111
125
|
# then
|
112
|
-
self.assertRedirects(response, "/bulletin-board/")
|
113
|
-
self.assertEqual(len(messages), 1)
|
114
|
-
self.assertEqual(
|
126
|
+
self.assertRedirects(response=response, expected_url="/bulletin-board/")
|
127
|
+
self.assertEqual(first=len(messages), second=1)
|
128
|
+
self.assertEqual(
|
129
|
+
first=str(messages[0]), second=f'Bulletin "{bulletin_title}" deleted.'
|
130
|
+
)
|
115
131
|
|
116
|
-
def test_should_raise_does_not_exist_exception_when_delete_bulletin_not_found(
|
132
|
+
def test_should_raise_does_not_exist_exception_when_delete_bulletin_not_found(
|
133
|
+
self,
|
134
|
+
) -> None:
|
117
135
|
"""
|
118
136
|
Test if a bulletin that doesn't exist should be removed
|
137
|
+
|
119
138
|
:return:
|
120
139
|
:rtype:
|
121
140
|
"""
|
@@ -126,24 +145,29 @@ class TestBulletins(TestCase):
|
|
126
145
|
content=f"<p>{fake.sentence()}</p>",
|
127
146
|
created_by=self.user_1001,
|
128
147
|
)
|
129
|
-
self.client.force_login(self.user_1003)
|
148
|
+
self.client.force_login(user=self.user_1003)
|
130
149
|
|
131
150
|
# when
|
132
151
|
response = self.client.get(
|
133
|
-
reverse(
|
152
|
+
path=reverse(
|
153
|
+
viewname="aa_bulletin_board:remove_bulletin", args=["foobarsson"]
|
154
|
+
)
|
134
155
|
)
|
135
156
|
messages = list(get_messages(response.wsgi_request))
|
136
157
|
|
137
|
-
self.assertRaises(bulletin.DoesNotExist)
|
138
|
-
self.assertEqual(len(messages), 1)
|
158
|
+
self.assertRaises(expected_exception=bulletin.DoesNotExist)
|
159
|
+
self.assertEqual(first=len(messages), second=1)
|
139
160
|
self.assertEqual(
|
140
|
-
str(messages[0]),
|
141
|
-
"The bulletin you are trying to delete does not exist.",
|
161
|
+
first=str(messages[0]),
|
162
|
+
second="The bulletin you are trying to delete does not exist.",
|
142
163
|
)
|
143
164
|
|
144
|
-
def test_should_raise_does_not_exist_exception_when_edit_bulletin_not_found(
|
165
|
+
def test_should_raise_does_not_exist_exception_when_edit_bulletin_not_found(
|
166
|
+
self,
|
167
|
+
) -> None:
|
145
168
|
"""
|
146
169
|
Test if a bulletin that doesn't exist should be edited
|
170
|
+
|
147
171
|
:return:
|
148
172
|
:rtype:
|
149
173
|
"""
|
@@ -154,24 +178,27 @@ class TestBulletins(TestCase):
|
|
154
178
|
content=f"<p>{fake.sentence()}</p>",
|
155
179
|
created_by=self.user_1001,
|
156
180
|
)
|
157
|
-
self.client.force_login(self.user_1003)
|
181
|
+
self.client.force_login(user=self.user_1003)
|
158
182
|
|
159
183
|
# when
|
160
184
|
response = self.client.get(
|
161
|
-
reverse(
|
185
|
+
path=reverse(
|
186
|
+
viewname="aa_bulletin_board:edit_bulletin", args=["foobarsson"]
|
187
|
+
)
|
162
188
|
)
|
163
|
-
messages = list(get_messages(response.wsgi_request))
|
189
|
+
messages = list(get_messages(request=response.wsgi_request))
|
164
190
|
|
165
|
-
self.assertRaises(bulletin.DoesNotExist)
|
166
|
-
self.assertEqual(len(messages), 1)
|
191
|
+
self.assertRaises(expected_exception=bulletin.DoesNotExist)
|
192
|
+
self.assertEqual(first=len(messages), second=1)
|
167
193
|
self.assertEqual(
|
168
|
-
str(messages[0]),
|
169
|
-
"The bulletin you are trying to edit does not exist.",
|
194
|
+
first=str(messages[0]),
|
195
|
+
second="The bulletin you are trying to edit does not exist.",
|
170
196
|
)
|
171
197
|
|
172
|
-
def test_should_translate_russian_letters_in_slug(self):
|
198
|
+
def test_should_translate_russian_letters_in_slug(self) -> None:
|
173
199
|
"""
|
174
200
|
Test that russian letters in a slug are translated
|
201
|
+
|
175
202
|
:return:
|
176
203
|
:rtype:
|
177
204
|
"""
|
@@ -182,12 +209,15 @@ class TestBulletins(TestCase):
|
|
182
209
|
created_by=self.user_1001,
|
183
210
|
)
|
184
211
|
|
185
|
-
self.assertEqual(bulletin.slug, "drifterke-rorki-v-dok")
|
212
|
+
self.assertEqual(first=bulletin.slug, second="drifterke-rorki-v-dok")
|
186
213
|
|
187
|
-
def test_should_return_cleaned_message_string_on_bulletin_creation(self):
|
214
|
+
def test_should_return_cleaned_message_string_on_bulletin_creation(self) -> None:
|
188
215
|
"""
|
189
|
-
Test should return a clean/sanitized message string
|
216
|
+
Test should return a clean/sanitized message string
|
217
|
+
when a new bulletin is created
|
218
|
+
|
190
219
|
:return:
|
220
|
+
:rtype:
|
191
221
|
"""
|
192
222
|
|
193
223
|
# given
|
@@ -196,18 +226,19 @@ class TestBulletins(TestCase):
|
|
196
226
|
"'test')</script>and this is style test. <style>.MathJax, "
|
197
227
|
".MathJax_Message, .MathJax_Preview{display: none}</style>end tests."
|
198
228
|
)
|
199
|
-
cleaned_message = string_cleanup(dirty_message)
|
229
|
+
cleaned_message = string_cleanup(string=dirty_message)
|
200
230
|
bulletin = Bulletin.objects.create(
|
201
231
|
title="Foobar",
|
202
232
|
content=dirty_message,
|
203
233
|
created_by=self.user_1001,
|
204
234
|
)
|
205
235
|
|
206
|
-
self.assertEqual(bulletin.content, cleaned_message)
|
236
|
+
self.assertEqual(first=bulletin.content, second=cleaned_message)
|
207
237
|
|
208
|
-
def test_bulletin_slug_creation(self):
|
238
|
+
def test_bulletin_slug_creation(self) -> None:
|
209
239
|
"""
|
210
240
|
Test slug creation
|
241
|
+
|
211
242
|
:return:
|
212
243
|
:rtype:
|
213
244
|
"""
|
@@ -230,13 +261,14 @@ class TestBulletins(TestCase):
|
|
230
261
|
created_by=self.user_1001,
|
231
262
|
)
|
232
263
|
|
233
|
-
self.assertEqual(bulletin.slug, "this-is-a-bulletin")
|
234
|
-
self.assertEqual(bulletin_2.slug, "this-is-a-bulletin-1")
|
235
|
-
self.assertEqual(bulletin_3.slug, "this-is-a-bulletin-2")
|
264
|
+
self.assertEqual(first=bulletin.slug, second="this-is-a-bulletin")
|
265
|
+
self.assertEqual(first=bulletin_2.slug, second="this-is-a-bulletin-1")
|
266
|
+
self.assertEqual(first=bulletin_3.slug, second="this-is-a-bulletin-2")
|
236
267
|
|
237
|
-
def test_should_return_bulletin_title_as_model_object_string_name(self):
|
268
|
+
def test_should_return_bulletin_title_as_model_object_string_name(self) -> None:
|
238
269
|
"""
|
239
270
|
Test should return the object's string name
|
271
|
+
|
240
272
|
:return:
|
241
273
|
:rtype:
|
242
274
|
"""
|
@@ -247,11 +279,12 @@ class TestBulletins(TestCase):
|
|
247
279
|
created_by=self.user_1001,
|
248
280
|
)
|
249
281
|
|
250
|
-
self.assertEqual(str(bulletin), "This is a bulletin")
|
282
|
+
self.assertEqual(first=str(bulletin), second="This is a bulletin")
|
251
283
|
|
252
|
-
def test_form_clean_content_method(self):
|
284
|
+
def test_form_clean_content_method(self) -> None:
|
253
285
|
"""
|
254
286
|
Test the clean_ method of the form
|
287
|
+
|
255
288
|
:return:
|
256
289
|
:rtype:
|
257
290
|
"""
|
@@ -261,10 +294,10 @@ class TestBulletins(TestCase):
|
|
261
294
|
"'test')</script>and this is style test. <style>.MathJax, "
|
262
295
|
".MathJax_Message, .MathJax_Preview{display: none}</style>end tests."
|
263
296
|
)
|
264
|
-
cleaned_message = string_cleanup(dirty_message)
|
297
|
+
cleaned_message = string_cleanup(string=dirty_message)
|
265
298
|
data = {"title": "This is a title", "content": dirty_message}
|
266
299
|
|
267
|
-
form = BulletinForm(data)
|
300
|
+
form = BulletinForm(data=data)
|
268
301
|
|
269
|
-
self.assertTrue(form.is_valid())
|
270
|
-
self.assertEqual(form.cleaned_data["content"], cleaned_message)
|
302
|
+
self.assertTrue(expr=form.is_valid())
|
303
|
+
self.assertEqual(first=form.cleaned_data["content"], second=cleaned_message)
|
@@ -15,22 +15,25 @@ class TestVersionedStatic(TestCase):
|
|
15
15
|
Test aa_bulletin_board_versioned_static template tag
|
16
16
|
"""
|
17
17
|
|
18
|
-
def test_versioned_static(self):
|
18
|
+
def test_versioned_static(self) -> None:
|
19
19
|
"""
|
20
20
|
Test versioned static template tag
|
21
|
+
|
21
22
|
:return:
|
22
23
|
:rtype:
|
23
24
|
"""
|
24
25
|
|
25
26
|
context = Context({"version": __version__})
|
26
27
|
template_to_render = Template(
|
27
|
-
|
28
|
-
|
28
|
+
template_string=(
|
29
|
+
"{% load aa_bulletin_board_versioned_static %}"
|
30
|
+
"{% aa_bulletin_board_static 'aa_bulletin_board/css/aa-bulletin-board.min.css' %}" # pylint: disable=line-too-long
|
31
|
+
)
|
29
32
|
)
|
30
33
|
|
31
|
-
rendered_template = template_to_render.render(context)
|
34
|
+
rendered_template = template_to_render.render(context=context)
|
32
35
|
|
33
36
|
self.assertInHTML(
|
34
|
-
f'/static/aa_bulletin_board/css/aa-bulletin-board.min.css?v={context["version"]}',
|
35
|
-
rendered_template,
|
37
|
+
needle=f'/static/aa_bulletin_board/css/aa-bulletin-board.min.css?v={context["version"]}', # pylint: disable=line-too-long
|
38
|
+
haystack=rendered_template,
|
36
39
|
)
|
@@ -24,35 +24,43 @@ class TestBulletinUI(WebTest):
|
|
24
24
|
"""
|
25
25
|
|
26
26
|
@classmethod
|
27
|
-
def setUpClass(cls):
|
27
|
+
def setUpClass(cls) -> None:
|
28
28
|
"""
|
29
29
|
Set up groups and users
|
30
|
+
|
31
|
+
:return:
|
32
|
+
:rtype:
|
30
33
|
"""
|
31
34
|
|
32
35
|
super().setUpClass()
|
33
36
|
cls.group = Group.objects.create(name="Superhero")
|
34
37
|
|
35
38
|
# User cannot access bulletins
|
36
|
-
cls.user_1001 = create_fake_user(
|
39
|
+
cls.user_1001 = create_fake_user(
|
40
|
+
character_id=1001, character_name="Peter Parker"
|
41
|
+
)
|
37
42
|
|
38
43
|
# User can access bulletins
|
39
44
|
cls.user_1002 = create_fake_user(
|
40
|
-
1002,
|
45
|
+
character_id=1002,
|
46
|
+
character_name="Bruce Wayne",
|
47
|
+
permissions=["aa_bulletin_board.basic_access"],
|
41
48
|
)
|
42
49
|
|
43
50
|
# User can manage bulletins
|
44
51
|
cls.user_1003 = create_fake_user(
|
45
|
-
1003,
|
46
|
-
"Clark Kent",
|
52
|
+
character_id=1003,
|
53
|
+
character_name="Clark Kent",
|
47
54
|
permissions=[
|
48
55
|
"aa_bulletin_board.basic_access",
|
49
56
|
"aa_bulletin_board.manage_bulletins",
|
50
57
|
],
|
51
58
|
)
|
52
59
|
|
53
|
-
def test_should_show_bulletin_page(self):
|
60
|
+
def test_should_show_bulletin_page(self) -> None:
|
54
61
|
"""
|
55
62
|
Test if a bulletin is shown
|
63
|
+
|
56
64
|
:return:
|
57
65
|
:rtype:
|
58
66
|
"""
|
@@ -63,51 +71,64 @@ class TestBulletinUI(WebTest):
|
|
63
71
|
content=f"<p>{fake.sentence()}</p>",
|
64
72
|
created_by=self.user_1002,
|
65
73
|
)
|
66
|
-
self.app.set_user(self.user_1002)
|
74
|
+
self.app.set_user(user=self.user_1002)
|
67
75
|
|
68
76
|
# when
|
69
77
|
page = self.app.get(
|
70
|
-
reverse(
|
78
|
+
url=reverse(
|
79
|
+
viewname="aa_bulletin_board:view_bulletin", args=[bulletin.slug]
|
80
|
+
)
|
71
81
|
)
|
72
82
|
|
73
83
|
# then
|
74
|
-
self.assertTemplateUsed(
|
84
|
+
self.assertTemplateUsed(
|
85
|
+
response=page, template_name="aa_bulletin_board/bulletin.html"
|
86
|
+
)
|
75
87
|
|
76
|
-
def test_should_redirect_to_bulletin_dashboard_when_bulletin_does_not_exist(
|
88
|
+
def test_should_redirect_to_bulletin_dashboard_when_bulletin_does_not_exist(
|
89
|
+
self,
|
90
|
+
) -> None:
|
77
91
|
"""
|
78
92
|
Test should redirect to bulletin dashboard when bulletin does not exist
|
93
|
+
|
79
94
|
:return:
|
80
95
|
:rtype:
|
81
96
|
"""
|
82
97
|
|
83
98
|
# given
|
84
|
-
self.app.set_user(self.user_1002)
|
99
|
+
self.app.set_user(user=self.user_1002)
|
85
100
|
|
86
101
|
# when
|
87
|
-
page = self.app.get(
|
102
|
+
page = self.app.get(
|
103
|
+
url=reverse(viewname="aa_bulletin_board:view_bulletin", args=["foobar"])
|
104
|
+
)
|
88
105
|
|
89
106
|
# then
|
90
|
-
self.assertRedirects(page, "/bulletin-board/")
|
107
|
+
self.assertRedirects(response=page, expected_url="/bulletin-board/")
|
91
108
|
|
92
|
-
def test_should_show_create_bulletin_page(self):
|
109
|
+
def test_should_show_create_bulletin_page(self) -> None:
|
93
110
|
"""
|
94
111
|
Test if create bulletin is shown
|
112
|
+
|
95
113
|
:return:
|
96
114
|
:rtype:
|
97
115
|
"""
|
98
116
|
|
99
117
|
# given
|
100
|
-
self.app.set_user(self.user_1003)
|
118
|
+
self.app.set_user(user=self.user_1003)
|
101
119
|
|
102
120
|
# when
|
103
|
-
page = self.app.get(reverse("aa_bulletin_board:create_bulletin"))
|
121
|
+
page = self.app.get(url=reverse(viewname="aa_bulletin_board:create_bulletin"))
|
104
122
|
|
105
123
|
# then
|
106
|
-
self.assertTemplateUsed(
|
124
|
+
self.assertTemplateUsed(
|
125
|
+
response=page, template_name="aa_bulletin_board/edit-bulletin.html"
|
126
|
+
)
|
107
127
|
|
108
|
-
def test_should_show_edit_bulletin_page(self):
|
128
|
+
def test_should_show_edit_bulletin_page(self) -> None:
|
109
129
|
"""
|
110
130
|
Test if edit bulletin is shown
|
131
|
+
|
111
132
|
:return:
|
112
133
|
:rtype:
|
113
134
|
"""
|
@@ -118,49 +139,58 @@ class TestBulletinUI(WebTest):
|
|
118
139
|
content=f"<p>{fake.sentence()}</p>",
|
119
140
|
created_by=self.user_1002,
|
120
141
|
)
|
121
|
-
self.app.set_user(self.user_1003)
|
142
|
+
self.app.set_user(user=self.user_1003)
|
122
143
|
|
123
144
|
# when
|
124
145
|
page = self.app.get(
|
125
|
-
reverse(
|
146
|
+
url=reverse(
|
147
|
+
viewname="aa_bulletin_board:edit_bulletin", args=[bulletin.slug]
|
148
|
+
)
|
126
149
|
)
|
127
150
|
|
128
151
|
# then
|
129
|
-
self.assertTemplateUsed(
|
152
|
+
self.assertTemplateUsed(
|
153
|
+
response=page, template_name="aa_bulletin_board/edit-bulletin.html"
|
154
|
+
)
|
130
155
|
|
131
156
|
def test_should_redirect_to_bulletin_dashboard_when_edit_bulletin_does_not_exist(
|
132
157
|
self,
|
133
|
-
):
|
158
|
+
) -> None:
|
134
159
|
"""
|
135
160
|
Test should redirect to bulletin dashboard when bulletin to edit does not exist
|
161
|
+
|
136
162
|
:return:
|
137
163
|
:rtype:
|
138
164
|
"""
|
139
165
|
|
140
166
|
# given
|
141
|
-
self.app.set_user(self.user_1003)
|
167
|
+
self.app.set_user(user=self.user_1003)
|
142
168
|
|
143
169
|
# when
|
144
|
-
page = self.app.get(
|
170
|
+
page = self.app.get(
|
171
|
+
url=reverse(viewname="aa_bulletin_board:edit_bulletin", args=["foobar"])
|
172
|
+
)
|
145
173
|
|
146
174
|
# then
|
147
|
-
self.assertRedirects(page, "/bulletin-board/")
|
175
|
+
self.assertRedirects(response=page, expected_url="/bulletin-board/")
|
148
176
|
|
149
|
-
def test_should_return_cleaned_message_string_on_bulletin_creation(self):
|
177
|
+
def test_should_return_cleaned_message_string_on_bulletin_creation(self) -> None:
|
150
178
|
"""
|
151
179
|
Test should return a clean/sanitized message string when a new bulletin is created
|
180
|
+
|
152
181
|
:return:
|
182
|
+
:rtype:
|
153
183
|
"""
|
154
184
|
|
155
185
|
# given
|
156
|
-
self.app.set_user(self.user_1003)
|
157
|
-
page = self.app.get(reverse("aa_bulletin_board:create_bulletin"))
|
186
|
+
self.app.set_user(user=self.user_1003)
|
187
|
+
page = self.app.get(url=reverse(viewname="aa_bulletin_board:create_bulletin"))
|
158
188
|
dirty_message = (
|
159
189
|
'this is a script test. <script type="text/javascript">alert('
|
160
190
|
"'test')</script>and this is style test. <style>.MathJax, "
|
161
191
|
".MathJax_Message, .MathJax_Preview{display: none}</style>end tests."
|
162
192
|
)
|
163
|
-
cleaned_message = string_cleanup(dirty_message)
|
193
|
+
cleaned_message = string_cleanup(string=dirty_message)
|
164
194
|
|
165
195
|
# when
|
166
196
|
form = page.forms["aa-bulletin-board-bulletin-form"]
|
@@ -170,12 +200,14 @@ class TestBulletinUI(WebTest):
|
|
170
200
|
|
171
201
|
# then
|
172
202
|
new_bulletin = Bulletin.objects.last()
|
173
|
-
self.assertEqual(new_bulletin.content, cleaned_message)
|
203
|
+
self.assertEqual(first=new_bulletin.content, second=cleaned_message)
|
174
204
|
|
175
|
-
def test_should_return_cleaned_message_string_on_bulletin_edit(self):
|
205
|
+
def test_should_return_cleaned_message_string_on_bulletin_edit(self) -> None:
|
176
206
|
"""
|
177
207
|
Test should return a clean/sanitized message string when a bulletin is edited
|
208
|
+
|
178
209
|
:return:
|
210
|
+
:rtype:
|
179
211
|
"""
|
180
212
|
|
181
213
|
# given
|
@@ -184,18 +216,20 @@ class TestBulletinUI(WebTest):
|
|
184
216
|
content=f"<p>{fake.sentence()}</p>",
|
185
217
|
created_by=self.user_1002,
|
186
218
|
)
|
187
|
-
self.app.set_user(self.user_1003)
|
219
|
+
self.app.set_user(user=self.user_1003)
|
188
220
|
|
189
221
|
# when
|
190
222
|
page = self.app.get(
|
191
|
-
reverse(
|
223
|
+
url=reverse(
|
224
|
+
viewname="aa_bulletin_board:edit_bulletin", args=[bulletin.slug]
|
225
|
+
)
|
192
226
|
)
|
193
227
|
dirty_message = (
|
194
228
|
'this is a script test. <script type="text/javascript">alert('
|
195
229
|
"'test')</script>and this is style test. <style>.MathJax, "
|
196
230
|
".MathJax_Message, .MathJax_Preview{display: none}</style>end tests."
|
197
231
|
)
|
198
|
-
cleaned_message = string_cleanup(dirty_message)
|
232
|
+
cleaned_message = string_cleanup(string=dirty_message)
|
199
233
|
|
200
234
|
form = page.forms["aa-bulletin-board-bulletin-form"]
|
201
235
|
form["title"] = "Message Cleanup Test"
|
@@ -204,20 +238,21 @@ class TestBulletinUI(WebTest):
|
|
204
238
|
|
205
239
|
# then
|
206
240
|
bulletin_edited = Bulletin.objects.get(pk=bulletin.pk)
|
207
|
-
self.assertEqual(bulletin_edited.content, cleaned_message)
|
241
|
+
self.assertEqual(first=bulletin_edited.content, second=cleaned_message)
|
208
242
|
|
209
243
|
def test_should_return_to_edit_bulletin_form_for_invalid_form_submitted_on_create_bulletin(
|
210
244
|
self,
|
211
|
-
):
|
245
|
+
) -> None:
|
212
246
|
"""
|
213
247
|
Test should return to the bulletin form, because the submitted form is not valid
|
214
248
|
due to missing title
|
249
|
+
|
215
250
|
:return:
|
216
251
|
:rtype:
|
217
252
|
"""
|
218
253
|
|
219
|
-
self.app.set_user(self.user_1003)
|
220
|
-
page = self.app.get(reverse("aa_bulletin_board:create_bulletin"))
|
254
|
+
self.app.set_user(user=self.user_1003)
|
255
|
+
page = self.app.get(url=reverse(viewname="aa_bulletin_board:create_bulletin"))
|
221
256
|
|
222
257
|
# when
|
223
258
|
form = page.forms["aa-bulletin-board-bulletin-form"]
|
@@ -225,14 +260,17 @@ class TestBulletinUI(WebTest):
|
|
225
260
|
page = form.submit()
|
226
261
|
|
227
262
|
# then
|
228
|
-
self.assertTemplateUsed(
|
263
|
+
self.assertTemplateUsed(
|
264
|
+
response=page, template_name="aa_bulletin_board/edit-bulletin.html"
|
265
|
+
)
|
229
266
|
|
230
267
|
def test_should_return_to_edit_bulletin_form_for_invalid_form_submitted_on_edit_bulletin(
|
231
268
|
self,
|
232
|
-
):
|
269
|
+
) -> None:
|
233
270
|
"""
|
234
271
|
Test should return to the bulletin form, because the submitted form is not valid
|
235
272
|
due to missing title
|
273
|
+
|
236
274
|
:return:
|
237
275
|
:rtype:
|
238
276
|
"""
|
@@ -242,11 +280,13 @@ class TestBulletinUI(WebTest):
|
|
242
280
|
content=f"<p>{fake.sentence()}</p>",
|
243
281
|
created_by=self.user_1002,
|
244
282
|
)
|
245
|
-
self.app.set_user(self.user_1003)
|
283
|
+
self.app.set_user(user=self.user_1003)
|
246
284
|
|
247
285
|
# when
|
248
286
|
page = self.app.get(
|
249
|
-
reverse(
|
287
|
+
url=reverse(
|
288
|
+
viewname="aa_bulletin_board:edit_bulletin", args=[bulletin.slug]
|
289
|
+
)
|
250
290
|
)
|
251
291
|
|
252
292
|
# when
|
@@ -256,4 +296,6 @@ class TestBulletinUI(WebTest):
|
|
256
296
|
page = form.submit()
|
257
297
|
|
258
298
|
# then
|
259
|
-
self.assertTemplateUsed(
|
299
|
+
self.assertTemplateUsed(
|
300
|
+
response=page, template_name="aa_bulletin_board/edit-bulletin.html"
|
301
|
+
)
|
aa_bulletin_board/tests/utils.py
CHANGED
@@ -25,10 +25,29 @@ def create_fake_user(
|
|
25
25
|
) -> User:
|
26
26
|
"""
|
27
27
|
Create a fake user incl. Main character and (optional) permissions.
|
28
|
+
|
29
|
+
:param character_id:
|
30
|
+
:type character_id:
|
31
|
+
:param character_name:
|
32
|
+
:type character_name:
|
33
|
+
:param corporation_id:
|
34
|
+
:type corporation_id:
|
35
|
+
:param corporation_name:
|
36
|
+
:type corporation_name:
|
37
|
+
:param corporation_ticker:
|
38
|
+
:type corporation_ticker:
|
39
|
+
:param alliance_id:
|
40
|
+
:type alliance_id:
|
41
|
+
:param alliance_name:
|
42
|
+
:type alliance_name:
|
43
|
+
:param permissions:
|
44
|
+
:type permissions:
|
45
|
+
:return:
|
46
|
+
:rtype:
|
28
47
|
"""
|
29
48
|
|
30
|
-
username = re.sub(r"[^\w\d@\.\+-]", "_", character_name)
|
31
|
-
user = AuthUtils.create_user(username)
|
49
|
+
username = re.sub(pattern=r"[^\w\d@\.\+-]", repl="_", string=character_name)
|
50
|
+
user = AuthUtils.create_user(username=username)
|
32
51
|
|
33
52
|
if not corporation_id:
|
34
53
|
corporation_id = 2001
|
@@ -51,7 +70,9 @@ def create_fake_user(
|
|
51
70
|
)
|
52
71
|
|
53
72
|
if permissions:
|
54
|
-
perm_objs = [
|
73
|
+
perm_objs = [
|
74
|
+
AuthUtils.get_permission_by_name(perm=perm) for perm in permissions
|
75
|
+
]
|
55
76
|
user = AuthUtils.add_permissions_to_user(perms=perm_objs, user=user)
|
56
77
|
|
57
78
|
return user
|
aa_bulletin_board/urls.py
CHANGED
@@ -11,9 +11,11 @@ from aa_bulletin_board import views
|
|
11
11
|
app_name: str = "aa_bulletin_board"
|
12
12
|
|
13
13
|
urlpatterns = [
|
14
|
-
path("", views.dashboard, name="dashboard"),
|
15
|
-
path("create/", views.create_bulletin, name="create_bulletin"),
|
16
|
-
path("bulletin/<slug:slug>/", views.view_bulletin, name="view_bulletin"),
|
17
|
-
path("edit/<slug:slug>/", views.edit_bulletin, name="edit_bulletin"),
|
18
|
-
path(
|
14
|
+
path(route="", view=views.dashboard, name="dashboard"),
|
15
|
+
path(route="create/", view=views.create_bulletin, name="create_bulletin"),
|
16
|
+
path(route="bulletin/<slug:slug>/", view=views.view_bulletin, name="view_bulletin"),
|
17
|
+
path(route="edit/<slug:slug>/", view=views.edit_bulletin, name="edit_bulletin"),
|
18
|
+
path(
|
19
|
+
route="remove/<slug:slug>/", view=views.remove_bulletin, name="remove_bulletin"
|
20
|
+
),
|
19
21
|
]
|