Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
add tests for the 'common' app
Browse files Browse the repository at this point in the history
  • Loading branch information
anatskiy committed Jan 30, 2017
1 parent ba941fb commit d26cef1
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.contrib.auth import get_user_model
from .models import Organization, PrincipalInvestigator, CostUnit

import json

User = get_user_model()


Expand Down Expand Up @@ -64,10 +66,28 @@ def test_get(self):

class NavigationTreeTest(TestCase):
def setUp(self):
User.objects.create_user(email='foo@bar.io', password='foo-foo')
admin = User.objects.create_user(
email='admin@bar.io', password='foo-foo', is_staff=True,
)

def test_navigation_tree(self):
self.client.login(email='foo@bar.io', password='foo-foo')
user = User.objects.create_user(
email='user@bar.io', password='foo-foo', is_staff=False,
)

def test_navigation_tree_admin(self):
self.client.login(email='admin@bar.io', password='foo-foo')
response = self.client.get(reverse('get_navigation_tree'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response['content-type'], 'application/json')

def test_navigation_tree_user(self):
self.client.login(email='user@bar.io', password='foo-foo')
response = self.client.get(reverse('get_navigation_tree'))
tabs = [
t['text']
for t in json.loads(str(response.content, 'utf-8'))['children']
]
hidden_tabs = ['Approval', 'Library Preparation', 'Pooling']

self.assertEqual(response.status_code, 200)
self.assertEqual(len(set(hidden_tabs).intersection(tabs)), 0)

0 comments on commit d26cef1

Please sign in to comment.