Skip to content

Commit

Permalink
Merge pull request #195 from avantifellows/feature/redis-on-ci
Browse files Browse the repository at this point in the history
Redis on CI + Test for Org User
  • Loading branch information
dalmia authored Jun 18, 2021
2 parents 227fa48 + cfae60d commit 2bad47b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ jobs:
name: Test cases
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
# Maps port 6379 on service container to the host
- 6379:6379
# Set health checks to wait until redis has started
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5

# Creates a postgres docker where migrations will run.
db:
image: postgres:12.3-alpine
Expand Down Expand Up @@ -46,6 +54,7 @@ jobs:
- name: Run Test Cases
env:
DB_HOST: 127.0.0.1
DB_PORT: 5432
DB_NAME: github_actions_testing
DB_USER: postgres
DB_PASSWORD: postgres
Expand All @@ -54,6 +63,8 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_STORAGE_BUCKET_NAME: ${{ secrets.AWS_STORAGE_BUCKET_NAME }}
REDIS_HOSTNAME: 127.0.0.1
REDIS_PORT: 6379
# command to run tests and generate coverage metrics
run: coverage run manage.py test

Expand Down
41 changes: 37 additions & 4 deletions users/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from rest_framework import status
from django.urls import reverse
from users.models import OneTimePassword
from users.models import OneTimePassword, User, Role
from plio.tests import BaseTestCase
from organizations.models import Organization


class OtpAuthTestCase(BaseTestCase):
Expand Down Expand Up @@ -66,7 +67,39 @@ def test_for_role(self):
class OrganizationUserTestCase(BaseTestCase):
def setUp(self):
super().setUp()
# set up an organization
self.organization = Organization.objects.create(name="Org 1", shortcode="org-1")
# set up a user that's supposed to be in the organization
self.organization_user = User.objects.create(mobile="+919988776655")

def test_normal_user_cannot_create_organization_user(self):
# get org-view role
role_org_view = Role.objects.filter(name="org-view").first()
# add organization_user to the organization
response = self.client.post(
reverse("organization-users-list"),
{
"user": self.organization_user.id,
"organization": self.organization.id,
"role": role_org_view.id,
},
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_for_organization_user(self):
# write API calls here
self.assertTrue(True)
def test_superuser_can_create_organization_user(self):
# make the current user as superuser
self.user.is_superuser = True
self.user.save()

# get org-view role
role_org_view = Role.objects.filter(name="org-view").first()
# add organization_user to the organization
response = self.client.post(
reverse("organization-users-list"),
{
"user": self.organization_user.id,
"organization": self.organization.id,
"role": role_org_view.id,
},
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

0 comments on commit 2bad47b

Please sign in to comment.