summaryrefslogtreecommitdiff
path: root/statistics_app/tests/test_views.py
diff options
context:
space:
mode:
authorAkshen2017-09-29 15:45:37 +0530
committerAkshen2017-09-29 15:45:37 +0530
commit59d5f503b11ecaa4b6d85b9f1f46bd9334bbfc7c (patch)
tree8f28914d89f110d42a7238eceb91dd4323945fcd /statistics_app/tests/test_views.py
parent8a0dcbf56d6a5a8ab389a0879c0da7a426de0d37 (diff)
downloadworkshop_booking-59d5f503b11ecaa4b6d85b9f1f46bd9334bbfc7c.tar.gz
workshop_booking-59d5f503b11ecaa4b6d85b9f1f46bd9334bbfc7c.tar.bz2
workshop_booking-59d5f503b11ecaa4b6d85b9f1f46bd9334bbfc7c.zip
Adds TestCases to statistics_app
- testcases added to statistics_app - ModelsTable_Diagram added - testcase modified for workshop_app/test_views.py
Diffstat (limited to 'statistics_app/tests/test_views.py')
-rw-r--r--statistics_app/tests/test_views.py176
1 files changed, 176 insertions, 0 deletions
diff --git a/statistics_app/tests/test_views.py b/statistics_app/tests/test_views.py
new file mode 100644
index 0000000..f3c7927
--- /dev/null
+++ b/statistics_app/tests/test_views.py
@@ -0,0 +1,176 @@
+from workshop_app.views import view_profile, user_login, edit_profile
+from django.test import TestCase
+from workshop_app.models import Profile, User, Workshop, WorkshopType,\
+ RequestedWorkshop, BookedWorkshop, ProposeWorkshopDate,\
+ has_profile
+from datetime import datetime
+from json import dumps
+from django.test import Client
+from django.contrib.auth.models import Group, Permission
+from django.contrib.auth import authenticate
+from django.core.urlresolvers import reverse
+from workshop_app.forms import CreateWorkshop
+from django.conf import settings
+
+
+class TestProfile(TestCase):
+ def setUp(self):
+ self.client = Client()
+
+ self.user1 = User.objects.create(
+ username='demo_test_user1',
+ password='pass@123',
+ email='test.user@gmail.com')
+
+ self.user2 = User.objects.create(
+ username='demo_test_user2',
+ email='test.user@gmail.com')
+
+ self.user2.set_password('pass@123')
+ self.user2.save()
+
+ self.user2_profile = Profile.objects.create(
+ user=self.user2,
+ department='Computer Engineering',
+ institute='ace',
+ title='Doctor',
+ position='instructor',
+ phone_number='1122993388',
+ location='mumbai',
+ how_did_you_hear_about_us='Google',
+ state='IN-MH',
+ is_email_verified=1
+ )
+
+ def test_has_profile_for_user_without_profile(self):
+ """
+ If no profile exists for user passed as argument return False
+ """
+ has_profile_status = has_profile(self.user1)
+ self.assertFalse(has_profile_status)
+
+ def test_has_profile_for_user_with_profile(self):
+ """
+ If profile exists for user passed as argument return True
+ """
+ has_profile_status = has_profile(self.user2)
+ self.assertTrue(has_profile_status)
+
+ def test_view_profile_denies_anonymous(self):
+ """
+ If not logged in redirect to login page
+ """
+ response = self.client.get(reverse(view_profile), follow=True)
+ redirect_destination = '/login/?next=/view_profile/'
+ self.assertTrue(response.status_code,200)
+ self.assertRedirects(response, redirect_destination)
+
+ def test_edit_profile_get(self):
+ """
+ GET request to edit profile should display profile form
+ """
+
+ self.client.login(username=self.user2, password='pass@123')
+ response = self.client.get(reverse(edit_profile))
+ user_profile = User.objects.get(id=self.user2.id)
+ profile = Profile.objects.get(user=user_profile)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(profile.institute, 'ace')
+ self.client.logout()
+
+ def test_edit_profile_post(self):
+
+ self.client.login(username=self.user2, password='pass@123')
+ response = self.client.post('/edit_profile/',
+ {
+ 'first_name': 'demo_test',
+ 'last_name': 'user2',
+ 'institute': 'IIT',
+ 'department': 'aerospace engineering'
+ })
+
+ updated_profile_user = User.objects.get(id=self.user2.id)
+ updated_profile = Profile.objects.get(user=updated_profile_user)
+ self.assertEqual(updated_profile.institute, 'IIT')
+ self.assertEqual(updated_profile.department, 'aerospace engineering')
+ self.assertEqual(updated_profile.position, 'instructor')
+ self.assertEqual(response.status_code, 200)
+ # self.assertTemplateUsed(response, 'workshop_app/profile_updated.html')
+
+ def test_register_page(self):
+ self.client.get('/register/')
+ self.register_response = self.client.post('/register/',
+ data={
+ 'username':'testuser',
+ 'email':'test@user.com',
+ 'password':'ABCD@123*',
+ 'confirm password':'ABCD@123*',
+ 'first name':'testor',
+ 'last name':'user',
+ 'phone number': 1234567890,
+ 'institute':'IIT',
+ 'location':'mumbai',
+ 'state': (2),
+ 'department':(2)})
+
+ self.assertEqual(self.register_response.status_code,200)
+
+
+class TestWorkshopStats(TestCase):
+ def setUp(self):
+ '''
+ test user as instructor
+ '''
+ self.superuser = User.objects.create_superuser(
+ username='admin',
+ password='pass@123',
+ email='test.user@gmail.com')
+
+ self.mod_group = Group.objects.create(name='instructor')
+
+ self.user_one = User.objects.create(
+ username='test_user1',
+ email='test.user@gmail.com')
+
+ self.user_one.set_password('pass@123')
+ self.user_one.save()
+
+ self.user_one_profile = Profile.objects.create(
+ user=self.user_one,
+ department='cs',
+ institute='IIT',
+ position='instructor',
+ phone_number='1122993388',
+ is_email_verified=1
+ )
+
+ #Add user_one in instructor group and give required permissions
+ self.mod_group.user_set.add(self.user_one)
+ self.permission = (Permission.objects.all())
+ self.user_one.user_permissions.add(self.permission[44])
+ self.user_one.user_permissions.add(self.permission[43])
+ self.user_one.user_permissions.add(self.permission[42])
+
+ def test_workshop_stats(self):
+ settings.SHOW_WORKSHOP_STATS = True
+ self.client.login(username=self.user_one, password='pass@123')
+ response = self.client.post('/statistics/',
+ {
+ 'from': '2017-01-01',
+ 'to': '2017-12-31',
+ 'Download': 'download'
+ }
+ )
+ self.assertEqual(response.status_code, 200)
+
+ def test_workshop_public_stats(self):
+ settings.SHOW_WORKSHOP_STATS = True
+ response = self.client.post('/statistics/public_stats/',
+ {
+ 'from': '2017-01-01',
+ 'to': '2017-12-31',
+ 'View': 'view'
+ }
+ )
+ self.assertEqual(response.status_code, 200)
+