@@ -23,10 +23,32 @@ def setUpTestData(cls):
23
23
# PrimaryNavigation.html requires apphook + categories
24
24
create_apphook_page (ProductsApphook )
25
25
cls .published1 = CategoryFactory (
26
- path = "0001" , name = "First one" , slug = "first-one"
26
+ path = "0001" ,
27
+ name = "First one" ,
28
+ slug = "first-one" ,
29
+ visible_for_anonymous = True ,
30
+ visible_for_authenticated = True ,
27
31
)
28
32
cls .published2 = CategoryFactory (
29
- path = "0002" , name = "Second one" , slug = "second-one"
33
+ path = "0002" ,
34
+ name = "Second one" ,
35
+ slug = "second-one" ,
36
+ visible_for_anonymous = True ,
37
+ visible_for_authenticated = False ,
38
+ )
39
+ cls .published3 = CategoryFactory (
40
+ path = "0003" ,
41
+ name = "Third one" ,
42
+ slug = "third-one" ,
43
+ visible_for_anonymous = False ,
44
+ visible_for_authenticated = True ,
45
+ )
46
+ cls .published4 = CategoryFactory (
47
+ path = "0004" ,
48
+ name = "Fourth one" ,
49
+ slug = "fourth-one" ,
50
+ visible_for_anonymous = False ,
51
+ visible_for_authenticated = False ,
30
52
)
31
53
32
54
def test_categories_hidden_from_anonymous_users (self ):
@@ -55,6 +77,37 @@ def test_categories_not_hidden_from_anonymous_users(self):
55
77
self .assertEqual (categories [0 ].tag , "a" )
56
78
self .assertEqual (categories [1 ].tag , "button" )
57
79
80
+ links = [x for x in doc .find ("[title='Onderwerpen'] + ul li a" ).items ()]
81
+ self .assertEqual (len (links ), 4 )
82
+ self .assertEqual (links [0 ].attr ("href" ), self .published1 .get_absolute_url ())
83
+ self .assertEqual (links [1 ].attr ("href" ), self .published2 .get_absolute_url ())
84
+ self .assertEqual (links [2 ].attr ("href" ), self .published1 .get_absolute_url ())
85
+ self .assertEqual (links [3 ].attr ("href" ), self .published2 .get_absolute_url ())
86
+
87
+ def test_categories_visibility_for_authenticated_users (self ):
88
+ config = SiteConfiguration .get_solo ()
89
+ config .hide_categories_from_anonymous_users = False
90
+ config .save ()
91
+
92
+ self .client .force_login (self .user )
93
+
94
+ response = self .client .get ("/" , user = self .user )
95
+
96
+ doc = PyQuery (response .content )
97
+
98
+ categories = doc .find ("[title='Onderwerpen']" )
99
+
100
+ self .assertEqual (len (categories ), 2 )
101
+ self .assertEqual (categories [0 ].tag , "a" )
102
+ self .assertEqual (categories [1 ].tag , "button" )
103
+
104
+ links = [x for x in doc .find ("[title='Onderwerpen'] + ul li a" ).items ()]
105
+ self .assertEqual (len (links ), 4 )
106
+ self .assertEqual (links [0 ].attr ("href" ), self .published1 .get_absolute_url ())
107
+ self .assertEqual (links [1 ].attr ("href" ), self .published3 .get_absolute_url ())
108
+ self .assertEqual (links [2 ].attr ("href" ), self .published1 .get_absolute_url ())
109
+ self .assertEqual (links [3 ].attr ("href" ), self .published3 .get_absolute_url ())
110
+
58
111
def test_search_bar_hidden_from_anonymous_users (self ):
59
112
config = SiteConfiguration .get_solo ()
60
113
config .hide_search_from_anonymous_users = True
0 commit comments