diff options
author | Akshen | 2017-10-07 18:20:09 +0530 |
---|---|---|
committer | GitHub | 2017-10-07 18:20:09 +0530 |
commit | 1e5a2ed97932b4d005c88d451603df475f6179b1 (patch) | |
tree | 8f28914d89f110d42a7238eceb91dd4323945fcd | |
parent | a0f639b4c8b765d40a9ccfbed2f3cfee734d3e8e (diff) | |
parent | 59d5f503b11ecaa4b6d85b9f1f46bd9334bbfc7c (diff) | |
download | workshop_booking-1e5a2ed97932b4d005c88d451603df475f6179b1.tar.gz workshop_booking-1e5a2ed97932b4d005c88d451603df475f6179b1.tar.bz2 workshop_booking-1e5a2ed97932b4d005c88d451603df475f6179b1.zip |
Merge pull request #24 from Akshen/develop
Adds TestCases to statistics_app
-rw-r--r-- | static/workshop_app/img/ModelsTable_Diagram.jpg | bin | 0 -> 61668 bytes | |||
-rw-r--r-- | statistics_app/tests.py | 3 | ||||
-rw-r--r-- | statistics_app/tests/__init__.py | 0 | ||||
-rw-r--r-- | statistics_app/tests/test_views.py | 176 | ||||
-rw-r--r-- | workshop_app/tests/test_views.py | 2 |
5 files changed, 178 insertions, 3 deletions
diff --git a/static/workshop_app/img/ModelsTable_Diagram.jpg b/static/workshop_app/img/ModelsTable_Diagram.jpg Binary files differnew file mode 100644 index 0000000..de7bc0c --- /dev/null +++ b/static/workshop_app/img/ModelsTable_Diagram.jpg diff --git a/statistics_app/tests.py b/statistics_app/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/statistics_app/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/statistics_app/tests/__init__.py b/statistics_app/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/statistics_app/tests/__init__.py 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) + diff --git a/workshop_app/tests/test_views.py b/workshop_app/tests/test_views.py index 9d65ba8..2577b91 100644 --- a/workshop_app/tests/test_views.py +++ b/workshop_app/tests/test_views.py @@ -12,6 +12,7 @@ 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() @@ -114,6 +115,7 @@ class TestProfile(TestCase): self.assertEqual(self.register_response.status_code,200) + class TestWorkshopCreation(TestCase): def setUp(self): ''' |