1
- from django .core .exceptions import ValidationError
2
1
from django .test import override_settings
3
2
from django .urls import reverse
4
3
8
7
from open_inwoner .accounts .tests .factories import ActionFactory , UserFactory
9
8
from open_inwoner .cms .profile .cms_appconfig import ProfileConfig
10
9
11
- from ..models import SiteConfiguration
12
-
13
10
14
11
@override_settings (ROOT_URLCONF = "open_inwoner.cms.tests.urls" )
15
12
class TestShowActions (WebTest ):
16
13
def setUp (self ):
17
14
self .user = UserFactory ()
18
- self .config = SiteConfiguration .get_solo ()
19
-
20
15
self .action = ActionFactory (created_by = self .user )
21
-
22
16
self .profile_url = reverse ("profile:detail" )
23
17
self .actions_list_url = reverse ("profile:action_list" )
24
18
25
- def test_default_enabled (self ):
26
- self .assertTrue (self .config .show_actions )
27
-
28
- def test_show_plans_requires_show_actions (self ):
29
- config = SiteConfiguration .get_solo ()
30
-
31
- # fine
32
- config .show_plans = False
33
- config .show_actions = False
34
- config .clean ()
35
-
36
- # fine
37
- config .show_plans = True
38
- config .show_actions = True
39
- config .clean ()
40
-
41
- # fine
42
- config .show_plans = False
43
- config .show_actions = True
44
- config .clean ()
45
-
46
- # not fine
47
- config .show_plans = True
48
- config .show_actions = False
49
- with self .assertRaises (ValidationError ) as e :
50
- config .clean ()
51
-
52
- self .assertEqual (
53
- set (e .exception .error_dict .keys ()), {"show_actions" , "show_plans" }
54
- )
55
-
56
- def test_when_enabled_and_user_is_logged_in (self ):
57
19
# cms profile apphook configuration
58
- profile_app = ProfileConfig .objects .create (namespace = "profile" )
20
+ self . profile_config = ProfileConfig .objects .create (namespace = "profile" )
59
21
api .create_page (
60
22
"profile" ,
61
23
"INHERIT" ,
62
24
"nl" ,
63
25
published = True ,
64
26
apphook = "ProfileApphook" ,
65
- apphook_namespace = profile_app .namespace ,
27
+ apphook_namespace = self . profile_config .namespace ,
66
28
)
29
+
30
+ def test_default_enabled (self ):
31
+ self .assertTrue (self .profile_config .actions )
32
+
33
+ def test_when_enabled_and_user_is_logged_in (self ):
67
34
response = self .app .get (self .profile_url , user = self .user )
68
35
69
36
links = response .pyquery (".personal-overview" )
70
37
self .assertNotEqual (links .find (".personal-overview__actions" ), [])
71
38
self .assertNotEqual (links .find (f'a[href="{ self .actions_list_url } "]' ), [])
72
39
73
40
def test_when_disabled_and_user_is_logged_in (self ):
74
- self .config . show_actions = False
75
- self .config .save ()
41
+ self .profile_config . actions = False
42
+ self .profile_config .save ()
76
43
response = self .app .get (self .profile_url , user = self .user )
77
44
78
45
links = response .pyquery (".personal-overview" )
@@ -92,8 +59,8 @@ def test_action_pages_show_404_when_disabled(self):
92
59
]
93
60
94
61
# test disabled raises http 404
95
- self .config . show_actions = False
96
- self .config .save ()
62
+ self .profile_config . actions = False
63
+ self .profile_config .save ()
97
64
98
65
for url in urls :
99
66
with self .subTest (f"{ url } " ):
0 commit comments