Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organization test cases #189

Merged
merged 10 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,3 @@ jobs:

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
# The codecov token to upload report. Can be retrieved from your Codecov dashboard.
# This should be set from `GitHub Repo > Settings > Secrets`.
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
dalmia marked this conversation as resolved.
Show resolved Hide resolved
dalmia marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions organizations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,30 @@ def setUp(self):
Organization.objects.create(name="Org 1", shortcode="org-1")
Organization.objects.create(name="Org 2", shortcode="org-2")

def test_guest_cannot_list_organization(self):
dalmia marked this conversation as resolved.
Show resolved Hide resolved
# unset the access token so that API requests go as unauthenticated user
self.client.credentials()
# Make a request without access token
response = self.client.get(reverse("organizations-list"))
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_guest_cannot_list_organization_random_token(self):
# Random token should give 401_unauthorized status
invalid_token = "abcd"
self.client.credentials(HTTP_AUTHORIZATION="Bearer " + invalid_token)

response = self.client.get(reverse("organizations-list"))
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_non_superuser_cannot_list_organizations(self):
"""A non-superuser should not be able to list organizations"""
# get organizations
response = self.client.get(reverse("organizations-list"))
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_superuser_can_list_organizations(self):
"""A superuser should be able to list organizations"""
self.user.is_superuser = True
self.user.save()
dalmia marked this conversation as resolved.
Show resolved Hide resolved
response = self.client.get(reverse("organizations-list"))
self.assertEqual(response.status_code, status.HTTP_200_OK)
22 changes: 19 additions & 3 deletions plio/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,26 @@ def test_user_cannot_duplicate_other_user_plio(self):
class VideoTestCase(BaseTestCase):
def setUp(self):
super().setUp()
# seed some videos
Video.objects.create(
title="Video 1", url="https://www.youtube.com/watch?v=vnISjBbrMUM"
)
Video.objects.create(
title="Video 2", url="https://www.youtube.com/watch?v=jWdA2JFCxGw"
)

def test_for_video(self):
# write API calls here
self.assertTrue(True)
def test_guest_cannot_list_videos(self):
# unset the credentials
self.client.credentials()
# get videos
response = self.client.get(reverse("videos-list"))
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_user_can_list_videos(self):
# get videos
response = self.client.get(reverse("videos-list"))
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 2)


class ItemTestCase(BaseTestCase):
Expand Down
2 changes: 1 addition & 1 deletion plio/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
api_router = routers.DefaultRouter()
api_router.register(r"organizations", OrganizationViewSet, basename="organizations")
api_router.register(r"users", UserViewSet, basename="users")
api_router.register(r"videos", VideoViewSet, basename="views")
api_router.register(r"videos", VideoViewSet, basename="videos")
# https://stackoverflow.com/questions/48548622/base-name-argument-not-specified-and-could-not-automatically-determine-the-name
api_router.register(r"plios", PlioViewSet, basename="plios")
api_router.register(r"items", ItemViewSet, basename="items")
Expand Down