@@ -69,8 +69,8 @@ def test_user_codelists(
6969 for version in codelist ["versions" ]
7070 if version .is_draft
7171 ] == [
72- codelist .versions .first ().id ,
7372 organisation_codelist .versions .first ().id ,
73+ codelist .versions .first ().id ,
7474 ]
7575
7676 # make org codelist under-review
@@ -144,3 +144,89 @@ def test_user_codelists(
144144 org_codelist_version_id ,
145145 user_codelist_version_id ,
146146 ]
147+
148+
149+ def test_user_codelists_sort_user_first (
150+ client ,
151+ user ,
152+ organisation ,
153+ codelist_from_scratch ,
154+ user_codelist_from_scratch ,
155+ ):
156+ # Give both codelists the same name (case-insensitive), one user-owned and one org-owned
157+ update_codelist (
158+ codelist = user_codelist_from_scratch ,
159+ owner = user ,
160+ name = "alpha list" ,
161+ slug = "alpha-list-user" ,
162+ description = user_codelist_from_scratch .description ,
163+ methodology = user_codelist_from_scratch .methodology ,
164+ references = {},
165+ signoffs = {},
166+ )
167+ update_codelist (
168+ codelist = codelist_from_scratch ,
169+ owner = organisation ,
170+ name = "ALPHA LIST" ,
171+ slug = "alpha-list-org" ,
172+ description = codelist_from_scratch .description ,
173+ methodology = codelist_from_scratch .methodology ,
174+ references = {},
175+ signoffs = {},
176+ )
177+
178+ client .force_login (user )
179+ response = client .get (reverse ("user" , args = (user .username ,)))
180+
181+ matching_codelists = [
182+ codelist ["codelist" ]
183+ for codelist in response .context ["all_codelists" ]
184+ if codelist ["codelist" ].name .casefold () == "alpha list"
185+ ]
186+ assert [codelist .owner for codelist in matching_codelists ] == [user , organisation ]
187+
188+
189+ def test_published_codelists_sorted_same_as_all_codelists (
190+ client ,
191+ user ,
192+ user_codelist ,
193+ user_codelist_from_scratch ,
194+ ):
195+ update_codelist (
196+ codelist = user_codelist ,
197+ owner = user ,
198+ name = "zeta list" ,
199+ slug = "zeta-list" ,
200+ description = user_codelist .description ,
201+ methodology = user_codelist .methodology ,
202+ references = {},
203+ signoffs = {},
204+ )
205+ update_codelist (
206+ codelist = user_codelist_from_scratch ,
207+ owner = user ,
208+ name = "ALPHA LIST" ,
209+ slug = "alpha-list" ,
210+ description = user_codelist_from_scratch .description ,
211+ methodology = user_codelist_from_scratch .methodology ,
212+ references = {},
213+ signoffs = {},
214+ )
215+ save_for_review (draft = user_codelist_from_scratch .versions .first ())
216+ publish_version (version = user_codelist_from_scratch .versions .last ())
217+
218+ client .force_login (user )
219+ response = client .get (reverse ("user" , args = (user .username ,)))
220+
221+ codelist_ids = {user_codelist .id , user_codelist_from_scratch .id }
222+ all_codelist_ids = [
223+ codelist ["codelist" ].id
224+ for codelist in response .context ["all_codelists" ]
225+ if codelist ["codelist" ].id in codelist_ids
226+ ]
227+ published_codelist_ids = [
228+ version .codelist .id
229+ for version in response .context ["published_codelists" ]
230+ if version .codelist .id in codelist_ids
231+ ]
232+ assert published_codelist_ids == all_codelist_ids
0 commit comments