@@ -38,6 +38,60 @@ def test_api_users_list_authenticated():
38
38
content = response .json ()
39
39
assert len (content ["results" ]) == 3
40
40
41
+ def test_api_users_list_query_email ():
42
+ """
43
+ Authenticated users should be able to list users
44
+ and filter by email.
45
+ """
46
+ user = factories .UserFactory ()
47
+
48
+ client = APIClient ()
49
+ client .force_login (user )
50
+
51
+ dave = factories .UserFactory (email = "david.bowman@work.com" )
52
+ nicole = factories .UserFactory (email = "nicole_foole@work.com" )
53
+ frank = factories .UserFactory (email = "frank_poole@work.com" )
54
+ factories .UserFactory (email = "heywood_floyd@work.com" )
55
+
56
+ response = client .get (
57
+ "/api/v1.0/users/?q=david.bowman@work.com" ,
58
+ )
59
+ assert response .status_code == 200
60
+ user_ids = [user ["id" ] for user in response .json ()["results" ]]
61
+ assert user_ids == [str (dave .id )]
62
+
63
+ response = client .get (
64
+ "/api/v1.0/users/?q=oole"
65
+ )
66
+
67
+ assert response .status_code == 200
68
+ user_ids = [user ["id" ] for user in response .json ()["results" ]]
69
+ assert user_ids == [str (nicole .id ), str (frank .id )]
70
+
71
+ def test_api_users_list_query_email_exclude_doc_user ():
72
+ """
73
+ Authenticated users should be able to list users
74
+ and filter by email.
75
+ """
76
+ user = factories .UserFactory ()
77
+ document = factories .DocumentFactory ()
78
+ access = factories .UserDocumentAccessFactory (document = document , user = user )
79
+
80
+ client = APIClient ()
81
+ client .force_login (user )
82
+
83
+ nicole = factories .UserFactory (email = "nicole_foole@work.com" )
84
+ frank = factories .UserFactory (email = "frank_poole@work.com" )
85
+ factories .UserFactory (email = "heywood_floyd@work.com" )
86
+
87
+ response = client .get (
88
+ "/api/v1.0/users/?q=oole"
89
+ )
90
+
91
+ assert response .status_code == 200
92
+ user_ids = [user ["id" ] for user in response .json ()["results" ]]
93
+ assert user_ids == [str (nicole .id ), str (frank .id )]
94
+
41
95
42
96
def test_api_users_retrieve_me_anonymous ():
43
97
"""Anonymous users should not be allowed to list users."""
0 commit comments