diff options
-rw-r--r-- | requirements.txt | 14 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/create_workshop.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/how_to_participate.html | 2 | ||||
-rw-r--r-- | workshop_app/test_models.py | 190 | ||||
-rw-r--r-- | workshop_app/test_views.py | 275 | ||||
-rw-r--r-- | workshop_app/tests.py | 3 | ||||
-rw-r--r-- | workshop_portal/settings.py | 10 |
7 files changed, 487 insertions, 9 deletions
diff --git a/requirements.txt b/requirements.txt index d40ba0a..c64ddbb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,22 @@ appdirs==1.4.0 +appnope==0.1.0 +decorator==4.0.11 Django==1.9 django-recurrence==1.4.1 +ipython==6.0.0 +ipython-genutils==0.2.0 +jedi==0.10.2 packaging==16.8 +pexpect==4.2.1 +pickleshare==0.7.4 +prompt-toolkit==1.0.14 +ptyprocess==0.5.1 +Pygments==2.2.0 pyparsing==2.1.10 python-dateutil==2.6.0 pytz==2016.10 +selenium==3.4.2 +simplegeneric==0.8.1 six==1.10.0 +traitlets==4.3.2 +wcwidth==0.1.7 diff --git a/workshop_app/templates/workshop_app/create_workshop.html b/workshop_app/templates/workshop_app/create_workshop.html index 2977a58..8b4d4d1 100644 --- a/workshop_app/templates/workshop_app/create_workshop.html +++ b/workshop_app/templates/workshop_app/create_workshop.html @@ -1,7 +1,7 @@ {% extends "workshop_app/base.html" %} {% block title %} - Create Event + Create Workshop {% endblock %} {% block extra %} diff --git a/workshop_app/templates/workshop_app/how_to_participate.html b/workshop_app/templates/workshop_app/how_to_participate.html index 0d8cc6f..c732a7f 100644 --- a/workshop_app/templates/workshop_app/how_to_participate.html +++ b/workshop_app/templates/workshop_app/how_to_participate.html @@ -1,7 +1,7 @@ {% extends 'workshop_app/base.html' %} {% block title %} - View Benefits + How to Participate {% endblock %} {% block extra %} diff --git a/workshop_app/test_models.py b/workshop_app/test_models.py new file mode 100644 index 0000000..fc48410 --- /dev/null +++ b/workshop_app/test_models.py @@ -0,0 +1,190 @@ +from django.test import TestCase +from .models import ( + Profile, User, Workshop, WorkshopType, + RequestedWorkshop, BookedWorkshop, ProposeWorkshopDate + ) +from datetime import datetime + +# Setup for Model Test +def setUpModule(): + ''' + demo user as coordinator and test user as instructor + ''' + + demoUser1 = User.objects.create(username='demouser1', + email='doke.akshen@gmail.com', password='pass@123') + demoUser2 = User.objects.create(username='demouser2', + email='doke.akshen@gmail.com', password='pass@123') + + testUser1 = User.objects.create(username='testuser1', + email='doke.akshen@gmail.com',password='pass@123') + + testUser2 = User.objects.create(username='testuser2', + email='doke.akshen@gmail.com', password='pass@123') + + ip = Profile.objects.create(user=testUser2, position='instructor', + department='cs', institute='ace', phone_number='9930011492', + is_email_verified=1) + + cp = Profile.objects.create(user=demoUser2, position='coordinator', + department='IT', institute='iit', phone_number='9930011492', + is_email_verified=1) + + wt1 = WorkshopType.objects.create(workshoptype_name='ISCP', + workshoptype_description='Introduction to Scientific Computing in\ + Python <br> > Numpy <br> > Matplotlib <br> > iPython <br>', + workshoptype_duration='1day, 8hours a day') + + rw = RequestedWorkshop.objects.create( + requested_workshop_instructor=testUser2, + requested_workshop_coordinator=demoUser2, + requested_workshop_title=wt1, + requested_workshop_date='2017-07-24' + ) + + pw = ProposeWorkshopDate.objects.create( + proposed_workshop_coordinator=demoUser2, + proposed_workshop_instructor=testUser2, + proposed_workshop_title=wt1, + proposed_workshop_date='2017-07-06', + conditionone=1, + conditiontwo=1, + conditionthree=1 + ) + + +def tearDownModule(): + User.objects.all().delete() + Profile.objects.all().delete() + ProposeWorkshopDate.objects.all().delete() + RequestedWorkshop.objects.all().delete() + WorkshopType.objects.all().delete() + +class ProfileModelTest(TestCase): + ''' + This class tests the Profile Model + ''' + def setUp(self): + ''' + ip is for instructor profile and cp is for coordinator profile + ''' + self.testuser1 = User.objects.get(username='testuser1') + self.demouser1 = User.objects.get(username='demouser1') + + + self.ip1 = Profile.objects.create(user=self.testuser1, position='instructor', + department='cs', institute='ace', phone_number='9930011492', + is_email_verified=1) + + self.cp1 = Profile.objects.create(user=self.demouser1, position='coordinator', + department='IT', institute='iit', phone_number='9930011492', + is_email_verified=1) + + + def test_profile_model(self): + self.assertEqual(self.demouser1.email,'doke.akshen@gmail.com') + self.assertEqual(self.testuser1.email,'doke.akshen@gmail.com') + self.assertEqual(self.ip1.position,'instructor') + self.assertEqual(self.cp1.position,'coordinator') + + +class WorkshopTypeModelTest(TestCase): + ''' + This class tests the WorkshopType Model + ''' + + def setUp(self): + self.wt1 = WorkshopType.objects.create(workshoptype_name='ISCP', + workshoptype_description='Introduction to Scientific Computing in\ + Python <br> > Numpy <br> > Matplotlib <br> > iPython <br>', + workshoptype_duration='1day, 8hours a day') + + self.wt2 = WorkshopType.objects.create(workshoptype_name='Basic Python', + workshoptype_description='Basic Python <br> > DataTypes <br> \ + > Conditions <br> > Loops <br> > Functions' + ,workshoptype_duration='3days, 8hours a day') + + def test_workshoptype_model(self): + self.assertEqual(self.wt2.workshoptype_duration,'3days, 8hours a day') + self.assertEqual(self.wt1.workshoptype_name, 'ISCP') + + +class WorkshopTest(TestCase): + ''' + This class tests the Workshop Model + ''' + + def setUp(self): + ''' + w is workshop object + ''' + self.testuser2 = User.objects.get(username='testuser2') + self.ip = Profile.objects.get(user=self.testuser2) + self.wt = WorkshopType.objects.get(workshoptype_name='ISCP') + self.w = Workshop.objects.create(workshop_instructor=self.testuser2, + workshop_title=self.wt, + recurrences='RRULE:FREQ=WEEKLY;UNTIL=20170524T183000Z;BYDAY=WE') + + def test_workshop_model(self): + self.assertEqual(self.w.workshop_title.workshoptype_name,'ISCP' ) + +class RequestedWorkshopTest(TestCase): + ''' + This class tests the RequestedWorkshop Model + ''' + + def setUp(self): + self.testuser2 = User.objects.get(username='testuser2') + self.demouser2 = User.objects.get(username='demouser2') + self.wt = WorkshopType.objects.get(workshoptype_name='ISCP') + self.rw = RequestedWorkshop.objects.create( + requested_workshop_instructor=self.testuser2, + requested_workshop_coordinator=self.demouser2, + requested_workshop_title=self.wt, + requested_workshop_date='2017-05-24' + ) + + def test_requestedworkshop_model(self): + self.assertEqual(self.rw.requested_workshop_date, '2017-05-24') + self.assertEqual(self.rw.status, 'Pending') + + +class ProposedWorkshopDateTest(TestCase): + ''' + This class tests the ProposeWorkshopDate Model + ''' + + def setUp(self): + self.testuser2 = User.objects.get(username='testuser2') + self.demouser2 = User.objects.get(username='demouser2') + self.wt = WorkshopType.objects.get(workshoptype_name='ISCP') + self.pw = ProposeWorkshopDate.objects.create( + proposed_workshop_coordinator=self.demouser2, + proposed_workshop_instructor=self.testuser2, + proposed_workshop_title=self.wt, + proposed_workshop_date='2017-06-06', + conditionone=1, + conditiontwo=1, + conditionthree=1 + ) + + def test_proposedworkshopdate_model(self): + self.assertEqual(self.pw.proposed_workshop_title.workshoptype_name,'ISCP') + self.assertEqual(self.pw.conditionthree, 1) + self.assertEqual(self.pw.status, 'Pending') + +class BookedWorkshopTest(TestCase): + ''' + This class tests the BookedWorkshop Model + ''' + + def setUp(self): + self.rw = RequestedWorkshop.objects.get(requested_workshop_date='2017-07-24') + self.pw = ProposeWorkshopDate.objects.get(proposed_workshop_date='2017-07-06') + self.bwr = BookedWorkshop.objects.create(booked_workshop_requested=self.rw) + self.bwp = BookedWorkshop.objects.create(booked_workshop_proposed=self.pw) + + def test_bookedworkshop_model(self): + self.assertEqual(self.bwp.booked_workshop_proposed.conditionone,1) + self.assertEqual(self.bwr.booked_workshop_requested.requested_workshop_title.workshoptype_name,'ISCP' ) + diff --git a/workshop_app/test_views.py b/workshop_app/test_views.py new file mode 100644 index 0000000..d9dd5e0 --- /dev/null +++ b/workshop_app/test_views.py @@ -0,0 +1,275 @@ +from .views import view_profile, user_login, edit_profile +from django.test import TestCase +from .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 .forms import CreateWorkshop + +class TestProfile(TestCase): + def setUp(self): + self.client = Client() + + self.user1 = User.objects.create( + username='demo_test_user1', + password='pass@123', + email='doke.akshen@gmail.com') + + self.user2 = User.objects.create( + username='demo_test_user2', + email='doke.akshen@gmail.com') + + self.user2.set_password('pass@123') + self.user2.save() + + self.user2_profile = Profile.objects.create( + user=self.user2, + department='cs', + institute='ace', + position='instructor', + phone_number='9930011492', + 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)) + self.assertEqual(response.status_code, 200) + self.client.logout() + + def test_edit_profile_post(self): + + self.client.login(username=self.user2, password='pass@123') + response = self.client.post('/edit_profile/', + data = { + 'first_name': 'demo_test', + 'last_name': 'user2', + 'institute': 'IIT', + 'department': 'Aerospace' + }) + + 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') + self.assertEqual(updated_profile.position, 'instructor') + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'workshop_app/profile_updated.html') + + +class TestWorkshopCreation(TestCase): + def setUp(self): + ''' + demo user as coordinator and test user as instructor + ''' + self.superuser = User.objects.create_superuser( + username='admin', + password='pass@123', + email='doke.akshen@gmail.com') + + self.mod_group = Group.objects.create(name='instructor') + + self.user_one = User.objects.create( + username='test_user1', + email='doke.akshen@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='9930011492', + is_email_verified=1 + ) + + #Add user_one in instructor group and give required permissions + self.mod_group.user_set.add(self.user_one) + self.per = (Permission.objects.all()) + self.user_one.user_permissions.add(self.per[44]) + self.user_one.user_permissions.add(self.per[43]) + self.user_one.user_permissions.add(self.per[42]) + + self.user_two = User.objects.create( + username='demo_user2', + email='doke.akshen@gmail.com') + + self.user_two.set_password('pass@123') + self.user_two.save() + + self.user_two_profile = Profile.objects.create( + user=self.user_two, + department='cs', + institute='ace', + position='coordinator', + phone_number='9930011492', + is_email_verified=1 + ) + + self.workshoptype = WorkshopType.objects.create(workshoptype_name='ISCP', workshoptype_description='Introduction to Scientific Computing in Python <br>\ + > Numpy <br> > Matplotlib <br> > iPython <br>', workshoptype_duration='1days, 8hours a day') + + def test_create_workshoptype_superuser(self): + self.client.login(username=self.superuser, password='pass@123') + self.client.post(('/admin/workshop_app/workshoptype/add/'), + data={ + 'workshoptype_name': 'Basic Python', + 'workshoptype_description': 'Basics of Python <br>\ + > Conditions <br> > Datatypes <br> > Loops <br>', + 'workshoptype_duration': '3days, 8hours a day' + }) + self.workshoptype_one = WorkshopType.objects.get(workshoptype_name='Basic Python') + self.assertEqual(self.workshoptype_one.workshoptype_name, 'Basic Python') + self.assertEqual(self.workshoptype_one.workshoptype_duration, '3days, 8hours a day') + self.client.logout() + + def test_create_workshop_instructor(self): + self.client.login(username=self.user_one, password='pass@123') + self.client.post('/create_workshop/', + { + 'workshop_title' : (2), + 'recurrences' : 'RRULE:FREQ=WEEKLY;UNTIL=20170624T183000Z;BYDAY=WE;' + }) + self.workshop = Workshop.objects.get(workshop_instructor=self.user_one) + self.assertEqual(str(self.workshop.workshop_title), 'ISCP 1days, 8hours a day') + self.client.logout() + + + def test_propose_workshop_coordinator(self): + self.client.login(username=self.user_two, password='pass@123') + self.client.post('/propose_workshop/', + { + 'conditionone': 1, + 'conditiontwo': 1, + 'conditionthree': 1, + 'proposed_workshop_title': (2), + 'proposed_workshop_date': '2017-06-06' + }) + self.proposed_workshop = ProposeWorkshopDate.objects.get(proposed_workshop_date='2017-06-06') + self.assertEqual(str(self.proposed_workshop.proposed_workshop_title),'ISCP 1days, 8hours a day') + self.client.logout() + + +class TestWorkshopDashboard(TestCase): + def setUp(self): + ''' + demo user as coordinator and test user as instructor + ''' + self.superuser = User.objects.create_superuser( + username='admin', + password='pass@123', + email='doke.akshen@gmail.com') + + self.mod_group = Group.objects.create(name='instructor') + + self.user_one = User.objects.create( + username='test_user1', + email='doke.akshen@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='9930011492', + is_email_verified=1 + ) + + #Add user_one in instructor group and give required permissions + self.mod_group.user_set.add(self.user_one) + self.per = (Permission.objects.all()) + self.user_one.user_permissions.add(self.per[44]) + self.user_one.user_permissions.add(self.per[43]) + self.user_one.user_permissions.add(self.per[42]) + + self.user_two = User.objects.create( + username='demo_user2', + email='doke.akshen@gmail.com') + + self.user_two.set_password('pass@123') + self.user_two.save() + + self.user_two_profile = Profile.objects.create( + user=self.user_two, + department='cs', + institute='ace', + position='coordinator', + phone_number='9930011492', + is_email_verified=1 + ) + + self.workshoptype = WorkshopType.objects.create(workshoptype_name='ISCP', workshoptype_description='Introduction to Scientific Computing in Python <br>\ + > Numpy <br> > Matplotlib <br> > iPython <br>', workshoptype_duration='1days, 8hours a day') + + self.workshop = Workshop.objects.create(workshop_instructor=self.user_one, + workshop_title=self.workshoptype, + recurrences='RRULE:FREQ=WEEKLY;UNTIL=20170624T183000Z;BYDAY=WE;') + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/workshop_app/tests.py b/workshop_app/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/workshop_app/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/workshop_portal/settings.py b/workshop_portal/settings.py index 20bb4b5..66ba5f1 100644 --- a/workshop_portal/settings.py +++ b/workshop_portal/settings.py @@ -10,7 +10,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.10/ref/settings/ """ -import os +import os, sys from local_settings import ( EMAIL_HOST, EMAIL_PORT, @@ -82,13 +82,15 @@ WSGI_APPLICATION = 'workshop_portal.wsgi.application' # Database # https://docs.djangoproject.com/en/1.10/ref/settings/#databases - DATABASES = { - 'default': { + 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'TEST': { + 'NAME': 'mytestdatabase', + }, + } } -} # Password validation |