summaryrefslogtreecommitdiff
path: root/fossee_manim/tests/test_views.py
blob: 525bd309cb5d40ef0899232005f6db8c181cc6c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 Science',
			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()