from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse

from .models import User


class LoginPageTest(TestCase):
	username = 'Shawn'

	def test_login_page_status_code(self):
		response = self.client.get('/accounts/login/')
		self.assertEqual(response.status_code, 200)

	def test_view_url_by_name(self):
		response = self.client.get(reverse('login'))
		self.assertEqual(response.status_code, 200)

	def test_view_uses_correct_template(self):
		response = self.client.get(reverse('login'))
		self.assertEqual(response.status_code, 200)
		self.assertTemplateUsed(response, 'registration/login.html')

	def test_login_form(self):
		new_user = get_user_model().objects.create_user(
		self.username)
		self.assertEqual(get_user_model().objects.all().count(), 1)
		self.assertEqual(get_user_model().objects.all()
		[0].username, self.username)


class SignUpTest(TestCase):
	username = 'Shawn'
	email = 'shawn@yahoo.com'

	def test_signup_page_status_code(self):
		response = self.client.get('/accounts/signup/')
		self.assertEqual(response.status_code, 200)

	def test_view_url_by_name(self):
		response = self.client.get(reverse('signup'))
		self.assertEqual(response.status_code, 200)

	def test_view_uses_correct_template(self):
		response = self.client.get(reverse('signup'))
		self.assertEqual(response.status_code, 200)
		self.assertTemplateUsed(response, 'accounts/signup.html')

	def test_signup_form(self):
		new_user = get_user_model().objects.create_user(
		self.username, self.email)
		self.assertEqual(get_user_model().objects.all().count(), 1)
		self.assertEqual(get_user_model().objects.all()
		[0].username, self.username)
		self.assertEqual(get_user_model().objects.all()
		[0].email, self.email)


class HomePageTests(TestCase):

	def test_home_page_status_code(self):
		response = self.client.get('/')
		self.assertEqual(response.status_code, 200)

	def test_view_url_by_name(self):
		response = self.client.get(reverse('index'))
		self.assertEqual(response.status_code, 200)

	def test_view_uses_correct_template(self):
		response = self.client.get(reverse('index'))
		self.assertEqual(response.status_code, 200)
		self.assertTemplateUsed(response, 'updates/index.html')


class SavestsPageTests(TestCase):

	def test_savest_page_status_code(self):
		response = self.client.get('/savest/')
		self.assertEqual(response.status_code, 200)

	def test_view_url_by_name(self):
		response = self.client.get(reverse('savest'))
		self.assertEqual(response.status_code, 200)

	def test_view_uses_correct_template(self):
		response = self.client.get(reverse('savest'))
		self.assertEqual(response.status_code, 200)
		self.assertTemplateUsed(response, 'updates/savest.html')
