diff --git a/web/grants/tests.py b/web/grants/tests.py index b2ecdbcf..b72aa6ed 100644 --- a/web/grants/tests.py +++ b/web/grants/tests.py @@ -29,7 +29,6 @@ def setUp(self): grant_category=self.test_category, ) - # This grant will not appear since we filter out grants without points self.test_grant_no_point = Grant.objects.create( grant="Test Grant No Point", title="Test Grant No Point Title", @@ -38,7 +37,7 @@ def setUp(self): ) -class GrantAPIRouteTests(APITestCase): +class GrantAPIRouteTests(BaseTestCase): def test_grant_list_route_exists(self): """ Ensure Grant List API route exists @@ -46,6 +45,13 @@ def test_grant_list_route_exists(self): response = self.client.get("/api/grants/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_grant_detail_route_exists(self): + """ + Ensure Grant Detail API route exists + """ + response = self.client.get(f"/api/grants/{self.test_grant.id}/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_grant_category_route_exists(self): """ Ensure Grant Categories List API route exists diff --git a/web/language/tests/tests_community.py b/web/language/tests/tests_community.py index f61e8bbf..f8c3ade1 100755 --- a/web/language/tests/tests_community.py +++ b/web/language/tests/tests_community.py @@ -3,14 +3,30 @@ from django.utils import timezone from django.contrib.gis.geos import GEOSGeometry -from language.models import Language, Community, CommunityMember, Recording +from language.models import ( + Language, + Community, + CommunityMember, + CommunityLanguageStats, + Recording, +) from users.models import User, Administrator from web.constants import VERIFIED, REJECTED class BaseTestCase(APITestCase): def setUp(self): - # Create an Admin Type User + FAKE_GEOM = """ + { + "type": "Point", + "coordinates": [ + -126.3482666015625, + 54.74840576223716 + ] + } + """ + self.point = GEOSGeometry(FAKE_GEOM) + self.admin_user = User.objects.create( username="admin_user", first_name="Admin", @@ -22,7 +38,6 @@ def setUp(self): self.admin_user.set_password("password") self.admin_user.save() - # Create a Regular User with no Privileges self.regular_user = User.objects.create( username="regular_user", first_name="Regular", @@ -32,11 +47,11 @@ def setUp(self): self.regular_user.set_password("password") self.regular_user.save() - # Initial Values for Language and Community self.test_language = Language.objects.create(name="Global Test Language") - self.test_community = Community.objects.create(name="Global Test Community") + self.test_community = Community.objects.create( + name="Global Test Community", point=FAKE_GEOM + ) - # Create a Community Admin for Testing Permissions self.community_admin = User.objects.create( username="community_admin_user", first_name="Community Admin", @@ -45,33 +60,27 @@ def setUp(self): ) self.community_admin.set_password("password") self.community_admin.save() + Administrator.objects.create( user=self.community_admin, language=self.test_language, community=self.test_community, ) - FAKE_GEOM = """ - { - "type": "Point", - "coordinates": [ - -126.3482666015625, - 54.74840576223716 - ] - } - """ - self.point = GEOSGeometry(FAKE_GEOM) - - -class CommunityGeoAPITests(BaseTestCase): - def setUp(self): - super().setUp() + # Create a community without a point, which does not show in the list/search APIs + self.invalid_community = Community.objects.create(name="Invalid Community") - self.valid_community = Community.objects.create( - name="Valid Community", point=self.point + # Create a test stats + self.test_stats = CommunityLanguageStats.objects.create( + community=self.test_community, + language=self.test_language, + fluent_speakers=1, + semi_speakers=1, + active_learners=1, ) - self.invalid_community = Community.objects.create(name="Invalid Community") + +class CommunityAPIRouteTests(BaseTestCase): def test_community_geo_route_exists(self): """ Ensure Community Geo API route exists @@ -86,6 +95,73 @@ def test_community_search_route_exists(self): response = self.client.get("/api/community-search/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_community_list_route_exists(self): + """ + Ensure Community List API route exists + """ + response = self.client.get("/api/community/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_community_list_member_to_verify_route_exists(self): + """ + Ensure Community List Members to Verify API route exists + """ + response = self.client.get( + "/api/community/list_member_to_verify/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_community_member_verify_route_exists(self): + """ + Ensure Community Member Verify API route exists + """ + response = self.client.get("/api/community/verify_member/", format="json") + self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) + + def test_community_member_reject_route_exists(self): + """ + Ensure Community Member Reject API route exists + """ + response = self.client.get("/api/community/reject_member/", format="json") + self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) + + def test_community_detail_route_exists(self): + """ + Ensure Community Detail API route exists + """ + response = self.client.get( + f"/api/community/{self.test_community.id}/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_community_add_audio_route_exists(self): + """ + Ensure Community Add Audio API route exists + """ + self.assertTrue( + self.client.login(username="community_admin_user", password="password") + ) + response = self.client.get( + f"/api/community/{self.test_community.id}/add_audio/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) + + def test_stats_list_route_exists(self): + """ + Ensure Stats List API route exists + """ + response = self.client.get("/api/stats/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_stats_detail_route_exists(self): + """ + Ensure Stats Detail API route exists + """ + response = self.client.get(f"/api/stats/{self.test_stats.id}/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + +class CommunityGeoAPITests(BaseTestCase): def test_community_geo(self): """ Ensure Community Geo API works @@ -95,7 +171,7 @@ def test_community_geo(self): self.assertEqual(response.status_code, status.HTTP_200_OK) # By fetching "features" specifically, we're committing - # that this API si a GEO Feature API + # that this API is a GEO Feature API data = response.json().get("features") # Only count 1 because the 2nd community in setUp() is invalid @@ -111,9 +187,9 @@ def test_community_search(self): data = response.json() # By fetching the first record, we're committing - # that the valid_community was added to the search list - valid_community = data[0] - self.assertEqual(valid_community.get("name"), "Valid Community") + # that the test_community was added to the search list + test_community = data[0] + self.assertEqual(test_community.get("name"), "Global Test Community") class CommunityAPITests(BaseTestCase): @@ -149,13 +225,6 @@ def test_community_detail(self): response.data["audio_obj"]["recorder"], self.recording.recorder ) - def test_community_list_route_exists(self): - """ - Ensure community list API route exists - """ - response = self.client.get("/api/community/", format="json") - self.assertEqual(response.status_code, status.HTTP_200_OK) - def test_community_add_audio_for_admin(self): """ Ensure we can add a community audio to a community object using an admin account. diff --git a/web/language/tests/tests_favourite.py b/web/language/tests/tests_favourite.py index 01b09c71..6cb2ab34 100755 --- a/web/language/tests/tests_favourite.py +++ b/web/language/tests/tests_favourite.py @@ -44,17 +44,41 @@ def setUp(self): self.point = GEOSGeometry(self.FAKE_GEOM) -class FavouriteAPITests(BaseTestCase): +class FavouriteAPIRouteTests(BaseTestCase): def test_favourite_list_route_exists(self): """ Ensure Favourite list API route exists """ - # Must be logged in - self.client.login(username="admin_user", password="password") + self.assertTrue(self.client.login(username="admin_user", password="password")) response = self.client.get("/api/favourite/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_favourite_detail_route_exists(self): + """ + Ensure Favourite Detail API route exists + """ + + self.assertTrue(self.client.login(username="admin_user", password="password")) + + favourite_placename = Favourite.objects.create( + name="Test Favourite Placename", + user=self.admin_user, + place=self.place, + favourite_type="favourite", + description="I like this Placename", + point=self.point, + zoom=10, + ) + + response = self.client.get( + f"/api/favourite/{favourite_placename.id}/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + +class FavouriteAPITests(BaseTestCase): + def test_get_favourite_placename(self): """ Ensure we can retrieve a newly created Favourite object. diff --git a/web/language/tests/tests_language.py b/web/language/tests/tests_language.py index e26ac971..5a052afa 100755 --- a/web/language/tests/tests_language.py +++ b/web/language/tests/tests_language.py @@ -9,16 +9,16 @@ class BaseTestCase(APITestCase): def setUp(self): - self.user = User.objects.create( - username="testuser001", - first_name="Test", - last_name="user 001", - email="test@countable.ca", + self.admin_user = User.objects.create( + username="admin_user", + first_name="Admin", + last_name="User", + email="admin@countable.ca", is_staff=True, is_superuser=True, ) - self.user.set_password("password") - self.user.save() + self.admin_user.set_password("password") + self.admin_user.save() self.FAKE_GEOM = """ { @@ -45,21 +45,48 @@ def setUp(self): ] }""" - -class CommunityGeoAPITests(BaseTestCase): - def setUp(self): - super().setUp() - poly = GEOSGeometry(self.FAKE_GEOM) - # Only include if it has a geometry - self.language1 = Language.objects.create( # Included (1) + + self.language1 = Language.objects.create( # With geom name="test language1", geom=poly ) - self.language2 = Language.objects.create( # Exclude + self.language2 = Language.objects.create( # Without geom name="test language2", ) - # ONE TEST TESTS ONLY ONE SCENARIO ###### + +class LanguageAPIRouteTests(BaseTestCase): + def test_language_list_route_exists(self): + """ + Ensure Language List API route exists + """ + response = self.client.get("/api/language/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_language_detail_route_exists(self): + """ + Ensure Language Detail API route exists + """ + response = self.client.get(f"/api/language/{self.language1.id}/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_language_add_greeting_audio_route_exists(self): + """ + Ensure Language Add Greeting Audio API route exists + """ + response = self.client.get( + f"/api/language/{self.language1.id}/add_greeting_audio/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) + + def test_language_add_language_audio_route_exists(self): + """ + Ensure Language Add Language Audio API route exists + """ + response = self.client.get( + f"/api/language/{self.language1.id}/add_language_audio/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) def test_language_geo_route_exists(self): """ @@ -75,6 +102,10 @@ def test_language_search_route_exists(self): response = self.client.get("/api/language-search/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) + +class LanguageGeoAPITests(BaseTestCase): + # ONE TEST TESTS ONLY ONE SCENARIO ###### + def test_language_geo(self): """ Ensure Language Geo API works @@ -150,7 +181,7 @@ def test_language_add_language_audio(self): Ensure we can add a language audio to a language object. """ # Must be logged in - self.assertTrue(self.client.login(username="testuser001", password="password")) + self.assertTrue(self.client.login(username="admin_user", password="password")) # Check we're logged in response = self.client.get("/api/user/auth/") @@ -187,7 +218,7 @@ def test_language_add_greeting_audio(self): Ensure we can add a greeting audio to a language object. """ # Must be logged in - self.assertTrue(self.client.login(username="testuser001", password="password")) + self.assertTrue(self.client.login(username="admin_user", password="password")) # Check we're logged in response = self.client.get("/api/user/auth/") diff --git a/web/language/tests/tests_media.py b/web/language/tests/tests_media.py index 95506b74..6551fe3d 100755 --- a/web/language/tests/tests_media.py +++ b/web/language/tests/tests_media.py @@ -31,7 +31,7 @@ def setUp(self): self.admin_user.set_password("password") self.admin_user.save() - # Create a Regular User with no Privileges + # Create a regular user with no privileges self.regular_user = User.objects.create( username="regular_user", first_name="Regular", @@ -42,6 +42,74 @@ def setUp(self): self.regular_user.save() +class MediaAPIRouteTests(BaseTestCase): + def setUp(self): + super().setUp() + + self.verified_media = Media.objects.create( + name="Verified Media", + file_type="string", + status=VERIFIED, + ) + + self.unverified_media = Media.objects.create( + name="Unverified Media", + file_type="string", + status=UNVERIFIED, + ) + + def test_media_list_route_exists(self): + """ + Ensure Media List API route exists + """ + response = self.client.get("/api/media/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_media_list_to_verify_route_exists(self): + """ + Ensure Media List to Verify API route exists + """ + self.assertTrue(self.client.login(username="admin_user", password="password")) + response = self.client.get(f"/api/media/list_to_verify/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_media_detail_route_exists(self): + """ + Ensure Media Detail API route exists + """ + response = self.client.get( + f"/api/media/{self.verified_media.id}/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_media_flag_route_exists(self): + """ + Ensure Media Detail API route exists + """ + response = self.client.get( + f"/api/media/{self.unverified_media.id}/flag/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) + + def test_media_reject_route_exists(self): + """ + Ensure Media Detail API route exists + """ + response = self.client.get( + f"/api/media/{self.unverified_media.id}/reject/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) + + def test_media_verify_route_exists(self): + """ + Ensure Media Detail API route exists + """ + response = self.client.get( + f"/api/media/{self.unverified_media.id}/verify/", format="json" + ) + self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) + + class MediaAPITests(BaseTestCase): def setUp(self): super().setUp() diff --git a/web/language/tests/tests_notification.py b/web/language/tests/tests_notification.py index a8d64c7b..8ab061f6 100755 --- a/web/language/tests/tests_notification.py +++ b/web/language/tests/tests_notification.py @@ -34,10 +34,6 @@ def setUp(self): self.user2.set_password("password") self.user2.save() - -class NotificationAPITests(BaseTestCase): - def setUp(self): - super().setUp() self.community1 = Community.objects.create(name="Test Community 1") self.language1 = Language.objects.create(name="Test Language 01") self.user_owned_notification = Notification.objects.create( @@ -46,6 +42,28 @@ def setUp(self): user=self.user, ) + +class NotificationAPIRouteTests(BaseTestCase): + def test_notification_list_route_exists(self): + """ + Ensure Notification List API exists + """ + self.assertTrue(self.client.login(username="testuser001", password="password")) + response = self.client.get("/api/notification/") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_notification_detail_route_exists(self): + """ + Ensure Notification Detail API exists + """ + self.assertTrue(self.client.login(username="testuser001", password="password")) + response = self.client.get( + f"/api/notification/{self.user_owned_notification.id}/" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + +class NotificationAPITests(BaseTestCase): # ONE TEST TESTS ONLY ONE SCENARIO def test_notification_detail(self): diff --git a/web/language/tests/tests_placename.py b/web/language/tests/tests_placename.py index f1e48abe..97e40c68 100755 --- a/web/language/tests/tests_placename.py +++ b/web/language/tests/tests_placename.py @@ -6,6 +6,7 @@ from language.models import ( Language, PlaceName, + Champion, Community, CommunityMember, Media, @@ -26,7 +27,6 @@ class BaseTestCase(APITestCase): def setUp(self): - # Create an Admin Type User self.admin_user = User.objects.create( username="admin_user", first_name="Admin", @@ -38,7 +38,6 @@ def setUp(self): self.admin_user.set_password("password") self.admin_user.save() - # Create a Regular User with no Privileges self.regular_user = User.objects.create( username="regular_user", first_name="Regular", @@ -47,9 +46,39 @@ def setUp(self): ) self.regular_user.set_password("password") self.regular_user.save() + self.now = timezone.now() + self.community1 = Community.objects.create(name="Test Community 01") + self.community2 = Community.objects.create(name="Test Community 02") + self.language1 = Language.objects.create(name="Test Language 01") + self.language2 = Language.objects.create(name="Test Language 02") + self.taxonomy = Taxonomy.objects.create( + name="Test Taxonomy", description="Test taxonomy desc." + ) -class PlaceNameAPIRouteTests(APITestCase): + self.new_user = User.objects.create( + username="new_user", + first_name="New", + last_name="User", + email="new.user@countable.ca", + is_staff=True, + is_superuser=True, + ) + self.new_user.set_password("password") + self.new_user.save() + + self.recording = Recording.objects.create( + speaker="Test recording", + recorder="Test recording", + created=self.now, + date_recorded=self.now, + ) + self.test_champion = Champion.objects.create( + name="Test Champion", bio="Test Bio", job="Test Job" + ) + + +class PlaceNameAPIRouteTests(BaseTestCase): def test_placename_detail_route_exists(self): """ Ensure PlaceName details API route exists @@ -67,6 +96,13 @@ def test_placename_list_route_exists(self): response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_placename_list_to_verify_route_exists(self): + """ + Ensure PlaceName list API route exists + """ + response = self.client.get("/api/placename/list_to_verify/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) + # GEO APIs def test_placename_geo_route_exists(self): """ @@ -135,7 +171,7 @@ def test_resource_list_route_exists(self): def test_grant_list_route_exists(self): """ - Ensure Grant List API route exists + Ensure Grant List API route exists (deprecated) """ response = self.client.get("/api/arts/grant/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -149,42 +185,31 @@ def test_artwork_list_route_exists(self): def test_poi_list_route_exists(self): """ - Ensure Art Search API route exists + Ensure POI List API route exists """ response = self.client.get("/api/arts/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_champion_list_route_exists(self): + """ + Ensure Champion List API route exists + """ + response = self.client.get("/api/champion/", format="json") + self.assertEqual(response.status_code, status.HTTP_200_OK) -class PlaceNameAPITests(BaseTestCase): - def setUp(self): - super().setUp() - self.now = timezone.now() - - self.community = Community.objects.create(name="Test Community") - self.community2 = Community.objects.create(name="Test Community 02") - self.language1 = Language.objects.create(name="Test Language 01") - self.language2 = Language.objects.create(name="Test Language 02") - self.taxonomy = Taxonomy.objects.create( - name="Test Taxonomy", description="Test taxonomy desc." + def test_champion_detail_route_exists(self): + """ + Ensure Champion Detail API route exists + """ + response = self.client.get( + f"/api/champion/{self.test_champion.id}/", format="json" ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.user2 = User.objects.create( - username="testuser002", - first_name="Test2", - last_name="user 002", - email="test2@countable.ca", - is_staff=True, - is_superuser=True, - ) - self.user2.set_password("password") - self.user2.save() - self.recording = Recording.objects.create( - speaker="Test recording", - recorder="Test recording", - created=self.now, - date_recorded=self.now, - ) +class PlaceNameAPITests(BaseTestCase): + def setUp(self): + super().setUp() def test_placename_detail(self): """ @@ -210,7 +235,7 @@ def test_placename_detail_returned_fields(self): audio_description="string", language=self.language1, ) - test_placename.communities.set([self.community]) + test_placename.communities.set([self.community1]) response = self.client.get( "/api/placename/{}/".format(test_placename.id), format="json" ) @@ -232,7 +257,7 @@ def test_placename_list_not_logged_in(self): test_placename01 = PlaceName.objects.create( name="test place01", language=self.language1, status=VERIFIED ) - test_placename01.communities.set([self.community]) + test_placename01.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) @@ -241,7 +266,7 @@ def test_placename_list_not_logged_in(self): test_placename02 = PlaceName.objects.create( name="test place02", language=self.language1, status=UNVERIFIED ) - test_placename02.communities.set([self.community]) + test_placename02.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) @@ -250,7 +275,7 @@ def test_placename_list_not_logged_in(self): test_placename03 = PlaceName.objects.create( name="test place03", language=self.language1, status=REJECTED ) - test_placename03.communities.set([self.community]) + test_placename03.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) @@ -259,7 +284,7 @@ def test_placename_list_not_logged_in(self): test_placename04 = PlaceName.objects.create( name="test place04", language=self.language1, status=FLAGGED ) - test_placename04.communities.set([self.community]) + test_placename04.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) @@ -282,7 +307,7 @@ def test_placename_list_logged_in_creator(self): language=self.language1, community_only=True, ) - test_placename01.communities.set([self.community]) + test_placename01.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) @@ -308,7 +333,7 @@ def test_placename_list_logged_in_creator(self): community_only=True, status=REJECTED, ) - test_placename03.communities.set([self.community]) + test_placename03.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 3) @@ -329,11 +354,11 @@ def test_placename_list_logged_in_creator(self): # REJECTED Placename from another user test_placename05 = PlaceName.objects.create( name="test place05", - creator=self.user2, + creator=self.new_user, language=self.language1, status=REJECTED, ) - test_placename05.communities.set([self.community]) + test_placename05.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 4) @@ -356,14 +381,14 @@ def test_placename_list_logged_in_member(self): community_only=True, status=VERIFIED, ) - test_placename01.communities.set([self.community]) + test_placename01.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 0) # UNVERIFIED CommunityMember MATCHING users's community member_same01 = CommunityMember.objects.create( - user=self.admin_user, community=self.community, status=UNVERIFIED + user=self.admin_user, community=self.community1, status=UNVERIFIED ) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -383,7 +408,7 @@ def test_placename_list_logged_in_member(self): community_only=True, status=UNVERIFIED, ) - test_placename02.communities.set([self.community]) + test_placename02.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) @@ -395,7 +420,7 @@ def test_placename_list_logged_in_member(self): community_only=True, status=REJECTED, ) - test_placename03.communities.set([self.community]) + test_placename03.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 3) @@ -407,7 +432,7 @@ def test_placename_list_logged_in_member(self): community_only=True, status=FLAGGED, ) - test_placename04.communities.set([self.community]) + test_placename04.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 4) @@ -442,7 +467,7 @@ def test_placename_list_logged_in_administrator(self): community_only=True, status=VERIFIED, ) - test_placename01.communities.set([self.community]) + test_placename01.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 0) @@ -450,7 +475,7 @@ def test_placename_list_logged_in_administrator(self): # Administrator of the pair language/community Administrator.objects.create( user=self.admin_user, - community=self.community, + community=self.community1, language=self.language1, ) @@ -472,7 +497,7 @@ def test_placename_list_logged_in_administrator(self): self.assertEqual(len(response.data), 1) # After changing the placename to the Administrator community - test_placename02.communities.set([self.community]) + test_placename02.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -491,7 +516,7 @@ def test_placename_list_logged_in_administrator(self): self.assertEqual(len(response.data), 2) # After changing the placename to the Administrator community - test_placename03.communities.set([self.community]) + test_placename03.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -510,7 +535,7 @@ def test_placename_list_logged_in_administrator(self): self.assertEqual(len(response.data), 3) # After changing the placename to the Administrator community - test_placename04.communities.set([self.community]) + test_placename04.communities.set([self.community1]) response = self.client.get("/api/placename/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -521,7 +546,7 @@ def test_placename_list_to_verify(self): Ensure placename list API brings newly created data which needs to be verified """ Administrator.objects.create( - user=self.admin_user, language=self.language1, community=self.community + user=self.admin_user, language=self.language1, community=self.community1 ) # Must be logged in to verify a media. @@ -535,7 +560,7 @@ def test_placename_list_to_verify(self): test_placename01 = PlaceName.objects.create( name="test place01", language=self.language1, status=VERIFIED ) - test_placename01.communities.set([self.community]) + test_placename01.communities.set([self.community1]) response = self.client.get("/api/placename/list_to_verify/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 0) @@ -547,7 +572,7 @@ def test_placename_list_to_verify(self): status=UNVERIFIED, status_reason="string", ) - test_placename02.communities.set([self.community]) + test_placename02.communities.set([self.community1]) response = self.client.get("/api/placename/list_to_verify/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) @@ -560,7 +585,7 @@ def test_placename_list_to_verify(self): status=FLAGGED, status_reason="string", ) - test_placename03.communities.set([self.community]) + test_placename03.communities.set([self.community1]) response = self.client.get("/api/placename/list_to_verify/", format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) @@ -606,7 +631,7 @@ def test_placename_post(self): "common_name": "string", "community_only": True, "description": "string", - "communities": [self.community.id], + "communities": [self.community1.id], "language": self.language1.id, "audio": self.recording.id, }, @@ -648,7 +673,7 @@ def test_placename_verify(self): placename.name = "test place" placename.language = self.language1 placename.save() - placename.communities.set([self.community]) + placename.communities.set([self.community1]) created_id = placename.id @@ -672,7 +697,7 @@ def test_placename_reject(self): placename.creator = self.admin_user placename.language = self.language1 placename.save() - placename.communities.set([self.community]) + placename.communities.set([self.community1]) created_id = placename.id @@ -693,7 +718,7 @@ def test_placename_flag(self): placename.creator = self.admin_user placename.language = self.language1 placename.save() - placename.communities.set([self.community]) + placename.communities.set([self.community1]) created_id = placename.id diff --git a/web/language/tests/tests_recording.py b/web/language/tests/tests_recording.py index 9b1fb5c0..f8e0e47a 100755 --- a/web/language/tests/tests_recording.py +++ b/web/language/tests/tests_recording.py @@ -20,32 +20,46 @@ def setUp(self): ) self.user.set_password("password") self.user.save() + self.now = timezone.now() + self.test_recording = Recording.objects.create( + speaker="Test speaker", + recorder="Test recorder", + created=self.now, + date_recorded=self.now, + ) -class RecordingAPITests(BaseTestCase): - def setUp(self): - super().setUp() - self.now = timezone.now() +class NotificationAPIRouteTests(BaseTestCase): + def test_recording_list_route_exists(self): + """ + Ensure Recording List API exists + """ + response = self.client.get("/api/recording/") + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_recording_detail_route_exists(self): + """ + Ensure Recording Detail API exists + """ + response = self.client.get( + f"/api/recording/{self.test_recording.id}/" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + +class RecordingAPITests(BaseTestCase): # ONE TEST TESTS ONLY ONE SCENARIO def test_recording_detail(self): """ Ensure we can retrieve a newly created recording object. """ - test_recording = Recording.objects.create( - speaker="Test speaker", - recorder="Test recorder", - created=self.now, - date_recorded=self.now, - ) - response = self.client.get( - "/api/recording/{}/".format(test_recording.id), format="json" + "/api/recording/{}/".format(self.test_recording.id), format="json" ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data["speaker"], test_recording.speaker) - self.assertEqual(response.data["recorder"], test_recording.recorder) + self.assertEqual(response.data["speaker"], self.test_recording.speaker) + self.assertEqual(response.data["recorder"], self.test_recording.recorder) def test_recording_post(self): """ @@ -85,15 +99,8 @@ def test_recording_patch(self): response = self.client.get("/api/user/auth/") self.assertEqual(response.json()["is_authenticated"], True) - test_recording = Recording.objects.create( - speaker="Test speaker", - recorder="Test recorder", - created=self.now, - date_recorded=self.now, - ) - response = self.client.patch( - "/api/recording/{}/".format(test_recording.id), + "/api/recording/{}/".format(self.test_recording.id), { "speaker": "Test speaker2", "recorder": "Test recorder2", @@ -102,7 +109,7 @@ def test_recording_patch(self): ) self.assertEqual(response.status_code, status.HTTP_200_OK) - recording = Recording.objects.get(pk=test_recording.id) + recording = Recording.objects.get(pk=self.test_recording.id) self.assertEqual(recording.speaker, "Test speaker2") self.assertEqual(recording.recorder, "Test recorder2") @@ -110,14 +117,7 @@ def test_recording_delete(self): """ Ensure recording API DELETE method API works """ - test_recording = Recording.objects.create( - speaker="Test speaker", - recorder="Test recorder", - created=self.now, - date_recorded=self.now, - ) - response = self.client.delete( - "/api/recording/{}/".format(test_recording.id), format="json" + "/api/recording/{}/".format(self.test_recording.id), format="json" ) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)