summaryrefslogtreecommitdiff
path: root/fossee_manim/tests
diff options
context:
space:
mode:
Diffstat (limited to 'fossee_manim/tests')
-rw-r--r--fossee_manim/tests/test_models.py61
-rw-r--r--fossee_manim/tests/test_views.py94
2 files changed, 151 insertions, 4 deletions
diff --git a/fossee_manim/tests/test_models.py b/fossee_manim/tests/test_models.py
index d7ffade..8b2162c 100644
--- a/fossee_manim/tests/test_models.py
+++ b/fossee_manim/tests/test_models.py
@@ -1,6 +1,7 @@
from django.test import TestCase
from fossee_manim.models import (
- Profile, User
+ Profile, User, Category, Animation,
+ Comment, AnimationStats
)
from datetime import datetime
@@ -22,6 +23,8 @@ def setUpModule():
testUser2 = User.objects.create(username='testuser2',
email='test.user@gmail.com', password='pass@123')
+ category1 = Category.objects.create(name='Math', description='Mathematics')
+
reviewer_profile = Profile.objects.create(user=testUser2, position='reviewer',
department='computer engineering', institute='ace', phone_number='1122334456',
title='Doctor', how_did_you_hear_about_us='Google', location='powai', state='IN-MH',
@@ -35,8 +38,10 @@ def setUpModule():
def tearDownModule():
- User.objects.all().delete()
- Profile.objects.all().delete()
+ User.objects.all().delete()
+ Profile.objects.all().delete()
+ Category.objects.all().delete()
+
class ProfileModelTest(TestCase):
'''
@@ -67,4 +72,52 @@ class ProfileModelTest(TestCase):
self.assertEqual(self.contributor_profile1.position,'contributor')
self.assertEqual(self.contributor_profile1.location,'powai')
self.assertEqual(self.reviewer_profile1.location,'powai')
- self.assertEqual(self.contributor_profile1.how_did_you_hear_about_us,'Google') \ No newline at end of file
+ self.assertEqual(self.contributor_profile1.how_did_you_hear_about_us,'Google')
+
+
+class CategoryModelTest(TestCase):
+ def setUp(self):
+ self.category1 = Category.objects.create(name='Biology', description='study of nature')
+ self.category2 = Category.objects.create(name='Aerospace',
+ description='Aerospace is the human effort in science, engineering, and business to fly in the atmosphere of Earth \
+ (aeronautics) and surrounding space (astronautics). \
+ Aerospace organizations research, design, manufacture, operate, or maintain aircraft or spacecraft. Aerospace activity \
+ is very diverse, with a multitude of commercial, industrial and military applications.'
+ )
+
+ def test_category_model(self):
+ self.assertEqual(self.category1.description, 'study of nature')
+ self.assertEqual(self.category2.name, 'Aerospace')
+
+
+class AnimationModelTest(TestCase):
+ def setUp(self):
+ self.demoUser2 = User.objects.create(username='demouser21',
+ email='test.user@gmail.com', password='pass@123')
+ self.testUser2 = User.objects.create(username='testuser21',
+ email='test.user@gmail.com', password='pass@123')
+ self.category1 = Category.objects.create(name='Biology', description='study of nature')
+ self.animation1 = Animation.objects.create(title='Testing Anime', contributor=self.demoUser2,
+ reviewer=self.testUser2, description='This is test animation upload', github='https://github.come/FOSSEE',
+ category=self.category1)
+
+ def test_animation_model(self):
+ self.assertEqual(self.animation1.title, 'Testing Anime')
+ self.assertEqual(self.category1.name, 'Biology')
+
+
+class CommentModelTest(TestCase):
+ def setUp(self):
+ self.demoUser2 = User.objects.create(username='demouser21',
+ email='test.user@gmail.com', password='pass@123')
+ self.testUser2 = User.objects.create(username='testuser21',
+ email='test.user@gmail.com', password='pass@123')
+ self.category1 = Category.objects.create(name='Biology', description='study of nature')
+ self.animation1 = Animation.objects.create(title='Testing Anime', contributor=self.demoUser2,
+ reviewer=self.testUser2, description='This is test animation upload', github='https://github.come/FOSSEE',
+ category=self.category1)
+ self.comment1 = Comment.objects.create(comment='This is a comment', commentor=self.testUser2,
+ animation=self.animation1, animation_status='changes')
+
+ def test_comment_model(self):
+ self.assertEqual(self.comment1.comment, 'This is a comment')
diff --git a/fossee_manim/tests/test_views.py b/fossee_manim/tests/test_views.py
index e69de29..3209f42 100644
--- a/fossee_manim/tests/test_views.py
+++ b/fossee_manim/tests/test_views.py
@@ -0,0 +1,94 @@
+from django.test import TestCase
+from fossee_manim.models import (
+ Profile, User, Category, Animation,
+ Comment, AnimationStats, has_profile
+ )
+from datetime import datetime
+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 fossee_manim.views import view_profile, user_login, edit_profile
+
+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)