33from django .utils import timezone
44from django .contrib .gis .geos import GEOSGeometry
55
6- from language .models import Language , Community , CommunityMember , Recording
6+ from language .models import (
7+ Language ,
8+ Community ,
9+ CommunityMember ,
10+ CommunityLanguageStats ,
11+ Recording ,
12+ )
713from users .models import User , Administrator
814from web .constants import VERIFIED , REJECTED
915
1016
1117class BaseTestCase (APITestCase ):
1218 def setUp (self ):
13- # Create an Admin Type User
19+ FAKE_GEOM = """
20+ {
21+ "type": "Point",
22+ "coordinates": [
23+ -126.3482666015625,
24+ 54.74840576223716
25+ ]
26+ }
27+ """
28+ self .point = GEOSGeometry (FAKE_GEOM )
29+
1430 self .admin_user = User .objects .create (
1531 username = "admin_user" ,
1632 first_name = "Admin" ,
@@ -22,7 +38,6 @@ def setUp(self):
2238 self .admin_user .set_password ("password" )
2339 self .admin_user .save ()
2440
25- # Create a Regular User with no Privileges
2641 self .regular_user = User .objects .create (
2742 username = "regular_user" ,
2843 first_name = "Regular" ,
@@ -32,11 +47,11 @@ def setUp(self):
3247 self .regular_user .set_password ("password" )
3348 self .regular_user .save ()
3449
35- # Initial Values for Language and Community
3650 self .test_language = Language .objects .create (name = "Global Test Language" )
37- self .test_community = Community .objects .create (name = "Global Test Community" )
51+ self .test_community = Community .objects .create (
52+ name = "Global Test Community" , point = FAKE_GEOM
53+ )
3854
39- # Create a Community Admin for Testing Permissions
4055 self .community_admin = User .objects .create (
4156 username = "community_admin_user" ,
4257 first_name = "Community Admin" ,
@@ -45,33 +60,27 @@ def setUp(self):
4560 )
4661 self .community_admin .set_password ("password" )
4762 self .community_admin .save ()
63+
4864 Administrator .objects .create (
4965 user = self .community_admin ,
5066 language = self .test_language ,
5167 community = self .test_community ,
5268 )
5369
54- FAKE_GEOM = """
55- {
56- "type": "Point",
57- "coordinates": [
58- -126.3482666015625,
59- 54.74840576223716
60- ]
61- }
62- """
63- self .point = GEOSGeometry (FAKE_GEOM )
64-
65-
66- class CommunityGeoAPITests (BaseTestCase ):
67- def setUp (self ):
68- super ().setUp ()
70+ # Create a community without a point, which does not show in the list/search APIs
71+ self .invalid_community = Community .objects .create (name = "Invalid Community" )
6972
70- self .valid_community = Community .objects .create (
71- name = "Valid Community" , point = self .point
73+ # Create a test stats
74+ self .test_stats = CommunityLanguageStats .objects .create (
75+ community = self .test_community ,
76+ language = self .test_language ,
77+ fluent_speakers = 1 ,
78+ semi_speakers = 1 ,
79+ active_learners = 1 ,
7280 )
73- self .invalid_community = Community .objects .create (name = "Invalid Community" )
7481
82+
83+ class CommunityAPIRouteTests (BaseTestCase ):
7584 def test_community_geo_route_exists (self ):
7685 """
7786 Ensure Community Geo API route exists
@@ -86,6 +95,73 @@ def test_community_search_route_exists(self):
8695 response = self .client .get ("/api/community-search/" , format = "json" )
8796 self .assertEqual (response .status_code , status .HTTP_200_OK )
8897
98+ def test_community_list_route_exists (self ):
99+ """
100+ Ensure Community List API route exists
101+ """
102+ response = self .client .get ("/api/community/" , format = "json" )
103+ self .assertEqual (response .status_code , status .HTTP_200_OK )
104+
105+ def test_community_list_member_to_verify_route_exists (self ):
106+ """
107+ Ensure Community List Members to Verify API route exists
108+ """
109+ response = self .client .get (
110+ "/api/community/list_member_to_verify/" , format = "json"
111+ )
112+ self .assertEqual (response .status_code , status .HTTP_200_OK )
113+
114+ def test_community_member_verify_route_exists (self ):
115+ """
116+ Ensure Community Member Verify API route exists
117+ """
118+ response = self .client .get ("/api/community/verify_member/" , format = "json" )
119+ self .assertEqual (response .status_code , status .HTTP_405_METHOD_NOT_ALLOWED )
120+
121+ def test_community_member_reject_route_exists (self ):
122+ """
123+ Ensure Community Member Reject API route exists
124+ """
125+ response = self .client .get ("/api/community/reject_member/" , format = "json" )
126+ self .assertEqual (response .status_code , status .HTTP_405_METHOD_NOT_ALLOWED )
127+
128+ def test_community_detail_route_exists (self ):
129+ """
130+ Ensure Community Detail API route exists
131+ """
132+ response = self .client .get (
133+ f"/api/community/{ self .test_community .id } /" , format = "json"
134+ )
135+ self .assertEqual (response .status_code , status .HTTP_200_OK )
136+
137+ def test_community_add_audio_route_exists (self ):
138+ """
139+ Ensure Community Add Audio API route exists
140+ """
141+ self .assertTrue (
142+ self .client .login (username = "community_admin_user" , password = "password" )
143+ )
144+ response = self .client .get (
145+ f"/api/community/{ self .test_community .id } /add_audio/" , format = "json"
146+ )
147+ self .assertEqual (response .status_code , status .HTTP_405_METHOD_NOT_ALLOWED )
148+
149+ def test_stats_list_route_exists (self ):
150+ """
151+ Ensure Stats List API route exists
152+ """
153+ response = self .client .get ("/api/stats/" , format = "json" )
154+ self .assertEqual (response .status_code , status .HTTP_200_OK )
155+
156+ def test_stats_detail_route_exists (self ):
157+ """
158+ Ensure Stats Detail API route exists
159+ """
160+ response = self .client .get (f"/api/stats/{ self .test_stats .id } /" , format = "json" )
161+ self .assertEqual (response .status_code , status .HTTP_200_OK )
162+
163+
164+ class CommunityGeoAPITests (BaseTestCase ):
89165 def test_community_geo (self ):
90166 """
91167 Ensure Community Geo API works
@@ -95,7 +171,7 @@ def test_community_geo(self):
95171 self .assertEqual (response .status_code , status .HTTP_200_OK )
96172
97173 # By fetching "features" specifically, we're committing
98- # that this API si a GEO Feature API
174+ # that this API is a GEO Feature API
99175 data = response .json ().get ("features" )
100176
101177 # Only count 1 because the 2nd community in setUp() is invalid
@@ -111,9 +187,9 @@ def test_community_search(self):
111187 data = response .json ()
112188
113189 # By fetching the first record, we're committing
114- # that the valid_community was added to the search list
115- valid_community = data [0 ]
116- self .assertEqual (valid_community .get ("name" ), "Valid Community" )
190+ # that the test_community was added to the search list
191+ test_community = data [0 ]
192+ self .assertEqual (test_community .get ("name" ), "Global Test Community" )
117193
118194
119195class CommunityAPITests (BaseTestCase ):
@@ -149,13 +225,6 @@ def test_community_detail(self):
149225 response .data ["audio_obj" ]["recorder" ], self .recording .recorder
150226 )
151227
152- def test_community_list_route_exists (self ):
153- """
154- Ensure community list API route exists
155- """
156- response = self .client .get ("/api/community/" , format = "json" )
157- self .assertEqual (response .status_code , status .HTTP_200_OK )
158-
159228 def test_community_add_audio_for_admin (self ):
160229 """
161230 Ensure we can add a community audio to a community object using an admin account.
0 commit comments