aa-bulletin-board 1.10.0__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 +5 -2
- aa_bulletin_board/apps.py +3 -1
- aa_bulletin_board/auth_hooks.py +15 -8
- aa_bulletin_board/docs/screenshots/weblate/.gitkeep +0 -0
- aa_bulletin_board/docs/screenshots/weblate/aa-bulletin-board-bulletin-created-message.jpg +0 -0
- aa_bulletin_board/docs/screenshots/weblate/aa-bulletin-board-group-restrictions.jpg +0 -0
- aa_bulletin_board/docs/screenshots/weblate/aa-bulletin-board-headline.jpg +0 -0
- aa_bulletin_board/docs/screenshots/weblate/aa-bulletin-board-hint-group-restrictions.jpg +0 -0
- aa_bulletin_board/docs/screenshots/weblate/aa-bulletin-board-menu-item.jpg +0 -0
- aa_bulletin_board/docs/screenshots/weblate/aa-bulletin-board-read-more-button.jpg +0 -0
- aa_bulletin_board/forms.py +8 -6
- 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 +69 -25
- aa_bulletin_board/locale/django.pot +61 -19
- aa_bulletin_board/locale/es/LC_MESSAGES/django.po +61 -19
- aa_bulletin_board/locale/fr_FR/LC_MESSAGES/django.po +61 -19
- aa_bulletin_board/locale/it_IT/LC_MESSAGES/django.po +61 -19
- aa_bulletin_board/locale/ja/LC_MESSAGES/django.po +61 -19
- aa_bulletin_board/locale/ko_KR/LC_MESSAGES/django.po +61 -19
- aa_bulletin_board/locale/ru/LC_MESSAGES/django.mo +0 -0
- aa_bulletin_board/locale/ru/LC_MESSAGES/django.po +71 -27
- aa_bulletin_board/locale/uk/LC_MESSAGES/django.mo +0 -0
- aa_bulletin_board/locale/uk/LC_MESSAGES/django.po +75 -28
- aa_bulletin_board/locale/zh_Hans/LC_MESSAGES/django.po +61 -19
- aa_bulletin_board/managers.py +8 -3
- aa_bulletin_board/migrations/0001_initial.py +0 -1
- aa_bulletin_board/migrations/0002_alter_bulletin_slug.py +0 -1
- aa_bulletin_board/migrations/0003_group_restrictions.py +0 -1
- aa_bulletin_board/migrations/0004_model_translation.py +71 -0
- aa_bulletin_board/models.py +34 -8
- 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/static/aa_bulletin_board/css/aa-bulletin-board.css +11 -0
- aa_bulletin_board/static/aa_bulletin_board/css/aa-bulletin-board.min.css +1 -1
- aa_bulletin_board/templates/aa_bulletin_board/base.html +5 -1
- aa_bulletin_board/templates/aa_bulletin_board/bulletin.html +6 -6
- aa_bulletin_board/templates/aa_bulletin_board/bundles/sumoselect-css.html +1 -1
- aa_bulletin_board/templates/aa_bulletin_board/bundles/sumoselect-js.html +1 -1
- aa_bulletin_board/templates/aa_bulletin_board/dashboard.html +9 -7
- aa_bulletin_board/templates/aa_bulletin_board/edit-bulletin.html +7 -5
- 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 +102 -41
- aa_bulletin_board/tests/test_templatetags.py +9 -6
- aa_bulletin_board/tests/test_user_interface.py +88 -46
- aa_bulletin_board/tests/utils.py +33 -4
- aa_bulletin_board/urls.py +7 -5
- aa_bulletin_board/views.py +86 -33
- {aa_bulletin_board-1.10.0.dist-info → aa_bulletin_board-1.11.0.dist-info}/METADATA +2 -7
- aa_bulletin_board-1.11.0.dist-info/RECORD +63 -0
- {aa_bulletin_board-1.10.0.dist-info → aa_bulletin_board-1.11.0.dist-info}/WHEEL +1 -1
- aa_bulletin_board-1.10.0.dist-info/RECORD +0 -54
- {aa_bulletin_board-1.10.0.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
|
-
Test should create sentinel user when it doesn't exist
|
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,60 @@ 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
|
161
|
+
first=str(messages[0]),
|
162
|
+
second="The bulletin you are trying to delete does not exist.",
|
142
163
|
)
|
143
164
|
|
144
|
-
def
|
165
|
+
def test_should_raise_does_not_exist_exception_when_edit_bulletin_not_found(
|
166
|
+
self,
|
167
|
+
) -> None:
|
168
|
+
"""
|
169
|
+
Test if a bulletin that doesn't exist should be edited
|
170
|
+
|
171
|
+
:return:
|
172
|
+
:rtype:
|
173
|
+
"""
|
174
|
+
|
175
|
+
# given
|
176
|
+
bulletin = Bulletin.objects.create(
|
177
|
+
title=fake.sentence(),
|
178
|
+
content=f"<p>{fake.sentence()}</p>",
|
179
|
+
created_by=self.user_1001,
|
180
|
+
)
|
181
|
+
self.client.force_login(user=self.user_1003)
|
182
|
+
|
183
|
+
# when
|
184
|
+
response = self.client.get(
|
185
|
+
path=reverse(
|
186
|
+
viewname="aa_bulletin_board:edit_bulletin", args=["foobarsson"]
|
187
|
+
)
|
188
|
+
)
|
189
|
+
messages = list(get_messages(request=response.wsgi_request))
|
190
|
+
|
191
|
+
self.assertRaises(expected_exception=bulletin.DoesNotExist)
|
192
|
+
self.assertEqual(first=len(messages), second=1)
|
193
|
+
self.assertEqual(
|
194
|
+
first=str(messages[0]),
|
195
|
+
second="The bulletin you are trying to edit does not exist.",
|
196
|
+
)
|
197
|
+
|
198
|
+
def test_should_translate_russian_letters_in_slug(self) -> None:
|
145
199
|
"""
|
146
200
|
Test that russian letters in a slug are translated
|
201
|
+
|
147
202
|
:return:
|
148
203
|
:rtype:
|
149
204
|
"""
|
@@ -154,12 +209,15 @@ class TestBulletins(TestCase):
|
|
154
209
|
created_by=self.user_1001,
|
155
210
|
)
|
156
211
|
|
157
|
-
self.assertEqual(bulletin.slug, "drifterke-rorki-v-dok")
|
212
|
+
self.assertEqual(first=bulletin.slug, second="drifterke-rorki-v-dok")
|
158
213
|
|
159
|
-
def test_should_return_cleaned_message_string_on_bulletin_creation(self):
|
214
|
+
def test_should_return_cleaned_message_string_on_bulletin_creation(self) -> None:
|
160
215
|
"""
|
161
|
-
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
|
+
|
162
219
|
:return:
|
220
|
+
:rtype:
|
163
221
|
"""
|
164
222
|
|
165
223
|
# given
|
@@ -168,18 +226,19 @@ class TestBulletins(TestCase):
|
|
168
226
|
"'test')</script>and this is style test. <style>.MathJax, "
|
169
227
|
".MathJax_Message, .MathJax_Preview{display: none}</style>end tests."
|
170
228
|
)
|
171
|
-
cleaned_message = string_cleanup(dirty_message)
|
229
|
+
cleaned_message = string_cleanup(string=dirty_message)
|
172
230
|
bulletin = Bulletin.objects.create(
|
173
231
|
title="Foobar",
|
174
232
|
content=dirty_message,
|
175
233
|
created_by=self.user_1001,
|
176
234
|
)
|
177
235
|
|
178
|
-
self.assertEqual(bulletin.content, cleaned_message)
|
236
|
+
self.assertEqual(first=bulletin.content, second=cleaned_message)
|
179
237
|
|
180
|
-
def test_bulletin_slug_creation(self):
|
238
|
+
def test_bulletin_slug_creation(self) -> None:
|
181
239
|
"""
|
182
240
|
Test slug creation
|
241
|
+
|
183
242
|
:return:
|
184
243
|
:rtype:
|
185
244
|
"""
|
@@ -202,13 +261,14 @@ class TestBulletins(TestCase):
|
|
202
261
|
created_by=self.user_1001,
|
203
262
|
)
|
204
263
|
|
205
|
-
self.assertEqual(bulletin.slug, "this-is-a-bulletin")
|
206
|
-
self.assertEqual(bulletin_2.slug, "this-is-a-bulletin-1")
|
207
|
-
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")
|
208
267
|
|
209
|
-
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:
|
210
269
|
"""
|
211
|
-
Test should return the
|
270
|
+
Test should return the object's string name
|
271
|
+
|
212
272
|
:return:
|
213
273
|
:rtype:
|
214
274
|
"""
|
@@ -219,11 +279,12 @@ class TestBulletins(TestCase):
|
|
219
279
|
created_by=self.user_1001,
|
220
280
|
)
|
221
281
|
|
222
|
-
self.assertEqual(str(bulletin), "This is a bulletin")
|
282
|
+
self.assertEqual(first=str(bulletin), second="This is a bulletin")
|
223
283
|
|
224
|
-
def test_form_clean_content_method(self):
|
284
|
+
def test_form_clean_content_method(self) -> None:
|
225
285
|
"""
|
226
286
|
Test the clean_ method of the form
|
287
|
+
|
227
288
|
:return:
|
228
289
|
:rtype:
|
229
290
|
"""
|
@@ -233,10 +294,10 @@ class TestBulletins(TestCase):
|
|
233
294
|
"'test')</script>and this is style test. <style>.MathJax, "
|
234
295
|
".MathJax_Message, .MathJax_Preview{display: none}</style>end tests."
|
235
296
|
)
|
236
|
-
cleaned_message = string_cleanup(dirty_message)
|
297
|
+
cleaned_message = string_cleanup(string=dirty_message)
|
237
298
|
data = {"title": "This is a title", "content": dirty_message}
|
238
299
|
|
239
|
-
form = BulletinForm(data)
|
300
|
+
form = BulletinForm(data=data)
|
240
301
|
|
241
|
-
self.assertTrue(form.is_valid())
|
242
|
-
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
|
-
Test should return a clean/sanitized message string when new bulletin is created
|
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
|
-
Test should return to bulletin form, because submitted form is not valid
|
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
|
-
Test should return to bulletin form, because submitted form is not valid
|
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
@@ -23,16 +23,41 @@ def create_fake_user(
|
|
23
23
|
alliance_name: str = None,
|
24
24
|
permissions: List[str] = None,
|
25
25
|
) -> User:
|
26
|
-
"""
|
27
|
-
|
28
|
-
|
26
|
+
"""
|
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:
|
47
|
+
"""
|
48
|
+
|
49
|
+
username = re.sub(pattern=r"[^\w\d@\.\+-]", repl="_", string=character_name)
|
50
|
+
user = AuthUtils.create_user(username=username)
|
51
|
+
|
29
52
|
if not corporation_id:
|
30
53
|
corporation_id = 2001
|
31
54
|
corporation_name = "Wayne Technologies Inc."
|
32
55
|
corporation_ticker = "WTE"
|
56
|
+
|
33
57
|
if not alliance_id:
|
34
58
|
alliance_id = 3001
|
35
59
|
alliance_name = "Wayne Enterprises"
|
60
|
+
|
36
61
|
AuthUtils.add_main_character_2(
|
37
62
|
user=user,
|
38
63
|
name=character_name,
|
@@ -43,7 +68,11 @@ def create_fake_user(
|
|
43
68
|
alliance_id=alliance_id,
|
44
69
|
alliance_name=alliance_name,
|
45
70
|
)
|
71
|
+
|
46
72
|
if permissions:
|
47
|
-
perm_objs = [
|
73
|
+
perm_objs = [
|
74
|
+
AuthUtils.get_permission_by_name(perm=perm) for perm in permissions
|
75
|
+
]
|
48
76
|
user = AuthUtils.add_permissions_to_user(perms=perm_objs, user=user)
|
77
|
+
|
49
78
|
return user
|